1 { config, lib, pkgs, modules, ... }:
7 # Location of the repository on the harddrive
8 nixosPath = toString ../..;
10 # Check if the path is from the NixOS repository
12 let s = toString path; in
13 removePrefix nixosPath s != s;
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).
19 # FIXME: use typeOf (Nix 1.6.1).
20 filter (x: !isAttrs x && !lib.isFunction x) modules;
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; };
28 # Path transformed to be valid on the installation device. Thus the
29 # device configuration could be rebuild.
30 relocatedModuleFiles =
33 "<nixpkgs/nixos" + removePrefix nixosPath (toString path) + ">";
35 { nixos = map relocateNixOS partitionedModuleFiles.nixos;
36 others = []; # TODO: copy the modules to the install-device repository.
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"
47 { config, pkgs, ... }:
50 imports = [ ${toString config.installer.cloneConfigIncludes} ];
52 ${config.installer.cloneConfigExtra}
62 installer.cloneConfig = mkOption {
65 Try to clone the installation-device configuration by re-using it's
66 profile from the list of imported modules.
70 installer.cloneConfigIncludes = mkOption {
72 example = [ "./nixos/modules/hardware/network/rt73.nix" ];
74 List of modules used to re-build this installation device profile.
78 installer.cloneConfigExtra = mkOption {
81 Extra text to include in the cloned configuration.nix included in this
89 installer.cloneConfigIncludes =
90 relocatedModuleFiles.nixos ++ relocatedModuleFiles.others;
92 boot.postBootCommands =
94 # Provide a mount point for nixos-install.
97 ${optionalString config.installer.cloneConfig ''
98 # Provide a configuration for the CD/DVD itself, to allow users
99 # to run nixos-rebuild to change the configuration of the
100 # running system on the CD/DVD.
101 if ! [ -e /etc/nixos/configuration.nix ]; then
102 cp ${configClone} /etc/nixos/configuration.nix