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 nixpkgs = lib.cleanSource pkgs.path;
10
11 # We need a copy of the Nix expressions for Nixpkgs and NixOS on the
12 # CD. These are installed into the "nixos" channel of the root
13 # user, as expected by nixos-rebuild/nixos-install. FIXME: merge
14 # with make-channel.nix.
15 channelSources = pkgs.runCommand "nixos-${config.system.nixos.version}"
16 { }
17 ''
18 mkdir -p $out
19 cp -prd ${nixpkgs} $out/nixos
20 chmod -R u+w $out/nixos
21 if [ ! -e $out/nixos/nixpkgs ]; then
22 ln -s . $out/nixos/nixpkgs
23 fi
24 echo -n ${config.system.nixos.revision} > $out/nixos/.git-revision
25 echo -n ${config.system.nixos.versionSuffix} > $out/nixos/.version-suffix
26 echo ${config.system.nixos.versionSuffix} | sed -e s/pre// > $out/nixos/svn-revision
27 '';
28
29in
30
31{
32 # Provide the NixOS/Nixpkgs sources in /etc/nixos. This is required
33 # for nixos-install.
34 boot.postBootCommands = mkAfter
35 ''
36 if ! [ -e /var/lib/nixos/did-channel-init ]; then
37 echo "unpacking the NixOS/Nixpkgs sources..."
38 mkdir -p /nix/var/nix/profiles/per-user/root
39 ${config.nix.package.out}/bin/nix-env -p /nix/var/nix/profiles/per-user/root/channels \
40 -i ${channelSources} --quiet --option build-use-substitutes false
41 mkdir -m 0700 -p /root/.nix-defexpr
42 ln -s /nix/var/nix/profiles/per-user/root/channels /root/.nix-defexpr/channels
43 mkdir -m 0755 -p /var/lib/nixos
44 touch /var/lib/nixos/did-channel-init
45 fi
46 '';
47}