at 25.11-pre 3.2 kB view raw
1{ 2 config, 3 lib, 4 pkgs, 5 modules, 6 ... 7}: 8 9with lib; 10 11let 12 13 # Location of the repository on the harddrive 14 nixosPath = toString ../..; 15 16 # Check if the path is from the NixOS repository 17 isNixOSFile = 18 path: 19 let 20 s = toString path; 21 in 22 removePrefix nixosPath s != s; 23 24 # Copy modules given as extra configuration files. Unfortunately, we 25 # cannot serialized attribute set given in the list of modules (that's why 26 # you should use files). 27 moduleFiles = 28 # FIXME: use typeOf (Nix 1.6.1). 29 filter (x: !isAttrs x && !lib.isFunction x) modules; 30 31 # Partition module files because between NixOS and non-NixOS files. NixOS 32 # files may change if the repository is updated. 33 partitionedModuleFiles = 34 let 35 p = partition isNixOSFile moduleFiles; 36 in 37 { 38 nixos = p.right; 39 others = p.wrong; 40 }; 41 42 # Path transformed to be valid on the installation device. Thus the 43 # device configuration could be rebuild. 44 relocatedModuleFiles = 45 let 46 relocateNixOS = path: "<nixpkgs/nixos" + removePrefix nixosPath (toString path) + ">"; 47 in 48 { 49 nixos = map relocateNixOS partitionedModuleFiles.nixos; 50 others = [ ]; # TODO: copy the modules to the install-device repository. 51 }; 52 53 # A dummy /etc/nixos/configuration.nix in the booted CD that 54 # rebuilds the CD's configuration (and allows the configuration to 55 # be modified, of course, providing a true live CD). Problem is 56 # that we don't really know how the CD was built - the Nix 57 # expression language doesn't allow us to query the expression being 58 # evaluated. So we'll just hope for the best. 59 configClone = pkgs.writeText "configuration.nix" '' 60 { config, pkgs, ... }: 61 62 { 63 imports = [ ${toString config.installer.cloneConfigIncludes} ]; 64 65 ${config.installer.cloneConfigExtra} 66 } 67 ''; 68 69in 70 71{ 72 73 options = { 74 75 installer.cloneConfig = mkOption { 76 default = true; 77 description = '' 78 Try to clone the installation-device configuration by re-using it's 79 profile from the list of imported modules. 80 ''; 81 }; 82 83 installer.cloneConfigIncludes = mkOption { 84 default = [ ]; 85 example = [ "./nixos/modules/hardware/network/rt73.nix" ]; 86 description = '' 87 List of modules used to re-build this installation device profile. 88 ''; 89 }; 90 91 installer.cloneConfigExtra = mkOption { 92 default = ""; 93 description = '' 94 Extra text to include in the cloned configuration.nix included in this 95 installer. 96 ''; 97 }; 98 }; 99 100 config = { 101 102 installer.cloneConfigIncludes = relocatedModuleFiles.nixos ++ relocatedModuleFiles.others; 103 104 boot.postBootCommands = '' 105 # Provide a mount point for nixos-install. 106 mkdir -p /mnt 107 108 ${optionalString config.installer.cloneConfig '' 109 # Provide a configuration for the CD/DVD itself, to allow users 110 # to run nixos-rebuild to change the configuration of the 111 # running system on the CD/DVD. 112 if ! [ -e /etc/nixos/configuration.nix ]; then 113 cp ${configClone} /etc/nixos/configuration.nix 114 fi 115 ''} 116 ''; 117 118 }; 119 120}