at 17.09-beta 3.0 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 && !builtins.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 relocateOthers = null; 35 in 36 { nixos = map relocateNixOS partitionedModuleFiles.nixos; 37 others = []; # TODO: copy the modules to the install-device repository. 38 }; 39 40 # A dummy /etc/nixos/configuration.nix in the booted CD that 41 # rebuilds the CD's configuration (and allows the configuration to 42 # be modified, of course, providing a true live CD). Problem is 43 # that we don't really know how the CD was built - the Nix 44 # expression language doesn't allow us to query the expression being 45 # evaluated. So we'll just hope for the best. 46 configClone = pkgs.writeText "configuration.nix" 47 '' 48 { config, pkgs, ... }: 49 50 { 51 imports = [ ${toString config.installer.cloneConfigIncludes} ]; 52 } 53 ''; 54 55in 56 57{ 58 59 options = { 60 61 installer.cloneConfig = mkOption { 62 default = true; 63 description = '' 64 Try to clone the installation-device configuration by re-using it's 65 profile from the list of imported modules. 66 ''; 67 }; 68 69 installer.cloneConfigIncludes = mkOption { 70 default = []; 71 example = [ "./nixos/modules/hardware/network/rt73.nix" ]; 72 description = '' 73 List of modules used to re-build this installation device profile. 74 ''; 75 }; 76 77 }; 78 79 config = { 80 81 installer.cloneConfigIncludes = 82 relocatedModuleFiles.nixos ++ relocatedModuleFiles.others; 83 84 boot.postBootCommands = 85 '' 86 # Provide a mount point for nixos-install. 87 mkdir -p /mnt 88 89 ${optionalString config.installer.cloneConfig '' 90 # Provide a configuration for the CD/DVD itself, to allow users 91 # to run nixos-rebuild to change the configuration of the 92 # running system on the CD/DVD. 93 if ! [ -e /etc/nixos/configuration.nix ]; then 94 cp ${configClone} /etc/nixos/configuration.nix 95 fi 96 ''} 97 ''; 98 99 }; 100 101}