1# Provide an initial copy of the NixOS channel so that the user
2# doesn't need to run "nix-channel --update" first.
3
4{ config, lib, pkgs, ... }:
5
6with lib;
7
8let
9
10 # We need a copy of the Nix expressions for Nixpkgs and NixOS on the
11 # CD. These are installed into the "nixos" channel of the root
12 # user, as expected by nixos-rebuild/nixos-install. FIXME: merge
13 # with make-channel.nix.
14 channelSources = pkgs.runCommand "nixos-${config.system.nixosVersion}"
15 { }
16 ''
17 mkdir -p $out
18 cp -prd ${pkgs.path} $out/nixos
19 chmod -R u+w $out/nixos
20 ln -s . $out/nixos/nixpkgs
21 rm -rf $out/nixos/.git
22 echo -n ${config.system.nixosVersionSuffix} > $out/nixos/.version-suffix
23 '';
24
25in
26
27{
28 # Provide the NixOS/Nixpkgs sources in /etc/nixos. This is required
29 # for nixos-install.
30 boot.postBootCommands = mkAfter
31 ''
32 if ! [ -e /var/lib/nixos/did-channel-init ]; then
33 echo "unpacking the NixOS/Nixpkgs sources..."
34 mkdir -p /nix/var/nix/profiles/per-user/root
35 ${config.nix.package}/bin/nix-env -p /nix/var/nix/profiles/per-user/root/channels \
36 -i ${channelSources} --quiet --option build-use-substitutes false
37 mkdir -m 0700 -p /root/.nix-defexpr
38 ln -s /nix/var/nix/profiles/per-user/root/channels /root/.nix-defexpr/channels
39 mkdir -m 0755 -p /var/lib/nixos
40 touch /var/lib/nixos/did-channel-init
41 fi
42 '';
43}