2006-11-08 02:34:14 +00:00
|
|
|
#! @shell@
|
|
|
|
|
2018-02-05 18:50:36 +00:00
|
|
|
set -e
|
|
|
|
shopt -s nullglob
|
|
|
|
|
|
|
|
export PATH=@path@:$PATH
|
2006-11-08 02:34:14 +00:00
|
|
|
|
2014-09-03 21:10:40 +00:00
|
|
|
# Ensure a consistent umask.
|
|
|
|
umask 0022
|
|
|
|
|
2013-09-29 14:38:57 +00:00
|
|
|
# Parse the command line for the -I flag
|
|
|
|
extraBuildFlags=()
|
2018-02-05 18:50:36 +00:00
|
|
|
|
|
|
|
mountPoint=/mnt
|
2013-09-29 14:38:57 +00:00
|
|
|
|
|
|
|
while [ "$#" -gt 0 ]; do
|
|
|
|
i="$1"; shift 1
|
|
|
|
case "$i" in
|
2015-03-11 16:44:31 +00:00
|
|
|
--max-jobs|-j|--cores|-I)
|
|
|
|
j="$1"; shift 1
|
|
|
|
extraBuildFlags+=("$i" "$j")
|
|
|
|
;;
|
|
|
|
--option)
|
|
|
|
j="$1"; shift 1
|
|
|
|
k="$1"; shift 1
|
|
|
|
extraBuildFlags+=("$i" "$j" "$k")
|
2013-10-11 12:12:36 +00:00
|
|
|
;;
|
2014-08-24 13:57:00 +00:00
|
|
|
--root)
|
|
|
|
mountPoint="$1"; shift 1
|
|
|
|
;;
|
2016-07-24 13:45:24 +00:00
|
|
|
--closure)
|
2018-02-05 18:50:36 +00:00
|
|
|
# FIXME: --closure is a misnomer
|
|
|
|
system="$1"; shift 1
|
2016-07-24 13:45:24 +00:00
|
|
|
;;
|
|
|
|
--no-channel-copy)
|
|
|
|
noChannelCopy=1
|
|
|
|
;;
|
|
|
|
--no-root-passwd)
|
|
|
|
noRootPasswd=1
|
|
|
|
;;
|
|
|
|
--no-bootloader)
|
2016-08-16 00:15:27 +00:00
|
|
|
noBootLoader=1
|
2016-07-24 13:45:24 +00:00
|
|
|
;;
|
2014-05-08 19:04:58 +00:00
|
|
|
--show-trace)
|
|
|
|
extraBuildFlags+=("$i")
|
|
|
|
;;
|
2013-10-11 12:12:36 +00:00
|
|
|
--help)
|
|
|
|
exec man nixos-install
|
|
|
|
exit 1
|
|
|
|
;;
|
2018-02-05 18:50:36 +00:00
|
|
|
--debug)
|
|
|
|
set -x
|
|
|
|
;;
|
2013-10-11 12:12:36 +00:00
|
|
|
*)
|
|
|
|
echo "$0: unknown option \`$i'"
|
|
|
|
exit 1
|
|
|
|
;;
|
2013-09-29 14:38:57 +00:00
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
2007-01-11 00:06:46 +00:00
|
|
|
if ! test -e "$mountPoint"; then
|
|
|
|
echo "mount point $mountPoint doesn't exist"
|
|
|
|
exit 1
|
|
|
|
fi
|
2007-02-05 15:52:55 +00:00
|
|
|
|
2014-05-08 22:25:05 +00:00
|
|
|
# Get the path of the NixOS configuration file.
|
2018-02-05 18:50:36 +00:00
|
|
|
if [[ -z $NIXOS_CONFIG ]]; then
|
|
|
|
NIXOS_CONFIG=$mountPoint/etc/nixos/configuration.nix
|
2014-05-08 22:25:05 +00:00
|
|
|
fi
|
|
|
|
|
2018-02-05 18:50:36 +00:00
|
|
|
if [[ ${NIXOS_CONFIG:0:1} != / ]]; then
|
|
|
|
echo "$0: \$NIXOS_CONFIG is not an absolute path"
|
2014-05-08 22:25:05 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2018-02-05 18:50:36 +00:00
|
|
|
if [ ! -e "$NIXOS_CONFIG" ] && [ -z "$closure" ]; then
|
|
|
|
echo "configuration file $NIXOS_CONFIG doesn't exist"
|
|
|
|
exit 1
|
2017-08-31 01:57:05 +00:00
|
|
|
fi
|
2006-11-11 17:59:08 +00:00
|
|
|
|
2018-02-05 18:50:36 +00:00
|
|
|
# A place to drop temporary stuff.
|
2017-02-20 19:57:16 +00:00
|
|
|
trap "rm -rf $tmpdir" EXIT
|
|
|
|
tmpdir="$(mktemp -d)"
|
2015-09-30 19:43:06 +00:00
|
|
|
|
2018-02-05 18:50:36 +00:00
|
|
|
subs="local?trusted=1 https://cache.nixos.org/"
|
2012-05-15 13:50:36 +00:00
|
|
|
|
2018-02-05 18:50:36 +00:00
|
|
|
# Build the system configuration in the target filesystem.
|
|
|
|
if [[ -z $system ]]; then
|
|
|
|
echo "building the configuration in $NIXOS_CONFIG..."
|
|
|
|
outLink="$tmpdir/system"
|
|
|
|
nix build --out-link "$outLink" --store "$mountPoint" "${extraBuildFlags[@]}" \
|
|
|
|
--substituters "$subs" \
|
|
|
|
-f '<nixpkgs/nixos>' system -I "nixos-config=$NIXOS_CONFIG"
|
|
|
|
system=$(readlink -f $outLink)
|
|
|
|
fi
|
2017-08-31 01:57:05 +00:00
|
|
|
|
2018-02-05 18:50:36 +00:00
|
|
|
# Set the system profile to point to the configuration. TODO: combine
|
|
|
|
# this with the previous step once we have a nix-env replacement with
|
|
|
|
# a progress bar.
|
|
|
|
nix-env --store "$mountPoint" "${extraBuildFlags[@]}" \
|
|
|
|
--substituters "$subs" \
|
|
|
|
-p $mountPoint/nix/var/nix/profiles/system --set "$system"
|
|
|
|
|
|
|
|
# Copy the NixOS/Nixpkgs sources to the target as the initial contents
|
|
|
|
# of the NixOS channel.
|
|
|
|
if [[ -z $noChannelCopy ]]; then
|
|
|
|
channelPath="$(nix-env -p /nix/var/nix/profiles/per-user/root/channels -q nixos --no-name --out-path 2>/dev/null || echo -n "")"
|
|
|
|
if [[ -n $channelPath ]]; then
|
|
|
|
echo "copying channel..."
|
|
|
|
mkdir -p $mountPoint/nix/var/nix/profiles/per-user/root
|
|
|
|
nix-env --store "$mountPoint" --substituters 'local?trusted=1' "${extraBuildFlags[@]}" \
|
|
|
|
-p $mountPoint/nix/var/nix/profiles/per-user/root/channels --set "$channelPath" --quiet
|
|
|
|
fi
|
|
|
|
fi
|
2012-05-15 13:50:36 +00:00
|
|
|
|
2018-02-05 18:50:36 +00:00
|
|
|
# Mark the target as a NixOS installation, otherwise switch-to-configuration will chicken out.
|
|
|
|
touch "$mountPoint/etc/NIXOS"
|
2008-05-09 10:08:02 +00:00
|
|
|
|
2006-11-12 23:30:03 +00:00
|
|
|
# Switch to the new system configuration. This will install Grub with
|
|
|
|
# a menu default pointing at the kernel/initrd/etc of the new
|
|
|
|
# configuration.
|
2018-02-05 18:50:36 +00:00
|
|
|
if [[ -z $noBootLoader ]]; then
|
|
|
|
echo "installing the boot loader..."
|
|
|
|
# Grub needs an mtab.
|
|
|
|
ln -sfn /proc/mounts $mountPoint/etc/mtab
|
|
|
|
NIXOS_INSTALL_BOOTLOADER=1 nixos-enter --root "$mountPoint" -- /run/current-system/bin/switch-to-configuration boot
|
2016-08-16 00:15:27 +00:00
|
|
|
fi
|
2014-05-08 22:04:48 +00:00
|
|
|
|
2018-02-05 18:50:36 +00:00
|
|
|
# Ask the user to set a root password, but only if the passwd command
|
|
|
|
# exists (i.e. when mutable user accounts are enabled).
|
|
|
|
if [[ -z $noRootPasswd ]] && [ -t 0 ]; then
|
|
|
|
nixos-enter --root "$mountPoint" -c '[[ -e /nix/var/nix/profiles/system/sw/bin/passwd ]] && echo "setting root password..." && /nix/var/nix/profiles/system/sw/bin/passwd'
|
2014-05-08 22:04:48 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
echo "installation finished!"
|