treewide: use optionalAttrs instead of 'else {}'

authored by

Felix Buehler and committed by
Anderson Torres
6672dde5 fa6b5a3c

+51 -66
+2 -3
nixos/modules/services/audio/roon-bridge.nix
··· 70 70 71 71 users.groups.${cfg.group} = {}; 72 72 users.users.${cfg.user} = 73 - if cfg.user == "roon-bridge" then { 73 + optionalAttrs (cfg.user == "roon-bridge") { 74 74 isSystemUser = true; 75 75 description = "Roon Bridge user"; 76 76 group = cfg.group; 77 77 extraGroups = [ "audio" ]; 78 - } 79 - else {}; 78 + }; 80 79 }; 81 80 }
+2 -3
nixos/modules/services/audio/roon-server.nix
··· 76 76 77 77 users.groups.${cfg.group} = {}; 78 78 users.users.${cfg.user} = 79 - if cfg.user == "roon-server" then { 79 + optionalAttrs (cfg.user == "roon-server") { 80 80 isSystemUser = true; 81 81 description = "Roon Server user"; 82 82 group = cfg.group; 83 83 extraGroups = [ "audio" ]; 84 - } 85 - else {}; 84 + }; 86 85 }; 87 86 }
+1 -1
nixos/modules/services/hardware/fwupd.nix
··· 50 50 # to install it because it would create a cyclic dependency between 51 51 # the outputs. We also need to enable the remote, 52 52 # which should not be done by default. 53 - if cfg.enableTestRemote then (enableRemote cfg.package.installedTests "fwupd-tests") else {} 53 + lib.optionalAttrs cfg.enableTestRemote (enableRemote cfg.package.installedTests "fwupd-tests") 54 54 ); 55 55 56 56 in {
+2 -2
nixos/modules/services/misc/disnix.nix
··· 87 87 environment = { 88 88 HOME = "/root"; 89 89 } 90 - // (if config.environment.variables ? DYSNOMIA_CONTAINERS_PATH then { inherit (config.environment.variables) DYSNOMIA_CONTAINERS_PATH; } else {}) 91 - // (if config.environment.variables ? DYSNOMIA_MODULES_PATH then { inherit (config.environment.variables) DYSNOMIA_MODULES_PATH; } else {}); 90 + // (optionalAttrs (config.environment.variables ? DYSNOMIA_CONTAINERS_PATH) { inherit (config.environment.variables) DYSNOMIA_CONTAINERS_PATH; }) 91 + // (optionalAttrs (config.environment.variables ? DYSNOMIA_MODULES_PATH) { inherit (config.environment.variables) DYSNOMIA_MODULES_PATH; }); 92 92 93 93 serviceConfig.ExecStart = "${cfg.package}/bin/disnix-service"; 94 94 };
+3 -7
nixos/modules/services/misc/docker-registry.nix
··· 15 15 storage = { 16 16 cache.blobdescriptor = blobCache; 17 17 delete.enabled = cfg.enableDelete; 18 - } // (if cfg.storagePath != null 19 - then { filesystem.rootdirectory = cfg.storagePath; } 20 - else {}); 18 + } // (optionalAttrs (cfg.storagePath != null) { filesystem.rootdirectory = cfg.storagePath; }); 21 19 http = { 22 20 addr = "${cfg.listenAddress}:${builtins.toString cfg.port}"; 23 21 headers.X-Content-Type-Options = ["nosniff"]; ··· 152 150 }; 153 151 154 152 users.users.docker-registry = 155 - (if cfg.storagePath != null 156 - then { 153 + (optionalAttrs (cfg.storagePath != null) { 157 154 createHome = true; 158 155 home = cfg.storagePath; 159 - } 160 - else {}) // { 156 + }) // { 161 157 group = "docker-registry"; 162 158 isSystemUser = true; 163 159 };
+2 -3
nixos/modules/services/networking/zerobin.nix
··· 75 75 76 76 config = mkIf (cfg.enable) { 77 77 users.users.${cfg.user} = 78 - if cfg.user == "zerobin" then { 78 + optionalAttrs (cfg.user == "zerobin") { 79 79 isSystemUser = true; 80 80 group = cfg.group; 81 81 home = cfg.dataDir; 82 82 createHome = true; 83 - } 84 - else {}; 83 + }; 85 84 users.groups.${cfg.group} = {}; 86 85 87 86 systemd.services.zerobin = {
+4 -4
nixos/modules/virtualisation/nixos-containers.nix
··· 800 800 # declarative containers 801 801 ++ (mapAttrsToList (name: cfg: nameValuePair "container@${name}" (let 802 802 containerConfig = cfg // ( 803 - if cfg.enableTun then 803 + optionalAttrs cfg.enableTun 804 804 { 805 805 allowedDevices = cfg.allowedDevices 806 806 ++ [ { node = "/dev/net/tun"; modifier = "rw"; } ]; 807 807 additionalCapabilities = cfg.additionalCapabilities 808 808 ++ [ "CAP_NET_ADMIN" ]; 809 809 } 810 - else {}); 810 + ); 811 811 in 812 812 recursiveUpdate unit { 813 813 preStart = preStartScript containerConfig; ··· 817 817 unitConfig.RequiresMountsFor = lib.optional (!containerConfig.ephemeral) "${stateDirectory}/%i"; 818 818 environment.root = if containerConfig.ephemeral then "/run/nixos-containers/%i" else "${stateDirectory}/%i"; 819 819 } // ( 820 - if containerConfig.autoStart then 820 + optionalAttrs containerConfig.autoStart 821 821 { 822 822 wantedBy = [ "machines.target" ]; 823 823 wants = [ "network.target" ]; ··· 828 828 ]; 829 829 restartIfChanged = true; 830 830 } 831 - else {}) 831 + ) 832 832 )) config.containers) 833 833 )); 834 834
+1 -1
nixos/tests/virtualbox.nix
··· 519 519 destroy_vm_test1() 520 520 destroy_vm_test2() 521 521 ''; 522 - } // (if enableUnfree then unfreeTests else {}) 522 + } // (lib.optionalAttrs enableUnfree unfreeTests)
+2 -2
pkgs/build-support/bintools-wrapper/default.nix
··· 388 388 }; 389 389 390 390 meta = 391 - let bintools_ = if bintools != null then bintools else {}; in 392 - (if bintools_ ? meta then removeAttrs bintools.meta ["priority"] else {}) // 391 + let bintools_ = lib.optionalAttrs (bintools != null) bintools; in 392 + (lib.optionalAttrs (bintools_ ? meta) (removeAttrs bintools.meta ["priority"])) // 393 393 { description = 394 394 lib.attrByPath ["meta" "description"] "System binary utilities" bintools_ 395 395 + " (wrapper script)";
+2 -2
pkgs/build-support/cc-wrapper/default.nix
··· 611 611 }; 612 612 613 613 meta = 614 - let cc_ = if cc != null then cc else {}; in 615 - (if cc_ ? meta then removeAttrs cc.meta ["priority"] else {}) // 614 + let cc_ = lib.optionalAttrs (cc != null) cc; in 615 + (lib.optionalAttrs (cc_ ? meta) (removeAttrs cc.meta ["priority"])) // 616 616 { description = 617 617 lib.attrByPath ["meta" "description"] "System C compiler" cc_ 618 618 + " (wrapper script)";
+1 -3
pkgs/build-support/emacs/buffer.nix
··· 73 73 haskell-package-env = 74 74 builtins.head haskell-package.env.nativeBuildInputs; 75 75 in 76 - if is-haskell-package 77 - then withPackages [ haskell-package-env ] 78 - else {}; 76 + lib.optionalAttrs is-haskell-package (withPackages [ haskell-package-env ]); 79 77 }
+2 -2
pkgs/build-support/pkg-config-wrapper/default.nix
··· 119 119 }; 120 120 121 121 meta = 122 - let pkg-config_ = if pkg-config != null then pkg-config else {}; in 123 - (if pkg-config_ ? meta then removeAttrs pkg-config.meta ["priority"] else {}) // 122 + let pkg-config_ = lib.optionalAttrs (pkg-config != null) pkg-config; in 123 + (lib.optionalAttrs (pkg-config_ ? meta) (removeAttrs pkg-config.meta ["priority"])) // 124 124 { description = 125 125 lib.attrByPath ["meta" "description"] "pkg-config" pkg-config_ 126 126 + " (wrapper script)";
+1 -1
pkgs/build-support/release/binary-tarball.nix
··· 70 70 test -n "$releaseName" && (echo "$releaseName" >> $out/nix-support/hydra-release-name) 71 71 ''; 72 72 73 - meta = (if args ? meta then args.meta else {}) // { 73 + meta = (lib.optionalAttrs (args ? meta) args.meta) // { 74 74 description = "Build of a generic binary distribution"; 75 75 }; 76 76
+1 -1
pkgs/build-support/release/debian-build.nix
··· 86 86 eval "$postInstall" 87 87 ''; 88 88 89 - meta = (if args ? meta then args.meta else {}) // { 89 + meta = (lib.optionalAttrs (args ? meta) args.meta) // { 90 90 description = "Deb package for ${diskImage.fullName}"; 91 91 }; 92 92 }
+1 -1
pkgs/build-support/release/nix-build.nix
··· 146 146 147 147 postPhases = postPhases ++ ["finalPhase"]; 148 148 149 - meta = (if args ? meta then args.meta else {}) // { 149 + meta = (lib.optionalAttrs (args ? meta) args.meta) // { 150 150 description = if doCoverageAnalysis then "Coverage analysis" else "Nix package for ${stdenv.hostPlatform.system}"; 151 151 }; 152 152
+1 -1
pkgs/build-support/release/rpm-build.nix
··· 46 46 done 47 47 ''; 48 48 49 - meta = (if args ? meta then args.meta else {}) // { 49 + meta = (lib.optionalAttrs (args ? meta) args.meta) // { 50 50 description = "RPM package for ${diskImage.fullName}"; 51 51 }; 52 52 }
+1 -3
pkgs/build-support/rust/build-rust-crate/test/rcgen-crates.nix
··· 24 24 , release ? true 25 25 # Additional crate2nix configuration if it exists. 26 26 , crateConfig 27 - ? if builtins.pathExists ./crate-config.nix 28 - then pkgs.callPackage ./crate-config.nix {} 29 - else {} 27 + ? lib.optionalAttrs (builtins.pathExists ./crate-config.nix) (pkgs.callPackage ./crate-config.nix {}) 30 28 }: 31 29 32 30 rec {
+1 -1
pkgs/data/icons/apple-cursor/default.nix
··· 8 8 name = variant; 9 9 url = "https://github.com/ful1e5/apple_cursor/releases/download/v${version}/${variant}.${suffix}"; 10 10 hash = hash; 11 - } // (if suffix == "zip" then { stripRoot = false; } else {})); 11 + } // (lib.optionalAttrs (suffix == "zip") { stripRoot = false; })); 12 12 13 13 version = "2.0.0"; 14 14 srcs = [
+1 -1
pkgs/desktops/gnustep/make/gsmakeDerivation.nix
··· 15 15 16 16 maintainers = with lib.maintainers; [ ashalkhakov matthewbauer ]; 17 17 platforms = lib.platforms.linux; 18 - } // (if builtins.hasAttr "meta" args then args.meta else {}); 18 + } // (lib.optionalAttrs (builtins.hasAttr "meta" args) args.meta); 19 19 })
+2 -4
pkgs/development/compilers/cudatoolkit/redist/extension.nix
··· 26 26 in lib.mapAttrs buildCudaToolkitRedistPackage attrs; 27 27 28 28 # All cudatoolkit redist packages for the current cuda version 29 - cudaToolkitRedistPackages = if 30 - lib.hasAttr cudaVersion cudaToolkitRedistManifests 31 - then buildCudaToolkitRedistPackages { version = cudaVersion; manifest = cudaToolkitRedistManifests.${cudaVersion}; } 32 - else {}; 29 + cudaToolkitRedistPackages = lib.optionalAttrs (lib.hasAttr cudaVersion cudaToolkitRedistManifests) 30 + (buildCudaToolkitRedistPackages { version = cudaVersion; manifest = cudaToolkitRedistManifests.${cudaVersion}; }); 33 31 34 32 in cudaToolkitRedistPackages
+1 -1
pkgs/development/coq-modules/zorns-lemma/default.nix
··· 36 36 maintainers = with maintainers; [ siraben ]; 37 37 license = licenses.lgpl21Plus; 38 38 }; 39 - }).overrideAttrs({version, ...}: if lib.versions.isGe "9.0" version then { repo = "topology"; } else {}) 39 + }).overrideAttrs({version, ...}: lib.optionalAttrs (lib.versions.isGe "9.0" version) { repo = "topology"; })
+1 -1
pkgs/development/interpreters/lua-5/interpreter.nix
··· 146 146 luaOnBuildForHost = override pkgsBuildHost.${luaAttr}; 147 147 luaOnBuildForTarget = override pkgsBuildTarget.${luaAttr}; 148 148 luaOnHostForHost = override pkgsHostHost.${luaAttr}; 149 - luaOnTargetForTarget = if lib.hasAttr luaAttr pkgsTargetTarget then (override pkgsTargetTarget.${luaAttr}) else {}; 149 + luaOnTargetForTarget = lib.optionalAttrs (lib.hasAttr luaAttr pkgsTargetTarget) (override pkgsTargetTarget.${luaAttr}); 150 150 }; 151 151 152 152 meta = {
+1 -1
pkgs/development/interpreters/luajit/default.nix
··· 127 127 luaOnBuildForHost = override pkgsBuildHost.${luaAttr}; 128 128 luaOnBuildForTarget = override pkgsBuildTarget.${luaAttr}; 129 129 luaOnHostForHost = override pkgsHostHost.${luaAttr}; 130 - luaOnTargetForTarget = if lib.hasAttr luaAttr pkgsTargetTarget then (override pkgsTargetTarget.${luaAttr}) else {}; 130 + luaOnTargetForTarget = lib.optionalAttrs (lib.hasAttr luaAttr pkgsTargetTarget) (override pkgsTargetTarget.${luaAttr}); 131 131 }; 132 132 133 133 meta = with lib; {
+1 -1
pkgs/development/interpreters/python/cpython/default.nix
··· 109 109 pythonOnBuildForHost = override pkgsBuildHost.${pythonAttr}; 110 110 pythonOnBuildForTarget = override pkgsBuildTarget.${pythonAttr}; 111 111 pythonOnHostForHost = override pkgsHostHost.${pythonAttr}; 112 - pythonOnTargetForTarget = if lib.hasAttr pythonAttr pkgsTargetTarget then (override pkgsTargetTarget.${pythonAttr}) else {}; 112 + pythonOnTargetForTarget = lib.optionalAttrs (lib.hasAttr pythonAttr pkgsTargetTarget) (override pkgsTargetTarget.${pythonAttr}); 113 113 }; 114 114 115 115 version = with sourceVersion; "${major}.${minor}.${patch}${suffix}";
+2 -2
pkgs/development/libraries/hspell/dicts.nix
··· 1 - { stdenv, hspell }: 1 + { lib, stdenv, hspell }: 2 2 3 3 let 4 4 dict = variant: a: stdenv.mkDerivation ({ ··· 8 8 meta = hspell.meta // { 9 9 broken = true; 10 10 description = "${variant} Hebrew dictionary"; 11 - } // (if a ? meta then a.meta else {}); 11 + } // (lib.optionalAttrs (a ? meta) a.meta); 12 12 } // (removeAttrs a ["meta"])); 13 13 in 14 14 {
+2 -3
pkgs/development/lisp-modules-new-obsolete/ql.nix
··· 221 221 }; 222 222 223 223 qlpkgs = 224 - if builtins.pathExists ./imported.nix 225 - then import ./imported.nix { inherit (pkgs) runCommand fetchzip; pkgs = builtQlpkgs; } 226 - else {}; 224 + lib.optionalAttrs (builtins.pathExists ./imported.nix) 225 + (import ./imported.nix { inherit (pkgs) runCommand fetchzip; pkgs = builtQlpkgs; }); 227 226 228 227 builtQlpkgs = mapAttrs (n: v: build v) qlpkgs; 229 228
+2 -3
pkgs/development/lisp-modules/ql.nix
··· 230 230 }); 231 231 232 232 qlpkgs = 233 - if builtins.pathExists ./imported.nix 234 - then pkgs.callPackage ./imported.nix { inherit build-asdf-system; } 235 - else {}; 233 + lib.optionalAttrs (builtins.pathExists ./imported.nix) 234 + (pkgs.callPackage ./imported.nix { inherit build-asdf-system; }); 236 235 237 236 in qlpkgs.overrideScope' overrides
+2 -2
pkgs/development/ocaml-modules/num/default.nix
··· 28 28 inherit (ocaml.meta) platforms; 29 29 inherit (src.meta) homepage; 30 30 }; 31 - } // (if lib.versions.majorMinor ocaml.version == "4.06" then { 31 + } // (lib.optionalAttrs (lib.versions.majorMinor ocaml.version == "4.06") { 32 32 env.NIX_CFLAGS_COMPILE = "-fcommon"; 33 - } else {}) 33 + }) 34 34 )
+2 -2
pkgs/development/tools/build-managers/bazel/bazel_4/default.nix
··· 320 320 sha256 = "1mm4awx6sa0myiz9j4hwp71rpr7yh8vihf3zm15n2ii6xb82r31k"; 321 321 }; 322 322 323 - in (if !stdenv.hostPlatform.isDarwin then { 323 + in (lib.optionalAttrs (!stdenv.hostPlatform.isDarwin) { 324 324 # `extracted` doesn’t work on darwin 325 325 shebang = callPackage ../shebang-test.nix { inherit runLocal extracted bazelTest distDir; bazel = bazel_self; }; 326 - } else {}) // { 326 + }) // { 327 327 bashTools = callPackage ../bash-tools-test.nix { inherit runLocal bazelTest distDir; bazel = bazel_self; }; 328 328 cpp = callPackage ../cpp-test.nix { inherit runLocal bazelTest bazel-examples distDir; bazel = bazel_self; }; 329 329 java = callPackage ../java-test.nix { inherit runLocal bazelTest bazel-examples distDir; bazel = bazel_self; };
+2 -2
pkgs/development/tools/build-managers/bazel/bazel_5/default.nix
··· 285 285 sha256 = "1mm4awx6sa0myiz9j4hwp71rpr7yh8vihf3zm15n2ii6xb82r31k"; 286 286 }; 287 287 288 - in (if !stdenv.hostPlatform.isDarwin then { 288 + in (lib.optionalSttrs (!stdenv.hostPlatform.isDarwin) { 289 289 # `extracted` doesn’t work on darwin 290 290 shebang = callPackage ../shebang-test.nix { inherit runLocal extracted bazelTest distDir; bazel = bazel_self;}; 291 - } else {}) // { 291 + }) // { 292 292 bashTools = callPackage ../bash-tools-test.nix { inherit runLocal bazelTest distDir; bazel = bazel_self;}; 293 293 cpp = callPackage ../cpp-test.nix { inherit runLocal bazelTest bazel-examples distDir; bazel = bazel_self;}; 294 294 java = callPackage ../java-test.nix { inherit runLocal bazelTest bazel-examples distDir; bazel = bazel_self;};
+2 -2
pkgs/development/tools/build-managers/bazel/bazel_6/default.nix
··· 295 295 sha256 = "1mm4awx6sa0myiz9j4hwp71rpr7yh8vihf3zm15n2ii6xb82r31k"; 296 296 }; 297 297 298 - in (if !stdenv.hostPlatform.isDarwin then { 298 + in (lib.optionalAttrs (!stdenv.hostPlatform.isDarwin) { 299 299 # `extracted` doesn’t work on darwin 300 300 shebang = callPackage ../shebang-test.nix { inherit runLocal extracted bazelTest distDir; bazel = bazel_self;}; 301 - } else {}) // { 301 + }) // { 302 302 bashTools = callPackage ../bash-tools-test.nix { inherit runLocal bazelTest distDir; bazel = bazel_self;}; 303 303 cpp = callPackage ../cpp-test.nix { inherit runLocal bazelTest bazel-examples distDir; bazel = bazel_self;}; 304 304 java = callPackage ../java-test.nix { inherit runLocal bazelTest bazel-examples distDir; bazel = bazel_self;};