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