···11+{ config, lib, pkgs, extendModules, noUserModules, ... }:
22+33+let
44+ inherit (lib)
55+ concatStringsSep
66+ mapAttrs
77+ mapAttrsToList
88+ mkOption
99+ types
1010+ ;
1111+1212+ # This attribute is responsible for creating boot entries for
1313+ # child configuration. They are only (directly) accessible
1414+ # when the parent configuration is boot default. For example,
1515+ # you can provide an easy way to boot the same configuration
1616+ # as you use, but with another kernel
1717+ # !!! fix this
1818+ children =
1919+ mapAttrs
2020+ (childName: childConfig: childConfig.configuration.system.build.toplevel)
2121+ config.specialisation;
2222+2323+in
2424+{
2525+ options = {
2626+2727+ specialisation = mkOption {
2828+ default = { };
2929+ example = lib.literalExpression "{ fewJobsManyCores.configuration = { nix.settings = { core = 0; max-jobs = 1; }; }; }";
3030+ description = lib.mdDoc ''
3131+ Additional configurations to build. If
3232+ `inheritParentConfig` is true, the system
3333+ will be based on the overall system configuration.
3434+3535+ To switch to a specialised configuration
3636+ (e.g. `fewJobsManyCores`) at runtime, run:
3737+3838+ ```
3939+ sudo /run/current-system/specialisation/fewJobsManyCores/bin/switch-to-configuration test
4040+ ```
4141+ '';
4242+ type = types.attrsOf (types.submodule (
4343+ local@{ ... }:
4444+ let
4545+ extend =
4646+ if local.config.inheritParentConfig
4747+ then extendModules
4848+ else noUserModules.extendModules;
4949+ in
5050+ {
5151+ options.inheritParentConfig = mkOption {
5252+ type = types.bool;
5353+ default = true;
5454+ description = lib.mdDoc "Include the entire system's configuration. Set to false to make a completely differently configured system.";
5555+ };
5656+5757+ options.configuration = mkOption {
5858+ default = { };
5959+ description = lib.mdDoc ''
6060+ Arbitrary NixOS configuration.
6161+6262+ Anything you can add to a normal NixOS configuration, you can add
6363+ here, including imports and config values, although nested
6464+ specialisations will be ignored.
6565+ '';
6666+ visible = "shallow";
6767+ inherit (extend { modules = [ ./no-clone.nix ]; }) type;
6868+ };
6969+ }
7070+ ));
7171+ };
7272+7373+ };
7474+7575+ config = {
7676+ system.systemBuilderCommands = ''
7777+ mkdir $out/specialisation
7878+ ${concatStringsSep "\n"
7979+ (mapAttrsToList (name: path: "ln -s ${path} $out/specialisation/${name}") children)}
8080+ '';
8181+ };
8282+8383+ # uses extendModules to generate a type
8484+ meta.buildDocsInSandbox = false;
8585+}
+24-79
nixos/modules/system/activation/top-level.nix
···11-{ config, lib, pkgs, extendModules, noUserModules, ... }:
11+{ config, lib, pkgs, ... }:
2233with lib;
4455let
66-77-88- # This attribute is responsible for creating boot entries for
99- # child configuration. They are only (directly) accessible
1010- # when the parent configuration is boot default. For example,
1111- # you can provide an easy way to boot the same configuration
1212- # as you use, but with another kernel
1313- # !!! fix this
1414- children =
1515- mapAttrs
1616- (childName: childConfig: childConfig.configuration.system.build.toplevel)
1717- config.specialisation;
1818-196 systemBuilder =
207 let
218 kernelPath = "${config.boot.kernelPackages.kernel}/" +
···7259 ln -s ${config.system.path} $out/sw
7360 ln -s "$systemd" $out/systemd
74617575- echo -n "$configurationName" > $out/configuration-name
7662 echo -n "systemd ${toString config.systemd.package.interfaceVersion}" > $out/init-interface-version
7763 echo -n "$nixosLabel" > $out/nixos-version
7864 echo -n "${config.boot.kernelPackages.stdenv.hostPlatform.system}" > $out/system
7979-8080- mkdir $out/specialisation
8181- ${concatStringsSep "\n"
8282- (mapAttrsToList (name: path: "ln -s ${path} $out/specialisation/${name}") children)}
83658466 mkdir $out/bin
8567 export localeArchive="${config.i18n.glibcLocales}/lib/locale/locale-archive"
···9375 fi
9476 ''}
95777878+ ${config.system.systemBuilderCommands}
7979+9680 echo -n "${toString config.system.extraDependencies}" > $out/extra-dependencies
97819882 ${config.system.extraSystemBuilderCmds}
···10387 # kernel, systemd units, init scripts, etc.) as well as a script
10488 # `switch-to-configuration' that activates the configuration and
10589 # makes it bootable.
106106- baseSystem = pkgs.stdenvNoCC.mkDerivation {
9090+ baseSystem = pkgs.stdenvNoCC.mkDerivation ({
10791 name = "nixos-system-${config.system.name}-${config.system.nixos.label}";
10892 preferLocalBuild = true;
10993 allowSubstitutes = false;
···120104 activationScript = config.system.activationScripts.script;
121105 dryActivationScript = config.system.dryActivationScript;
122106 nixosLabel = config.system.nixos.label;
123123-124124- configurationName = config.boot.loader.grub.configurationName;
125107126108 # Needed by switch-to-configuration.
127109 perl = pkgs.perl.withPackages (p: with p; [ ConfigIniFiles FileSlurp ]);
128128- };
110110+ } // config.system.systemBuilderArgs);
129111130112 # Handle assertions and warnings
131113···140122 pkgs.replaceDependency { inherit oldDependency newDependency drv; }
141123 ) baseSystemAssertWarn config.system.replaceRuntimeDependencies;
142124143143- /* Workaround until https://github.com/NixOS/nixpkgs/pull/156533
144144- Call can be replaced by argument when that's merged.
145145- */
146146- tmpFixupSubmoduleBoundary = subopts:
147147- lib.mkOption {
148148- type = lib.types.submoduleWith {
149149- modules = [ { options = subopts; } ];
150150- };
151151- };
152152-153125in
154126155127{
···161133162134 options = {
163135164164- specialisation = mkOption {
165165- default = {};
166166- example = lib.literalExpression "{ fewJobsManyCores.configuration = { nix.settings = { core = 0; max-jobs = 1; }; }; }";
167167- description = lib.mdDoc ''
168168- Additional configurations to build. If
169169- `inheritParentConfig` is true, the system
170170- will be based on the overall system configuration.
171171-172172- To switch to a specialised configuration
173173- (e.g. `fewJobsManyCores`) at runtime, run:
174174-175175- ```
176176- sudo /run/current-system/specialisation/fewJobsManyCores/bin/switch-to-configuration test
177177- ```
178178- '';
179179- type = types.attrsOf (types.submodule (
180180- local@{ ... }: let
181181- extend = if local.config.inheritParentConfig
182182- then extendModules
183183- else noUserModules.extendModules;
184184- in {
185185- options.inheritParentConfig = mkOption {
186186- type = types.bool;
187187- default = true;
188188- description = lib.mdDoc "Include the entire system's configuration. Set to false to make a completely differently configured system.";
189189- };
190190-191191- options.configuration = mkOption {
192192- default = {};
193193- description = lib.mdDoc ''
194194- Arbitrary NixOS configuration.
195195-196196- Anything you can add to a normal NixOS configuration, you can add
197197- here, including imports and config values, although nested
198198- specialisations will be ignored.
199199- '';
200200- visible = "shallow";
201201- inherit (extend { modules = [ ./no-clone.nix ]; }) type;
202202- };
203203- })
204204- );
205205- };
206206-207136 system.boot.loader.id = mkOption {
208137 internal = true;
209138 default = "";
···231160 '';
232161 };
233162234234- system.build = tmpFixupSubmoduleBoundary {
163163+ system.build = {
235164 installBootLoader = mkOption {
236165 internal = true;
237166 # "; true" => make the `$out` argument from switch-to-configuration.pl
···276205 '';
277206 };
278207208208+ system.systemBuilderCommands = mkOption {
209209+ type = types.lines;
210210+ internal = true;
211211+ default = "";
212212+ description = ''
213213+ This code will be added to the builder creating the system store path.
214214+ '';
215215+ };
216216+217217+ system.systemBuilderArgs = mkOption {
218218+ type = types.attrsOf types.unspecified;
219219+ internal = true;
220220+ default = {};
221221+ description = lib.mdDoc ''
222222+ `lib.mkDerivation` attributes that will be passed to the top level system builder.
223223+ '';
224224+ };
225225+279226 system.extraSystemBuilderCmds = mkOption {
280227 type = types.lines;
281228 internal = true;
···357304358305 };
359306360360- # uses extendModules to generate a type
361361- meta.buildDocsInSandbox = false;
362307}