at 24.11-pre 2.5 kB view raw
1{ config, lib, pkgs, extendModules, noUserModules, ... }: 2 3let 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 23in 24{ 25 options = { 26 27 specialisation = mkOption { 28 default = { }; 29 example = lib.literalExpression "{ fewJobsManyCores.configuration = { nix.settings = { core = 0; max-jobs = 1; }; }; }"; 30 description = '' 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 = "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 = '' 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}