mirror of
https://github.com/NixOS/nixpkgs.git
synced 2025-07-13 21:50:33 +03:00
nixos-install: add options --closure, --no-channel-copy, --no-root-passwd, and --no-bootloader
Closes #17236 nix-build -A tests.installer.simple '<nixos/release.nix>' succeeds ✓
This commit is contained in:
parent
4eef7a4ecf
commit
037d9c6cab
2 changed files with 56 additions and 10 deletions
|
@ -25,6 +25,19 @@
|
||||||
<arg choice='plain'><option>--root</option></arg>
|
<arg choice='plain'><option>--root</option></arg>
|
||||||
<replaceable>root</replaceable>
|
<replaceable>root</replaceable>
|
||||||
</arg>
|
</arg>
|
||||||
|
<arg>
|
||||||
|
<arg choice='plain'><option>--closure</option></arg>
|
||||||
|
<replaceable>closure</replaceable>
|
||||||
|
</arg>
|
||||||
|
<arg>
|
||||||
|
<arg choice='plain'><option>--no-channel-copy</option></arg>
|
||||||
|
</arg>
|
||||||
|
<arg>
|
||||||
|
<arg choice='plain'><option>--no-root-passwd</option></arg>
|
||||||
|
</arg>
|
||||||
|
<arg>
|
||||||
|
<arg choice='plain'><option>--no-bootloader</option></arg>
|
||||||
|
</arg>
|
||||||
<arg>
|
<arg>
|
||||||
<group choice='req'>
|
<group choice='req'>
|
||||||
<arg choice='plain'><option>--max-jobs</option></arg>
|
<arg choice='plain'><option>--max-jobs</option></arg>
|
||||||
|
@ -71,12 +84,13 @@ the following steps:
|
||||||
<filename>/mnt/etc/nixos/configuration.nix</filename>.</para></listitem>
|
<filename>/mnt/etc/nixos/configuration.nix</filename>.</para></listitem>
|
||||||
|
|
||||||
<listitem><para>It installs the GRUB boot loader on the device
|
<listitem><para>It installs the GRUB boot loader on the device
|
||||||
specified in the option <option>boot.loader.grub.device</option>,
|
specified in the option <option>boot.loader.grub.device</option>
|
||||||
|
(unless <option>--no-bootloader</option> is specified),
|
||||||
and generates a GRUB configuration file that boots into the NixOS
|
and generates a GRUB configuration file that boots into the NixOS
|
||||||
configuration just installed.</para></listitem>
|
configuration just installed.</para></listitem>
|
||||||
|
|
||||||
<listitem><para>It prompts you for a password for the root
|
<listitem><para>It prompts you for a password for the root account
|
||||||
account.</para></listitem>
|
(unless <option>--no-root-passwd</option> is specified).</para></listitem>
|
||||||
|
|
||||||
</itemizedlist>
|
</itemizedlist>
|
||||||
|
|
||||||
|
@ -103,6 +117,19 @@ it.</para>
|
||||||
</listitem>
|
</listitem>
|
||||||
</varlistentry>
|
</varlistentry>
|
||||||
|
|
||||||
|
<varlistentry>
|
||||||
|
<term><option>--closure</option></term>
|
||||||
|
<listitem>
|
||||||
|
<para>If this option is provided, <command>nixos-install</command> will install the specified closure
|
||||||
|
rather than attempt to build one from <filename>/mnt/etc/nixos/configuration.nix</filename>.</para>
|
||||||
|
|
||||||
|
<para>The closure must be an appropriately configured NixOS system, with boot loader and partition
|
||||||
|
configuration that fits the target host. Such a closure is typically obtained with a command such as
|
||||||
|
<command>nix-build -I nixos-config=./configuration.nix '<nixos>' -A system --no-out-link</command>
|
||||||
|
</para>
|
||||||
|
</listitem>
|
||||||
|
</varlistentry>
|
||||||
|
|
||||||
<varlistentry>
|
<varlistentry>
|
||||||
<term><option>-I</option></term>
|
<term><option>-I</option></term>
|
||||||
<listitem>
|
<listitem>
|
||||||
|
|
|
@ -24,6 +24,7 @@ fi
|
||||||
# Parse the command line for the -I flag
|
# Parse the command line for the -I flag
|
||||||
extraBuildFlags=()
|
extraBuildFlags=()
|
||||||
chrootCommand=(/run/current-system/sw/bin/bash)
|
chrootCommand=(/run/current-system/sw/bin/bash)
|
||||||
|
bootLoader=1
|
||||||
|
|
||||||
while [ "$#" -gt 0 ]; do
|
while [ "$#" -gt 0 ]; do
|
||||||
i="$1"; shift 1
|
i="$1"; shift 1
|
||||||
|
@ -40,6 +41,18 @@ while [ "$#" -gt 0 ]; do
|
||||||
--root)
|
--root)
|
||||||
mountPoint="$1"; shift 1
|
mountPoint="$1"; shift 1
|
||||||
;;
|
;;
|
||||||
|
--closure)
|
||||||
|
closure="$1"; shift 1
|
||||||
|
;;
|
||||||
|
--no-channel-copy)
|
||||||
|
noChannelCopy=1
|
||||||
|
;;
|
||||||
|
--no-root-passwd)
|
||||||
|
noRootPasswd=1
|
||||||
|
;;
|
||||||
|
--no-bootloader)
|
||||||
|
bootLoader=0
|
||||||
|
;;
|
||||||
--show-trace)
|
--show-trace)
|
||||||
extraBuildFlags+=("$i")
|
extraBuildFlags+=("$i")
|
||||||
;;
|
;;
|
||||||
|
@ -111,7 +124,7 @@ if test -z "$NIXOS_CONFIG"; then
|
||||||
NIXOS_CONFIG=/etc/nixos/configuration.nix
|
NIXOS_CONFIG=/etc/nixos/configuration.nix
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if ! test -e "$mountPoint/$NIXOS_CONFIG"; then
|
if [ ! -e "$mountPoint/$NIXOS_CONFIG" ] && [ -z "$closure" ]; then
|
||||||
echo "configuration file $mountPoint/$NIXOS_CONFIG doesn't exist"
|
echo "configuration file $mountPoint/$NIXOS_CONFIG doesn't exist"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
@ -200,16 +213,22 @@ for i in /nix/var/nix/manifests/*.nixmanifest; do
|
||||||
done
|
done
|
||||||
|
|
||||||
|
|
||||||
# Get the absolute path to the NixOS/Nixpkgs sources.
|
if [ -z "$closure" ]; then
|
||||||
nixpkgs="$(readlink -f $(nix-instantiate --find-file nixpkgs))"
|
# Get the absolute path to the NixOS/Nixpkgs sources.
|
||||||
|
nixpkgs="$(readlink -f $(nix-instantiate --find-file nixpkgs))"
|
||||||
|
|
||||||
|
nixEnvAction="-f <nixpkgs/nixos> --set -A system"
|
||||||
|
else
|
||||||
|
nixpkgs=""
|
||||||
|
nixEnvAction="--set $closure"
|
||||||
|
fi
|
||||||
|
|
||||||
# Build the specified Nix expression in the target store and install
|
# Build the specified Nix expression in the target store and install
|
||||||
# it into the system configuration profile.
|
# it into the system configuration profile.
|
||||||
echo "building the system configuration..."
|
echo "building the system configuration..."
|
||||||
NIX_PATH="nixpkgs=/tmp/root/$nixpkgs:nixos-config=$NIXOS_CONFIG" NIXOS_CONFIG= \
|
NIX_PATH="nixpkgs=/tmp/root/$nixpkgs:nixos-config=$NIXOS_CONFIG" NIXOS_CONFIG= \
|
||||||
chroot $mountPoint @nix@/bin/nix-env \
|
chroot $mountPoint @nix@/bin/nix-env \
|
||||||
"${extraBuildFlags[@]}" -p /nix/var/nix/profiles/system -f '<nixpkgs/nixos>' --set -A system
|
"${extraBuildFlags[@]}" -p /nix/var/nix/profiles/system $nixEnvAction
|
||||||
|
|
||||||
|
|
||||||
# Copy the NixOS/Nixpkgs sources to the target as the initial contents
|
# Copy the NixOS/Nixpkgs sources to the target as the initial contents
|
||||||
|
@ -218,7 +237,7 @@ mkdir -m 0755 -p $mountPoint/nix/var/nix/profiles
|
||||||
mkdir -m 1777 -p $mountPoint/nix/var/nix/profiles/per-user
|
mkdir -m 1777 -p $mountPoint/nix/var/nix/profiles/per-user
|
||||||
mkdir -m 0755 -p $mountPoint/nix/var/nix/profiles/per-user/root
|
mkdir -m 0755 -p $mountPoint/nix/var/nix/profiles/per-user/root
|
||||||
srcs=$(nix-env "${extraBuildFlags[@]}" -p /nix/var/nix/profiles/per-user/root/channels -q nixos --no-name --out-path 2>/dev/null || echo -n "")
|
srcs=$(nix-env "${extraBuildFlags[@]}" -p /nix/var/nix/profiles/per-user/root/channels -q nixos --no-name --out-path 2>/dev/null || echo -n "")
|
||||||
if test -n "$srcs"; then
|
if [ -z "$noChannelCopy" ] && [ -n "$srcs" ]; then
|
||||||
echo "copying NixOS/Nixpkgs sources..."
|
echo "copying NixOS/Nixpkgs sources..."
|
||||||
chroot $mountPoint @nix@/bin/nix-env \
|
chroot $mountPoint @nix@/bin/nix-env \
|
||||||
"${extraBuildFlags[@]}" -p /nix/var/nix/profiles/per-user/root/channels -i "$srcs" --quiet
|
"${extraBuildFlags[@]}" -p /nix/var/nix/profiles/per-user/root/channels -i "$srcs" --quiet
|
||||||
|
@ -244,7 +263,7 @@ touch $mountPoint/etc/NIXOS
|
||||||
# a menu default pointing at the kernel/initrd/etc of the new
|
# a menu default pointing at the kernel/initrd/etc of the new
|
||||||
# configuration.
|
# configuration.
|
||||||
echo "finalising the installation..."
|
echo "finalising the installation..."
|
||||||
NIXOS_INSTALL_GRUB=1 chroot $mountPoint \
|
NIXOS_INSTALL_GRUB="$bootLoader" chroot $mountPoint \
|
||||||
/nix/var/nix/profiles/system/bin/switch-to-configuration boot
|
/nix/var/nix/profiles/system/bin/switch-to-configuration boot
|
||||||
|
|
||||||
|
|
||||||
|
@ -253,7 +272,7 @@ chroot $mountPoint /nix/var/nix/profiles/system/activate
|
||||||
|
|
||||||
|
|
||||||
# Ask the user to set a root password.
|
# Ask the user to set a root password.
|
||||||
if [ "$(chroot $mountPoint /run/current-system/sw/bin/sh -l -c "nix-instantiate --eval '<nixpkgs/nixos>' -A config.users.mutableUsers")" = true ] && [ -t 0 ] ; then
|
if [ -z "$noRootPasswd" ] && [ "$(chroot $mountPoint /run/current-system/sw/bin/sh -l -c "nix-instantiate --eval '<nixpkgs/nixos>' -A config.users.mutableUsers")" = true ] && [ -t 0 ] ; then
|
||||||
echo "setting root password..."
|
echo "setting root password..."
|
||||||
chroot $mountPoint /var/setuid-wrappers/passwd
|
chroot $mountPoint /var/setuid-wrappers/passwd
|
||||||
fi
|
fi
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue