Merge pull request #199595 from hercules-ci/nixos-toplevel-maintenance

nixos/top-level: maintenance

authored by Robert Hensing and committed by GitHub 59f6a930 93a905ec

+115 -79
+1
nixos/modules/module-list.nix
··· 1224 1224 ./services/x11/xfs.nix 1225 1225 ./services/x11/xserver.nix 1226 1226 ./system/activation/activation-script.nix 1227 + ./system/activation/specialisation.nix 1227 1228 ./system/activation/top-level.nix 1228 1229 ./system/boot/binfmt.nix 1229 1230 ./system/boot/emergency-mode.nix
+85
nixos/modules/system/activation/specialisation.nix
··· 1 + { config, lib, pkgs, extendModules, noUserModules, ... }: 2 + 3 + let 4 + inherit (lib) 5 + concatStringsSep 6 + mapAttrs 7 + mapAttrsToList 8 + mkOption 9 + types 10 + ; 11 + 12 + # This attribute is responsible for creating boot entries for 13 + # child configuration. They are only (directly) accessible 14 + # when the parent configuration is boot default. For example, 15 + # you can provide an easy way to boot the same configuration 16 + # as you use, but with another kernel 17 + # !!! fix this 18 + children = 19 + mapAttrs 20 + (childName: childConfig: childConfig.configuration.system.build.toplevel) 21 + config.specialisation; 22 + 23 + in 24 + { 25 + options = { 26 + 27 + specialisation = mkOption { 28 + default = { }; 29 + example = lib.literalExpression "{ fewJobsManyCores.configuration = { nix.settings = { core = 0; max-jobs = 1; }; }; }"; 30 + description = lib.mdDoc '' 31 + Additional configurations to build. If 32 + `inheritParentConfig` is true, the system 33 + will be based on the overall system configuration. 34 + 35 + To switch to a specialised configuration 36 + (e.g. `fewJobsManyCores`) at runtime, run: 37 + 38 + ``` 39 + sudo /run/current-system/specialisation/fewJobsManyCores/bin/switch-to-configuration test 40 + ``` 41 + ''; 42 + type = types.attrsOf (types.submodule ( 43 + local@{ ... }: 44 + let 45 + extend = 46 + if local.config.inheritParentConfig 47 + then extendModules 48 + else noUserModules.extendModules; 49 + in 50 + { 51 + options.inheritParentConfig = mkOption { 52 + type = types.bool; 53 + default = true; 54 + description = lib.mdDoc "Include the entire system's configuration. Set to false to make a completely differently configured system."; 55 + }; 56 + 57 + options.configuration = mkOption { 58 + default = { }; 59 + description = lib.mdDoc '' 60 + Arbitrary NixOS configuration. 61 + 62 + Anything you can add to a normal NixOS configuration, you can add 63 + here, including imports and config values, although nested 64 + specialisations will be ignored. 65 + ''; 66 + visible = "shallow"; 67 + inherit (extend { modules = [ ./no-clone.nix ]; }) type; 68 + }; 69 + } 70 + )); 71 + }; 72 + 73 + }; 74 + 75 + config = { 76 + system.systemBuilderCommands = '' 77 + mkdir $out/specialisation 78 + ${concatStringsSep "\n" 79 + (mapAttrsToList (name: path: "ln -s ${path} $out/specialisation/${name}") children)} 80 + ''; 81 + }; 82 + 83 + # uses extendModules to generate a type 84 + meta.buildDocsInSandbox = false; 85 + }
+24 -79
nixos/modules/system/activation/top-level.nix
··· 1 - { config, lib, pkgs, extendModules, noUserModules, ... }: 1 + { config, lib, pkgs, ... }: 2 2 3 3 with lib; 4 4 5 5 let 6 - 7 - 8 - # This attribute is responsible for creating boot entries for 9 - # child configuration. They are only (directly) accessible 10 - # when the parent configuration is boot default. For example, 11 - # you can provide an easy way to boot the same configuration 12 - # as you use, but with another kernel 13 - # !!! fix this 14 - children = 15 - mapAttrs 16 - (childName: childConfig: childConfig.configuration.system.build.toplevel) 17 - config.specialisation; 18 - 19 6 systemBuilder = 20 7 let 21 8 kernelPath = "${config.boot.kernelPackages.kernel}/" + ··· 72 59 ln -s ${config.system.path} $out/sw 73 60 ln -s "$systemd" $out/systemd 74 61 75 - echo -n "$configurationName" > $out/configuration-name 76 62 echo -n "systemd ${toString config.systemd.package.interfaceVersion}" > $out/init-interface-version 77 63 echo -n "$nixosLabel" > $out/nixos-version 78 64 echo -n "${config.boot.kernelPackages.stdenv.hostPlatform.system}" > $out/system 79 - 80 - mkdir $out/specialisation 81 - ${concatStringsSep "\n" 82 - (mapAttrsToList (name: path: "ln -s ${path} $out/specialisation/${name}") children)} 83 65 84 66 mkdir $out/bin 85 67 export localeArchive="${config.i18n.glibcLocales}/lib/locale/locale-archive" ··· 93 75 fi 94 76 ''} 95 77 78 + ${config.system.systemBuilderCommands} 79 + 96 80 echo -n "${toString config.system.extraDependencies}" > $out/extra-dependencies 97 81 98 82 ${config.system.extraSystemBuilderCmds} ··· 103 87 # kernel, systemd units, init scripts, etc.) as well as a script 104 88 # `switch-to-configuration' that activates the configuration and 105 89 # makes it bootable. 106 - baseSystem = pkgs.stdenvNoCC.mkDerivation { 90 + baseSystem = pkgs.stdenvNoCC.mkDerivation ({ 107 91 name = "nixos-system-${config.system.name}-${config.system.nixos.label}"; 108 92 preferLocalBuild = true; 109 93 allowSubstitutes = false; ··· 120 104 activationScript = config.system.activationScripts.script; 121 105 dryActivationScript = config.system.dryActivationScript; 122 106 nixosLabel = config.system.nixos.label; 123 - 124 - configurationName = config.boot.loader.grub.configurationName; 125 107 126 108 # Needed by switch-to-configuration. 127 109 perl = pkgs.perl.withPackages (p: with p; [ ConfigIniFiles FileSlurp ]); 128 - }; 110 + } // config.system.systemBuilderArgs); 129 111 130 112 # Handle assertions and warnings 131 113 ··· 140 122 pkgs.replaceDependency { inherit oldDependency newDependency drv; } 141 123 ) baseSystemAssertWarn config.system.replaceRuntimeDependencies; 142 124 143 - /* Workaround until https://github.com/NixOS/nixpkgs/pull/156533 144 - Call can be replaced by argument when that's merged. 145 - */ 146 - tmpFixupSubmoduleBoundary = subopts: 147 - lib.mkOption { 148 - type = lib.types.submoduleWith { 149 - modules = [ { options = subopts; } ]; 150 - }; 151 - }; 152 - 153 125 in 154 126 155 127 { ··· 161 133 162 134 options = { 163 135 164 - specialisation = mkOption { 165 - default = {}; 166 - example = lib.literalExpression "{ fewJobsManyCores.configuration = { nix.settings = { core = 0; max-jobs = 1; }; }; }"; 167 - description = lib.mdDoc '' 168 - Additional configurations to build. If 169 - `inheritParentConfig` is true, the system 170 - will be based on the overall system configuration. 171 - 172 - To switch to a specialised configuration 173 - (e.g. `fewJobsManyCores`) at runtime, run: 174 - 175 - ``` 176 - sudo /run/current-system/specialisation/fewJobsManyCores/bin/switch-to-configuration test 177 - ``` 178 - ''; 179 - type = types.attrsOf (types.submodule ( 180 - local@{ ... }: let 181 - extend = if local.config.inheritParentConfig 182 - then extendModules 183 - else noUserModules.extendModules; 184 - in { 185 - options.inheritParentConfig = mkOption { 186 - type = types.bool; 187 - default = true; 188 - description = lib.mdDoc "Include the entire system's configuration. Set to false to make a completely differently configured system."; 189 - }; 190 - 191 - options.configuration = mkOption { 192 - default = {}; 193 - description = lib.mdDoc '' 194 - Arbitrary NixOS configuration. 195 - 196 - Anything you can add to a normal NixOS configuration, you can add 197 - here, including imports and config values, although nested 198 - specialisations will be ignored. 199 - ''; 200 - visible = "shallow"; 201 - inherit (extend { modules = [ ./no-clone.nix ]; }) type; 202 - }; 203 - }) 204 - ); 205 - }; 206 - 207 136 system.boot.loader.id = mkOption { 208 137 internal = true; 209 138 default = ""; ··· 231 160 ''; 232 161 }; 233 162 234 - system.build = tmpFixupSubmoduleBoundary { 163 + system.build = { 235 164 installBootLoader = mkOption { 236 165 internal = true; 237 166 # "; true" => make the `$out` argument from switch-to-configuration.pl ··· 276 205 ''; 277 206 }; 278 207 208 + system.systemBuilderCommands = mkOption { 209 + type = types.lines; 210 + internal = true; 211 + default = ""; 212 + description = '' 213 + This code will be added to the builder creating the system store path. 214 + ''; 215 + }; 216 + 217 + system.systemBuilderArgs = mkOption { 218 + type = types.attrsOf types.unspecified; 219 + internal = true; 220 + default = {}; 221 + description = lib.mdDoc '' 222 + `lib.mkDerivation` attributes that will be passed to the top level system builder. 223 + ''; 224 + }; 225 + 279 226 system.extraSystemBuilderCmds = mkOption { 280 227 type = types.lines; 281 228 internal = true; ··· 357 304 358 305 }; 359 306 360 - # uses extendModules to generate a type 361 - meta.buildDocsInSandbox = false; 362 307 }
+5
nixos/modules/system/boot/loader/grub/grub.nix
··· 748 748 749 749 boot.loader.supportsInitrdSecrets = true; 750 750 751 + system.systemBuilderArgs.configurationName = cfg.configurationName; 752 + system.systemBuilderCommands = '' 753 + echo -n "$configurationName" > $out/configuration-name 754 + ''; 755 + 751 756 system.build.installBootLoader = 752 757 let 753 758 install-grub-pl = pkgs.substituteAll {