mirror of
https://github.com/NixOS/nixpkgs.git
synced 2024-11-21 22:43:01 +00:00
treewide: use optionalAttrs instead of 'else {}'
This commit is contained in:
parent
fa6b5a3cb3
commit
6672dde558
@ -70,12 +70,11 @@ in {
|
||||
|
||||
users.groups.${cfg.group} = {};
|
||||
users.users.${cfg.user} =
|
||||
if cfg.user == "roon-bridge" then {
|
||||
optionalAttrs (cfg.user == "roon-bridge") {
|
||||
isSystemUser = true;
|
||||
description = "Roon Bridge user";
|
||||
group = cfg.group;
|
||||
extraGroups = [ "audio" ];
|
||||
}
|
||||
else {};
|
||||
};
|
||||
};
|
||||
}
|
||||
|
@ -76,12 +76,11 @@ in {
|
||||
|
||||
users.groups.${cfg.group} = {};
|
||||
users.users.${cfg.user} =
|
||||
if cfg.user == "roon-server" then {
|
||||
optionalAttrs (cfg.user == "roon-server") {
|
||||
isSystemUser = true;
|
||||
description = "Roon Server user";
|
||||
group = cfg.group;
|
||||
extraGroups = [ "audio" ];
|
||||
}
|
||||
else {};
|
||||
};
|
||||
};
|
||||
}
|
||||
|
@ -50,7 +50,7 @@ let
|
||||
# to install it because it would create a cyclic dependency between
|
||||
# the outputs. We also need to enable the remote,
|
||||
# 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 {
|
||||
|
@ -87,8 +87,8 @@ in
|
||||
environment = {
|
||||
HOME = "/root";
|
||||
}
|
||||
// (if config.environment.variables ? DYSNOMIA_CONTAINERS_PATH then { inherit (config.environment.variables) DYSNOMIA_CONTAINERS_PATH; } else {})
|
||||
// (if config.environment.variables ? DYSNOMIA_MODULES_PATH then { inherit (config.environment.variables) DYSNOMIA_MODULES_PATH; } else {});
|
||||
// (optionalAttrs (config.environment.variables ? DYSNOMIA_CONTAINERS_PATH) { inherit (config.environment.variables) DYSNOMIA_CONTAINERS_PATH; })
|
||||
// (optionalAttrs (config.environment.variables ? DYSNOMIA_MODULES_PATH) { inherit (config.environment.variables) DYSNOMIA_MODULES_PATH; });
|
||||
|
||||
serviceConfig.ExecStart = "${cfg.package}/bin/disnix-service";
|
||||
};
|
||||
|
@ -15,9 +15,7 @@ let
|
||||
storage = {
|
||||
cache.blobdescriptor = blobCache;
|
||||
delete.enabled = cfg.enableDelete;
|
||||
} // (if cfg.storagePath != null
|
||||
then { filesystem.rootdirectory = cfg.storagePath; }
|
||||
else {});
|
||||
} // (optionalAttrs (cfg.storagePath != null) { filesystem.rootdirectory = cfg.storagePath; });
|
||||
http = {
|
||||
addr = "${cfg.listenAddress}:${builtins.toString cfg.port}";
|
||||
headers.X-Content-Type-Options = ["nosniff"];
|
||||
@ -152,12 +150,10 @@ in {
|
||||
};
|
||||
|
||||
users.users.docker-registry =
|
||||
(if cfg.storagePath != null
|
||||
then {
|
||||
(optionalAttrs (cfg.storagePath != null) {
|
||||
createHome = true;
|
||||
home = cfg.storagePath;
|
||||
}
|
||||
else {}) // {
|
||||
}) // {
|
||||
group = "docker-registry";
|
||||
isSystemUser = true;
|
||||
};
|
||||
|
@ -75,13 +75,12 @@ in
|
||||
|
||||
config = mkIf (cfg.enable) {
|
||||
users.users.${cfg.user} =
|
||||
if cfg.user == "zerobin" then {
|
||||
optionalAttrs (cfg.user == "zerobin") {
|
||||
isSystemUser = true;
|
||||
group = cfg.group;
|
||||
home = cfg.dataDir;
|
||||
createHome = true;
|
||||
}
|
||||
else {};
|
||||
};
|
||||
users.groups.${cfg.group} = {};
|
||||
|
||||
systemd.services.zerobin = {
|
||||
|
@ -800,14 +800,14 @@ in
|
||||
# declarative containers
|
||||
++ (mapAttrsToList (name: cfg: nameValuePair "container@${name}" (let
|
||||
containerConfig = cfg // (
|
||||
if cfg.enableTun then
|
||||
optionalAttrs cfg.enableTun
|
||||
{
|
||||
allowedDevices = cfg.allowedDevices
|
||||
++ [ { node = "/dev/net/tun"; modifier = "rw"; } ];
|
||||
additionalCapabilities = cfg.additionalCapabilities
|
||||
++ [ "CAP_NET_ADMIN" ];
|
||||
}
|
||||
else {});
|
||||
);
|
||||
in
|
||||
recursiveUpdate unit {
|
||||
preStart = preStartScript containerConfig;
|
||||
@ -817,7 +817,7 @@ in
|
||||
unitConfig.RequiresMountsFor = lib.optional (!containerConfig.ephemeral) "${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" ];
|
||||
wants = [ "network.target" ];
|
||||
@ -828,7 +828,7 @@ in
|
||||
];
|
||||
restartIfChanged = true;
|
||||
}
|
||||
else {})
|
||||
)
|
||||
)) config.containers)
|
||||
));
|
||||
|
||||
|
@ -519,4 +519,4 @@ in mapAttrs (mkVBoxTest false vboxVMs) {
|
||||
destroy_vm_test1()
|
||||
destroy_vm_test2()
|
||||
'';
|
||||
} // (if enableUnfree then unfreeTests else {})
|
||||
} // (lib.optionalAttrs enableUnfree unfreeTests)
|
||||
|
@ -388,8 +388,8 @@ stdenv.mkDerivation {
|
||||
};
|
||||
|
||||
meta =
|
||||
let bintools_ = if bintools != null then bintools else {}; in
|
||||
(if bintools_ ? meta then removeAttrs bintools.meta ["priority"] else {}) //
|
||||
let bintools_ = lib.optionalAttrs (bintools != null) bintools; in
|
||||
(lib.optionalAttrs (bintools_ ? meta) (removeAttrs bintools.meta ["priority"])) //
|
||||
{ description =
|
||||
lib.attrByPath ["meta" "description"] "System binary utilities" bintools_
|
||||
+ " (wrapper script)";
|
||||
|
@ -611,8 +611,8 @@ stdenv.mkDerivation {
|
||||
};
|
||||
|
||||
meta =
|
||||
let cc_ = if cc != null then cc else {}; in
|
||||
(if cc_ ? meta then removeAttrs cc.meta ["priority"] else {}) //
|
||||
let cc_ = lib.optionalAttrs (cc != null) cc; in
|
||||
(lib.optionalAttrs (cc_ ? meta) (removeAttrs cc.meta ["priority"])) //
|
||||
{ description =
|
||||
lib.attrByPath ["meta" "description"] "System C compiler" cc_
|
||||
+ " (wrapper script)";
|
||||
|
@ -73,7 +73,5 @@ rec {
|
||||
haskell-package-env =
|
||||
builtins.head haskell-package.env.nativeBuildInputs;
|
||||
in
|
||||
if is-haskell-package
|
||||
then withPackages [ haskell-package-env ]
|
||||
else {};
|
||||
lib.optionalAttrs is-haskell-package (withPackages [ haskell-package-env ]);
|
||||
}
|
||||
|
@ -119,8 +119,8 @@ stdenv.mkDerivation {
|
||||
};
|
||||
|
||||
meta =
|
||||
let pkg-config_ = if pkg-config != null then pkg-config else {}; in
|
||||
(if pkg-config_ ? meta then removeAttrs pkg-config.meta ["priority"] else {}) //
|
||||
let pkg-config_ = lib.optionalAttrs (pkg-config != null) pkg-config; in
|
||||
(lib.optionalAttrs (pkg-config_ ? meta) (removeAttrs pkg-config.meta ["priority"])) //
|
||||
{ description =
|
||||
lib.attrByPath ["meta" "description"] "pkg-config" pkg-config_
|
||||
+ " (wrapper script)";
|
||||
|
@ -70,7 +70,7 @@ stdenv.mkDerivation (
|
||||
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";
|
||||
};
|
||||
|
||||
|
@ -86,7 +86,7 @@ vmTools.runInLinuxImage (stdenv.mkDerivation (
|
||||
eval "$postInstall"
|
||||
'';
|
||||
|
||||
meta = (if args ? meta then args.meta else {}) // {
|
||||
meta = (lib.optionalAttrs (args ? meta) args.meta) // {
|
||||
description = "Deb package for ${diskImage.fullName}";
|
||||
};
|
||||
}
|
||||
|
@ -146,7 +146,7 @@ stdenv.mkDerivation (
|
||||
|
||||
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}";
|
||||
};
|
||||
|
||||
|
@ -46,7 +46,7 @@ vmTools.buildRPM (
|
||||
done
|
||||
'';
|
||||
|
||||
meta = (if args ? meta then args.meta else {}) // {
|
||||
meta = (lib.optionalAttrs (args ? meta) args.meta) // {
|
||||
description = "RPM package for ${diskImage.fullName}";
|
||||
};
|
||||
}
|
||||
|
@ -24,9 +24,7 @@
|
||||
, release ? true
|
||||
# Additional crate2nix configuration if it exists.
|
||||
, crateConfig
|
||||
? if builtins.pathExists ./crate-config.nix
|
||||
then pkgs.callPackage ./crate-config.nix {}
|
||||
else {}
|
||||
? lib.optionalAttrs (builtins.pathExists ./crate-config.nix) (pkgs.callPackage ./crate-config.nix {})
|
||||
}:
|
||||
|
||||
rec {
|
||||
|
@ -8,7 +8,7 @@ let
|
||||
name = variant;
|
||||
url = "https://github.com/ful1e5/apple_cursor/releases/download/v${version}/${variant}.${suffix}";
|
||||
hash = hash;
|
||||
} // (if suffix == "zip" then { stripRoot = false; } else {}));
|
||||
} // (lib.optionalAttrs (suffix == "zip") { stripRoot = false; }));
|
||||
|
||||
version = "2.0.0";
|
||||
srcs = [
|
||||
|
@ -15,5 +15,5 @@ stdenv.mkDerivation (args // {
|
||||
|
||||
maintainers = with lib.maintainers; [ ashalkhakov matthewbauer ];
|
||||
platforms = lib.platforms.linux;
|
||||
} // (if builtins.hasAttr "meta" args then args.meta else {});
|
||||
} // (lib.optionalAttrs (builtins.hasAttr "meta" args) args.meta);
|
||||
})
|
||||
|
@ -26,9 +26,7 @@ final: prev: let
|
||||
in lib.mapAttrs buildCudaToolkitRedistPackage attrs;
|
||||
|
||||
# All cudatoolkit redist packages for the current cuda version
|
||||
cudaToolkitRedistPackages = if
|
||||
lib.hasAttr cudaVersion cudaToolkitRedistManifests
|
||||
then buildCudaToolkitRedistPackages { version = cudaVersion; manifest = cudaToolkitRedistManifests.${cudaVersion}; }
|
||||
else {};
|
||||
cudaToolkitRedistPackages = lib.optionalAttrs (lib.hasAttr cudaVersion cudaToolkitRedistManifests)
|
||||
(buildCudaToolkitRedistPackages { version = cudaVersion; manifest = cudaToolkitRedistManifests.${cudaVersion}; });
|
||||
|
||||
in cudaToolkitRedistPackages
|
||||
|
@ -36,4 +36,4 @@
|
||||
maintainers = with maintainers; [ siraben ];
|
||||
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"; })
|
||||
|
@ -146,7 +146,7 @@ stdenv.mkDerivation rec {
|
||||
luaOnBuildForHost = override pkgsBuildHost.${luaAttr};
|
||||
luaOnBuildForTarget = override pkgsBuildTarget.${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 = {
|
||||
|
@ -127,7 +127,7 @@ stdenv.mkDerivation rec {
|
||||
luaOnBuildForHost = override pkgsBuildHost.${luaAttr};
|
||||
luaOnBuildForTarget = override pkgsBuildTarget.${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; {
|
||||
|
@ -109,7 +109,7 @@ let
|
||||
pythonOnBuildForHost = override pkgsBuildHost.${pythonAttr};
|
||||
pythonOnBuildForTarget = override pkgsBuildTarget.${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}";
|
||||
|
@ -1,4 +1,4 @@
|
||||
{ stdenv, hspell }:
|
||||
{ lib, stdenv, hspell }:
|
||||
|
||||
let
|
||||
dict = variant: a: stdenv.mkDerivation ({
|
||||
@ -8,7 +8,7 @@ let
|
||||
meta = hspell.meta // {
|
||||
broken = true;
|
||||
description = "${variant} Hebrew dictionary";
|
||||
} // (if a ? meta then a.meta else {});
|
||||
} // (lib.optionalAttrs (a ? meta) a.meta);
|
||||
} // (removeAttrs a ["meta"]));
|
||||
in
|
||||
{
|
||||
|
@ -221,9 +221,8 @@ let
|
||||
};
|
||||
|
||||
qlpkgs =
|
||||
if builtins.pathExists ./imported.nix
|
||||
then import ./imported.nix { inherit (pkgs) runCommand fetchzip; pkgs = builtQlpkgs; }
|
||||
else {};
|
||||
lib.optionalAttrs (builtins.pathExists ./imported.nix)
|
||||
(import ./imported.nix { inherit (pkgs) runCommand fetchzip; pkgs = builtQlpkgs; });
|
||||
|
||||
builtQlpkgs = mapAttrs (n: v: build v) qlpkgs;
|
||||
|
||||
|
@ -230,8 +230,7 @@ let
|
||||
});
|
||||
|
||||
qlpkgs =
|
||||
if builtins.pathExists ./imported.nix
|
||||
then pkgs.callPackage ./imported.nix { inherit build-asdf-system; }
|
||||
else {};
|
||||
lib.optionalAttrs (builtins.pathExists ./imported.nix)
|
||||
(pkgs.callPackage ./imported.nix { inherit build-asdf-system; });
|
||||
|
||||
in qlpkgs.overrideScope' overrides
|
||||
|
@ -28,7 +28,7 @@ stdenv.mkDerivation (rec {
|
||||
inherit (ocaml.meta) platforms;
|
||||
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";
|
||||
} else {})
|
||||
})
|
||||
)
|
||||
|
@ -320,10 +320,10 @@ stdenv.mkDerivation rec {
|
||||
sha256 = "1mm4awx6sa0myiz9j4hwp71rpr7yh8vihf3zm15n2ii6xb82r31k";
|
||||
};
|
||||
|
||||
in (if !stdenv.hostPlatform.isDarwin then {
|
||||
in (lib.optionalAttrs (!stdenv.hostPlatform.isDarwin) {
|
||||
# `extracted` doesn’t work on darwin
|
||||
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; };
|
||||
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; };
|
||||
|
@ -285,10 +285,10 @@ stdenv.mkDerivation rec {
|
||||
sha256 = "1mm4awx6sa0myiz9j4hwp71rpr7yh8vihf3zm15n2ii6xb82r31k";
|
||||
};
|
||||
|
||||
in (if !stdenv.hostPlatform.isDarwin then {
|
||||
in (lib.optionalSttrs (!stdenv.hostPlatform.isDarwin) {
|
||||
# `extracted` doesn’t work on darwin
|
||||
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;};
|
||||
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;};
|
||||
|
@ -295,10 +295,10 @@ stdenv.mkDerivation rec {
|
||||
sha256 = "1mm4awx6sa0myiz9j4hwp71rpr7yh8vihf3zm15n2ii6xb82r31k";
|
||||
};
|
||||
|
||||
in (if !stdenv.hostPlatform.isDarwin then {
|
||||
in (lib.optionalAttrs (!stdenv.hostPlatform.isDarwin) {
|
||||
# `extracted` doesn’t work on darwin
|
||||
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;};
|
||||
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;};
|
||||
|
Loading…
Reference in New Issue
Block a user