# 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/a4ldzxivd6cxcn6qvh72acq18fsrxj48-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/bmc5jqkv17g4m6r73y6p8998wwj69cvl-nix-2.31.2/bin/nix-store --load-db < /nix-path-registration &&
  rm /nix-path-registration
fi

# nixos-rebuild also requires a "system" profile
/nix/store/bmc5jqkv17g4m6r73y6p8998wwj69cvl-nix-2.31.2/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/bmc5jqkv17g4m6r73y6p8998wwj69cvl-nix-2.31.2/bin/nix-env -p /nix/var/nix/profiles/per-user/root/channels \
    -i /nix/store/q4kn99bk64ki773530qnd8af8pc0i4k9-nixos-25.11.8107.1073dad219cb --quiet --option build-use-substitutes false \
     # There's an issue with pivot_root
  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


