# Provide a mount point for nixos-install.
mkdir -p /mnt

# Provide a configuration for the CD/DVD itself, to allow users
# to run nixos-rebuild to change the configuration of the
# running system on the CD/DVD.
if ! [ -e /etc/nixos/configuration.nix ]; then
  cp /nix/store/m1k63vxrj7rq15465b43ixi0vdi6m21x-configuration.nix /etc/nixos/configuration.nix
fi


# After booting, register the contents of the Nix store in the Nix
# database.
if [ -f /nix-path-registration ]; then
  /nix/store/ml7n86msim8xn5nk0yvf83409b2qzr96-nix-2.4pre_xer_xeredo-11.10.2021/bin/nix-store --load-db < /nix-path-registration &&
  rm /nix-path-registration
fi

# nixos-rebuild also requires a "system" profile
/nix/store/ml7n86msim8xn5nk0yvf83409b2qzr96-nix-2.4pre_xer_xeredo-11.10.2021/bin/nix-env -p /nix/var/nix/profiles/system --set /run/current-system

if ! [ -e /var/lib/nixos/did-channel-init ]; then
  echo "unpacking the NixOS/Nixpkgs sources..."
  mkdir -p /nix/var/nix/profiles/per-user/root
  /nix/store/ml7n86msim8xn5nk0yvf83409b2qzr96-nix-2.4pre_xer_xeredo-11.10.2021/bin/nix-env -p /nix/var/nix/profiles/per-user/root/channels \
    -i /nix/store/mfng7yjzjlan3isd8acsnbnl83ram32h-nixos-22.05.19700101.dirty --quiet --option build-use-substitutes false
  mkdir -m 0700 -p /root/.nix-defexpr
  ln -s /nix/var/nix/profiles/per-user/root/channels /root/.nix-defexpr/channels
  mkdir -m 0755 -p /var/lib/nixos
  touch /var/lib/nixos/did-channel-init
fi


