3
0
Fork 0
forked from mirrors/nixpkgs

treewide: use optionalAttrs instead of 'else {}'

This commit is contained in:
Felix Buehler 2023-06-25 12:25:42 +02:00 committed by Anderson Torres
parent fa6b5a3cb3
commit 6672dde558
31 changed files with 51 additions and 66 deletions

View file

@ -70,12 +70,11 @@ in {
users.groups.${cfg.group} = {}; users.groups.${cfg.group} = {};
users.users.${cfg.user} = users.users.${cfg.user} =
if cfg.user == "roon-bridge" then { optionalAttrs (cfg.user == "roon-bridge") {
isSystemUser = true; isSystemUser = true;
description = "Roon Bridge user"; description = "Roon Bridge user";
group = cfg.group; group = cfg.group;
extraGroups = [ "audio" ]; extraGroups = [ "audio" ];
} };
else {};
}; };
} }

View file

@ -76,12 +76,11 @@ in {
users.groups.${cfg.group} = {}; users.groups.${cfg.group} = {};
users.users.${cfg.user} = users.users.${cfg.user} =
if cfg.user == "roon-server" then { optionalAttrs (cfg.user == "roon-server") {
isSystemUser = true; isSystemUser = true;
description = "Roon Server user"; description = "Roon Server user";
group = cfg.group; group = cfg.group;
extraGroups = [ "audio" ]; extraGroups = [ "audio" ];
} };
else {};
}; };
} }

View file

@ -50,7 +50,7 @@ let
# to install it because it would create a cyclic dependency between # to install it because it would create a cyclic dependency between
# the outputs. We also need to enable the remote, # the outputs. We also need to enable the remote,
# which should not be done by default. # which should not be done by default.
if cfg.enableTestRemote then (enableRemote cfg.package.installedTests "fwupd-tests") else {} lib.optionalAttrs cfg.enableTestRemote (enableRemote cfg.package.installedTests "fwupd-tests")
); );
in { in {

View file

@ -87,8 +87,8 @@ in
environment = { environment = {
HOME = "/root"; HOME = "/root";
} }
// (if config.environment.variables ? DYSNOMIA_CONTAINERS_PATH then { inherit (config.environment.variables) DYSNOMIA_CONTAINERS_PATH; } else {}) // (optionalAttrs (config.environment.variables ? DYSNOMIA_CONTAINERS_PATH) { inherit (config.environment.variables) DYSNOMIA_CONTAINERS_PATH; })
// (if config.environment.variables ? DYSNOMIA_MODULES_PATH then { inherit (config.environment.variables) DYSNOMIA_MODULES_PATH; } else {}); // (optionalAttrs (config.environment.variables ? DYSNOMIA_MODULES_PATH) { inherit (config.environment.variables) DYSNOMIA_MODULES_PATH; });
serviceConfig.ExecStart = "${cfg.package}/bin/disnix-service"; serviceConfig.ExecStart = "${cfg.package}/bin/disnix-service";
}; };

View file

@ -15,9 +15,7 @@ let
storage = { storage = {
cache.blobdescriptor = blobCache; cache.blobdescriptor = blobCache;
delete.enabled = cfg.enableDelete; delete.enabled = cfg.enableDelete;
} // (if cfg.storagePath != null } // (optionalAttrs (cfg.storagePath != null) { filesystem.rootdirectory = cfg.storagePath; });
then { filesystem.rootdirectory = cfg.storagePath; }
else {});
http = { http = {
addr = "${cfg.listenAddress}:${builtins.toString cfg.port}"; addr = "${cfg.listenAddress}:${builtins.toString cfg.port}";
headers.X-Content-Type-Options = ["nosniff"]; headers.X-Content-Type-Options = ["nosniff"];
@ -152,12 +150,10 @@ in {
}; };
users.users.docker-registry = users.users.docker-registry =
(if cfg.storagePath != null (optionalAttrs (cfg.storagePath != null) {
then {
createHome = true; createHome = true;
home = cfg.storagePath; home = cfg.storagePath;
} }) // {
else {}) // {
group = "docker-registry"; group = "docker-registry";
isSystemUser = true; isSystemUser = true;
}; };

View file

@ -75,13 +75,12 @@ in
config = mkIf (cfg.enable) { config = mkIf (cfg.enable) {
users.users.${cfg.user} = users.users.${cfg.user} =
if cfg.user == "zerobin" then { optionalAttrs (cfg.user == "zerobin") {
isSystemUser = true; isSystemUser = true;
group = cfg.group; group = cfg.group;
home = cfg.dataDir; home = cfg.dataDir;
createHome = true; createHome = true;
} };
else {};
users.groups.${cfg.group} = {}; users.groups.${cfg.group} = {};
systemd.services.zerobin = { systemd.services.zerobin = {

View file

@ -800,14 +800,14 @@ in
# declarative containers # declarative containers
++ (mapAttrsToList (name: cfg: nameValuePair "container@${name}" (let ++ (mapAttrsToList (name: cfg: nameValuePair "container@${name}" (let
containerConfig = cfg // ( containerConfig = cfg // (
if cfg.enableTun then optionalAttrs cfg.enableTun
{ {
allowedDevices = cfg.allowedDevices allowedDevices = cfg.allowedDevices
++ [ { node = "/dev/net/tun"; modifier = "rw"; } ]; ++ [ { node = "/dev/net/tun"; modifier = "rw"; } ];
additionalCapabilities = cfg.additionalCapabilities additionalCapabilities = cfg.additionalCapabilities
++ [ "CAP_NET_ADMIN" ]; ++ [ "CAP_NET_ADMIN" ];
} }
else {}); );
in in
recursiveUpdate unit { recursiveUpdate unit {
preStart = preStartScript containerConfig; preStart = preStartScript containerConfig;
@ -817,7 +817,7 @@ in
unitConfig.RequiresMountsFor = lib.optional (!containerConfig.ephemeral) "${stateDirectory}/%i"; unitConfig.RequiresMountsFor = lib.optional (!containerConfig.ephemeral) "${stateDirectory}/%i";
environment.root = if containerConfig.ephemeral then "/run/nixos-containers/%i" else "${stateDirectory}/%i"; environment.root = if containerConfig.ephemeral then "/run/nixos-containers/%i" else "${stateDirectory}/%i";
} // ( } // (
if containerConfig.autoStart then optionalAttrs containerConfig.autoStart
{ {
wantedBy = [ "machines.target" ]; wantedBy = [ "machines.target" ];
wants = [ "network.target" ]; wants = [ "network.target" ];
@ -828,7 +828,7 @@ in
]; ];
restartIfChanged = true; restartIfChanged = true;
} }
else {}) )
)) config.containers) )) config.containers)
)); ));

View file

@ -519,4 +519,4 @@ in mapAttrs (mkVBoxTest false vboxVMs) {
destroy_vm_test1() destroy_vm_test1()
destroy_vm_test2() destroy_vm_test2()
''; '';
} // (if enableUnfree then unfreeTests else {}) } // (lib.optionalAttrs enableUnfree unfreeTests)

View file

@ -388,8 +388,8 @@ stdenv.mkDerivation {
}; };
meta = meta =
let bintools_ = if bintools != null then bintools else {}; in let bintools_ = lib.optionalAttrs (bintools != null) bintools; in
(if bintools_ ? meta then removeAttrs bintools.meta ["priority"] else {}) // (lib.optionalAttrs (bintools_ ? meta) (removeAttrs bintools.meta ["priority"])) //
{ description = { description =
lib.attrByPath ["meta" "description"] "System binary utilities" bintools_ lib.attrByPath ["meta" "description"] "System binary utilities" bintools_
+ " (wrapper script)"; + " (wrapper script)";

View file

@ -611,8 +611,8 @@ stdenv.mkDerivation {
}; };
meta = meta =
let cc_ = if cc != null then cc else {}; in let cc_ = lib.optionalAttrs (cc != null) cc; in
(if cc_ ? meta then removeAttrs cc.meta ["priority"] else {}) // (lib.optionalAttrs (cc_ ? meta) (removeAttrs cc.meta ["priority"])) //
{ description = { description =
lib.attrByPath ["meta" "description"] "System C compiler" cc_ lib.attrByPath ["meta" "description"] "System C compiler" cc_
+ " (wrapper script)"; + " (wrapper script)";

View file

@ -73,7 +73,5 @@ rec {
haskell-package-env = haskell-package-env =
builtins.head haskell-package.env.nativeBuildInputs; builtins.head haskell-package.env.nativeBuildInputs;
in in
if is-haskell-package lib.optionalAttrs is-haskell-package (withPackages [ haskell-package-env ]);
then withPackages [ haskell-package-env ]
else {};
} }

View file

@ -119,8 +119,8 @@ stdenv.mkDerivation {
}; };
meta = meta =
let pkg-config_ = if pkg-config != null then pkg-config else {}; in let pkg-config_ = lib.optionalAttrs (pkg-config != null) pkg-config; in
(if pkg-config_ ? meta then removeAttrs pkg-config.meta ["priority"] else {}) // (lib.optionalAttrs (pkg-config_ ? meta) (removeAttrs pkg-config.meta ["priority"])) //
{ description = { description =
lib.attrByPath ["meta" "description"] "pkg-config" pkg-config_ lib.attrByPath ["meta" "description"] "pkg-config" pkg-config_
+ " (wrapper script)"; + " (wrapper script)";

View file

@ -70,7 +70,7 @@ stdenv.mkDerivation (
test -n "$releaseName" && (echo "$releaseName" >> $out/nix-support/hydra-release-name) test -n "$releaseName" && (echo "$releaseName" >> $out/nix-support/hydra-release-name)
''; '';
meta = (if args ? meta then args.meta else {}) // { meta = (lib.optionalAttrs (args ? meta) args.meta) // {
description = "Build of a generic binary distribution"; description = "Build of a generic binary distribution";
}; };

View file

@ -86,7 +86,7 @@ vmTools.runInLinuxImage (stdenv.mkDerivation (
eval "$postInstall" eval "$postInstall"
''; '';
meta = (if args ? meta then args.meta else {}) // { meta = (lib.optionalAttrs (args ? meta) args.meta) // {
description = "Deb package for ${diskImage.fullName}"; description = "Deb package for ${diskImage.fullName}";
}; };
} }

View file

@ -146,7 +146,7 @@ stdenv.mkDerivation (
postPhases = postPhases ++ ["finalPhase"]; postPhases = postPhases ++ ["finalPhase"];
meta = (if args ? meta then args.meta else {}) // { meta = (lib.optionalAttrs (args ? meta) args.meta) // {
description = if doCoverageAnalysis then "Coverage analysis" else "Nix package for ${stdenv.hostPlatform.system}"; description = if doCoverageAnalysis then "Coverage analysis" else "Nix package for ${stdenv.hostPlatform.system}";
}; };

View file

@ -46,7 +46,7 @@ vmTools.buildRPM (
done done
''; '';
meta = (if args ? meta then args.meta else {}) // { meta = (lib.optionalAttrs (args ? meta) args.meta) // {
description = "RPM package for ${diskImage.fullName}"; description = "RPM package for ${diskImage.fullName}";
}; };
} }

View file

@ -24,9 +24,7 @@
, release ? true , release ? true
# Additional crate2nix configuration if it exists. # Additional crate2nix configuration if it exists.
, crateConfig , crateConfig
? if builtins.pathExists ./crate-config.nix ? lib.optionalAttrs (builtins.pathExists ./crate-config.nix) (pkgs.callPackage ./crate-config.nix {})
then pkgs.callPackage ./crate-config.nix {}
else {}
}: }:
rec { rec {

View file

@ -8,7 +8,7 @@ let
name = variant; name = variant;
url = "https://github.com/ful1e5/apple_cursor/releases/download/v${version}/${variant}.${suffix}"; url = "https://github.com/ful1e5/apple_cursor/releases/download/v${version}/${variant}.${suffix}";
hash = hash; hash = hash;
} // (if suffix == "zip" then { stripRoot = false; } else {})); } // (lib.optionalAttrs (suffix == "zip") { stripRoot = false; }));
version = "2.0.0"; version = "2.0.0";
srcs = [ srcs = [

View file

@ -15,5 +15,5 @@ stdenv.mkDerivation (args // {
maintainers = with lib.maintainers; [ ashalkhakov matthewbauer ]; maintainers = with lib.maintainers; [ ashalkhakov matthewbauer ];
platforms = lib.platforms.linux; platforms = lib.platforms.linux;
} // (if builtins.hasAttr "meta" args then args.meta else {}); } // (lib.optionalAttrs (builtins.hasAttr "meta" args) args.meta);
}) })

View file

@ -26,9 +26,7 @@ final: prev: let
in lib.mapAttrs buildCudaToolkitRedistPackage attrs; in lib.mapAttrs buildCudaToolkitRedistPackage attrs;
# All cudatoolkit redist packages for the current cuda version # All cudatoolkit redist packages for the current cuda version
cudaToolkitRedistPackages = if cudaToolkitRedistPackages = lib.optionalAttrs (lib.hasAttr cudaVersion cudaToolkitRedistManifests)
lib.hasAttr cudaVersion cudaToolkitRedistManifests (buildCudaToolkitRedistPackages { version = cudaVersion; manifest = cudaToolkitRedistManifests.${cudaVersion}; });
then buildCudaToolkitRedistPackages { version = cudaVersion; manifest = cudaToolkitRedistManifests.${cudaVersion}; }
else {};
in cudaToolkitRedistPackages in cudaToolkitRedistPackages

View file

@ -36,4 +36,4 @@
maintainers = with maintainers; [ siraben ]; maintainers = with maintainers; [ siraben ];
license = licenses.lgpl21Plus; license = licenses.lgpl21Plus;
}; };
}).overrideAttrs({version, ...}: if lib.versions.isGe "9.0" version then { repo = "topology"; } else {}) }).overrideAttrs({version, ...}: lib.optionalAttrs (lib.versions.isGe "9.0" version) { repo = "topology"; })

View file

@ -146,7 +146,7 @@ stdenv.mkDerivation rec {
luaOnBuildForHost = override pkgsBuildHost.${luaAttr}; luaOnBuildForHost = override pkgsBuildHost.${luaAttr};
luaOnBuildForTarget = override pkgsBuildTarget.${luaAttr}; luaOnBuildForTarget = override pkgsBuildTarget.${luaAttr};
luaOnHostForHost = override pkgsHostHost.${luaAttr}; luaOnHostForHost = override pkgsHostHost.${luaAttr};
luaOnTargetForTarget = if lib.hasAttr luaAttr pkgsTargetTarget then (override pkgsTargetTarget.${luaAttr}) else {}; luaOnTargetForTarget = lib.optionalAttrs (lib.hasAttr luaAttr pkgsTargetTarget) (override pkgsTargetTarget.${luaAttr});
}; };
meta = { meta = {

View file

@ -127,7 +127,7 @@ stdenv.mkDerivation rec {
luaOnBuildForHost = override pkgsBuildHost.${luaAttr}; luaOnBuildForHost = override pkgsBuildHost.${luaAttr};
luaOnBuildForTarget = override pkgsBuildTarget.${luaAttr}; luaOnBuildForTarget = override pkgsBuildTarget.${luaAttr};
luaOnHostForHost = override pkgsHostHost.${luaAttr}; luaOnHostForHost = override pkgsHostHost.${luaAttr};
luaOnTargetForTarget = if lib.hasAttr luaAttr pkgsTargetTarget then (override pkgsTargetTarget.${luaAttr}) else {}; luaOnTargetForTarget = lib.optionalAttrs (lib.hasAttr luaAttr pkgsTargetTarget) (override pkgsTargetTarget.${luaAttr});
}; };
meta = with lib; { meta = with lib; {

View file

@ -109,7 +109,7 @@ let
pythonOnBuildForHost = override pkgsBuildHost.${pythonAttr}; pythonOnBuildForHost = override pkgsBuildHost.${pythonAttr};
pythonOnBuildForTarget = override pkgsBuildTarget.${pythonAttr}; pythonOnBuildForTarget = override pkgsBuildTarget.${pythonAttr};
pythonOnHostForHost = override pkgsHostHost.${pythonAttr}; pythonOnHostForHost = override pkgsHostHost.${pythonAttr};
pythonOnTargetForTarget = if lib.hasAttr pythonAttr pkgsTargetTarget then (override pkgsTargetTarget.${pythonAttr}) else {}; pythonOnTargetForTarget = lib.optionalAttrs (lib.hasAttr pythonAttr pkgsTargetTarget) (override pkgsTargetTarget.${pythonAttr});
}; };
version = with sourceVersion; "${major}.${minor}.${patch}${suffix}"; version = with sourceVersion; "${major}.${minor}.${patch}${suffix}";

View file

@ -1,4 +1,4 @@
{ stdenv, hspell }: { lib, stdenv, hspell }:
let let
dict = variant: a: stdenv.mkDerivation ({ dict = variant: a: stdenv.mkDerivation ({
@ -8,7 +8,7 @@ let
meta = hspell.meta // { meta = hspell.meta // {
broken = true; broken = true;
description = "${variant} Hebrew dictionary"; description = "${variant} Hebrew dictionary";
} // (if a ? meta then a.meta else {}); } // (lib.optionalAttrs (a ? meta) a.meta);
} // (removeAttrs a ["meta"])); } // (removeAttrs a ["meta"]));
in in
{ {

View file

@ -221,9 +221,8 @@ let
}; };
qlpkgs = qlpkgs =
if builtins.pathExists ./imported.nix lib.optionalAttrs (builtins.pathExists ./imported.nix)
then import ./imported.nix { inherit (pkgs) runCommand fetchzip; pkgs = builtQlpkgs; } (import ./imported.nix { inherit (pkgs) runCommand fetchzip; pkgs = builtQlpkgs; });
else {};
builtQlpkgs = mapAttrs (n: v: build v) qlpkgs; builtQlpkgs = mapAttrs (n: v: build v) qlpkgs;

View file

@ -230,8 +230,7 @@ let
}); });
qlpkgs = qlpkgs =
if builtins.pathExists ./imported.nix lib.optionalAttrs (builtins.pathExists ./imported.nix)
then pkgs.callPackage ./imported.nix { inherit build-asdf-system; } (pkgs.callPackage ./imported.nix { inherit build-asdf-system; });
else {};
in qlpkgs.overrideScope' overrides in qlpkgs.overrideScope' overrides

View file

@ -28,7 +28,7 @@ stdenv.mkDerivation (rec {
inherit (ocaml.meta) platforms; inherit (ocaml.meta) platforms;
inherit (src.meta) homepage; inherit (src.meta) homepage;
}; };
} // (if lib.versions.majorMinor ocaml.version == "4.06" then { } // (lib.optionalAttrs (lib.versions.majorMinor ocaml.version == "4.06") {
env.NIX_CFLAGS_COMPILE = "-fcommon"; env.NIX_CFLAGS_COMPILE = "-fcommon";
} else {}) })
) )

View file

@ -320,10 +320,10 @@ stdenv.mkDerivation rec {
sha256 = "1mm4awx6sa0myiz9j4hwp71rpr7yh8vihf3zm15n2ii6xb82r31k"; sha256 = "1mm4awx6sa0myiz9j4hwp71rpr7yh8vihf3zm15n2ii6xb82r31k";
}; };
in (if !stdenv.hostPlatform.isDarwin then { in (lib.optionalAttrs (!stdenv.hostPlatform.isDarwin) {
# `extracted` doesnt work on darwin # `extracted` doesnt work on darwin
shebang = callPackage ../shebang-test.nix { inherit runLocal extracted bazelTest distDir; bazel = bazel_self; }; shebang = callPackage ../shebang-test.nix { inherit runLocal extracted bazelTest distDir; bazel = bazel_self; };
} else {}) // { }) // {
bashTools = callPackage ../bash-tools-test.nix { inherit runLocal bazelTest distDir; bazel = bazel_self; }; bashTools = callPackage ../bash-tools-test.nix { inherit runLocal bazelTest distDir; bazel = bazel_self; };
cpp = callPackage ../cpp-test.nix { inherit runLocal bazelTest bazel-examples distDir; bazel = bazel_self; }; cpp = callPackage ../cpp-test.nix { inherit runLocal bazelTest bazel-examples distDir; bazel = bazel_self; };
java = callPackage ../java-test.nix { inherit runLocal bazelTest bazel-examples distDir; bazel = bazel_self; }; java = callPackage ../java-test.nix { inherit runLocal bazelTest bazel-examples distDir; bazel = bazel_self; };

View file

@ -285,10 +285,10 @@ stdenv.mkDerivation rec {
sha256 = "1mm4awx6sa0myiz9j4hwp71rpr7yh8vihf3zm15n2ii6xb82r31k"; sha256 = "1mm4awx6sa0myiz9j4hwp71rpr7yh8vihf3zm15n2ii6xb82r31k";
}; };
in (if !stdenv.hostPlatform.isDarwin then { in (lib.optionalSttrs (!stdenv.hostPlatform.isDarwin) {
# `extracted` doesnt work on darwin # `extracted` doesnt work on darwin
shebang = callPackage ../shebang-test.nix { inherit runLocal extracted bazelTest distDir; bazel = bazel_self;}; shebang = callPackage ../shebang-test.nix { inherit runLocal extracted bazelTest distDir; bazel = bazel_self;};
} else {}) // { }) // {
bashTools = callPackage ../bash-tools-test.nix { inherit runLocal bazelTest distDir; bazel = bazel_self;}; bashTools = callPackage ../bash-tools-test.nix { inherit runLocal bazelTest distDir; bazel = bazel_self;};
cpp = callPackage ../cpp-test.nix { inherit runLocal bazelTest bazel-examples distDir; bazel = bazel_self;}; cpp = callPackage ../cpp-test.nix { inherit runLocal bazelTest bazel-examples distDir; bazel = bazel_self;};
java = callPackage ../java-test.nix { inherit runLocal bazelTest bazel-examples distDir; bazel = bazel_self;}; java = callPackage ../java-test.nix { inherit runLocal bazelTest bazel-examples distDir; bazel = bazel_self;};

View file

@ -295,10 +295,10 @@ stdenv.mkDerivation rec {
sha256 = "1mm4awx6sa0myiz9j4hwp71rpr7yh8vihf3zm15n2ii6xb82r31k"; sha256 = "1mm4awx6sa0myiz9j4hwp71rpr7yh8vihf3zm15n2ii6xb82r31k";
}; };
in (if !stdenv.hostPlatform.isDarwin then { in (lib.optionalAttrs (!stdenv.hostPlatform.isDarwin) {
# `extracted` doesnt work on darwin # `extracted` doesnt work on darwin
shebang = callPackage ../shebang-test.nix { inherit runLocal extracted bazelTest distDir; bazel = bazel_self;}; shebang = callPackage ../shebang-test.nix { inherit runLocal extracted bazelTest distDir; bazel = bazel_self;};
} else {}) // { }) // {
bashTools = callPackage ../bash-tools-test.nix { inherit runLocal bazelTest distDir; bazel = bazel_self;}; bashTools = callPackage ../bash-tools-test.nix { inherit runLocal bazelTest distDir; bazel = bazel_self;};
cpp = callPackage ../cpp-test.nix { inherit runLocal bazelTest bazel-examples distDir; bazel = bazel_self;}; cpp = callPackage ../cpp-test.nix { inherit runLocal bazelTest bazel-examples distDir; bazel = bazel_self;};
java = callPackage ../java-test.nix { inherit runLocal bazelTest bazel-examples distDir; bazel = bazel_self;}; java = callPackage ../java-test.nix { inherit runLocal bazelTest bazel-examples distDir; bazel = bazel_self;};