···2020<itemizedlist>
2121 <listitem>
2222 <para>
2323+ Nix now defaults to 2.0; see its
2424+ <link xlink:href="https://nixos.org/nix/manual/#ssec-relnotes-2.0">release notes</link>.
2525+ </para>
2626+ </listitem>
2727+2828+ <listitem>
2929+ <para>
2330 Linux kernel defaults to the 4.14 branch (it was 4.9).
2431 </para>
2532 </listitem>
+26-22
nixos/lib/make-disk-image.nix
···51515252let format' = format; in let
53535454- format = if (format' == "qcow2-compressed") then "qcow2" else format';
5454+ format = if format' == "qcow2-compressed" then "qcow2" else format';
55555656 compress = optionalString (format' == "qcow2-compressed") "-c";
5757···84848585 nixpkgs = cleanSource pkgs.path;
86868787+ # FIXME: merge with channel.nix / make-channel.nix.
8788 channelSources = pkgs.runCommand "nixos-${config.system.nixos.version}" {} ''
8889 mkdir -p $out
8990 cp -prd ${nixpkgs} $out/nixos
···9596 echo -n ${config.system.nixos.versionSuffix} > $out/nixos/.version-suffix
9697 '';
97989898- metaClosure = pkgs.writeText "meta" ''
9999- ${config.system.build.toplevel}
100100- ${config.nix.package.out}
101101- ${channelSources}
102102- '';
103103-104104- prepareImageInputs = with pkgs; [ rsync utillinux parted e2fsprogs lkl fakeroot config.system.build.nixos-prepare-root ] ++ stdenv.initialPath;
9999+ binPath = with pkgs; makeBinPath (
100100+ [ rsync
101101+ utillinux
102102+ parted
103103+ e2fsprogs
104104+ lkl
105105+ config.system.build.nixos-install
106106+ config.system.build.nixos-enter
107107+ nix
108108+ ] ++ stdenv.initialPath);
105109106110 # I'm preserving the line below because I'm going to search for it across nixpkgs to consolidate
107111 # image building logic. The comment right below this now appears in 4 different places in nixpkgs :)
···109113 sources = map (x: x.source) contents;
110114 targets = map (x: x.target) contents;
111115116116+ closureInfo = pkgs.closureInfo { rootPaths = [ config.system.build.toplevel channelSources ]; };
117117+112118 prepareImage = ''
113113- export PATH=${makeBinPath prepareImageInputs}
119119+ export PATH=${binPath}
114120115121 # Yes, mkfs.ext4 takes different units in different contexts. Fun.
116122 sectorsToKilobytes() {
···168174 fi
169175 done
170176171171- # TODO: Nix really likes to chown things it creates to its current user...
172172- fakeroot nixos-prepare-root $root ${channelSources} ${config.system.build.toplevel} closure
177177+ export HOME=$TMPDIR
173178174174- # fakeroot seems to always give the owner write permissions, which we do not want
175175- find $root/nix/store -mindepth 1 -maxdepth 1 -type f -o -type d | xargs chmod -R a-w
179179+ # Provide a Nix database so that nixos-install can copy closures.
180180+ export NIX_STATE_DIR=$TMPDIR/state
181181+ nix-store --load-db < ${closureInfo}/registration
182182+183183+ echo "running nixos-install..."
184184+ nixos-install --root $root --no-bootloader --no-root-passwd \
185185+ --system ${config.system.build.toplevel} --channel ${channelSources} --substituters ""
176186177187 echo "copying staging root to image..."
178188 cptofs -p ${optionalString (partitionTableType != "none") "-P ${rootPartition}"} -t ${fsType} -i $diskImage $root/* /
···181191 pkgs.runCommand name
182192 { preVM = prepareImage;
183193 buildInputs = with pkgs; [ utillinux e2fsprogs dosfstools ];
184184- exportReferencesGraph = [ "closure" metaClosure ];
185194 postVM = ''
186195 ${if format == "raw" then ''
187196 mv $diskImage $out/${filename}
···194203 memSize = 1024;
195204 }
196205 ''
206206+ export PATH=${binPath}:$PATH
207207+197208 rootDisk=${if partitionTableType != "none" then "/dev/vda${rootPartition}" else "/dev/vda"}
198209199210 # Some tools assume these exist
···218229 cp ${configFile} /mnt/etc/nixos/configuration.nix
219230 ''}
220231221221- mount --rbind /dev $mountPoint/dev
222222- mount --rbind /proc $mountPoint/proc
223223- mount --rbind /sys $mountPoint/sys
224224-225232 # Set up core system link, GRUB, etc.
226226- NIXOS_INSTALL_BOOTLOADER=1 chroot $mountPoint /nix/var/nix/profiles/system/bin/switch-to-configuration boot
227227-228228- # TODO: figure out if I should activate, but for now I won't
229229- # chroot $mountPoint /nix/var/nix/profiles/system/activate
233233+ NIXOS_INSTALL_BOOTLOADER=1 nixos-enter --root $mountPoint -- /nix/var/nix/profiles/system/bin/switch-to-configuration boot
230234231235 # The above scripts will generate a random machine-id and we don't want to bake a single ID into all our images
232236 rm -f $mountPoint/etc/machine-id
···727273737474# Add the closures of the top-level store objects.
7575-storePaths=$(perl $pathsFromGraph closure-*)
7676-for i in $storePaths; do
7575+for i in $(< $closureInfo/store-paths); do
7776 addPath "${i:1}" "$i"
7877done
797880798180# Also include a manifest of the closures in a format suitable for
8281# nix-store --load-db.
8383-if [ -n "$object" ]; then
8484- printRegistration=1 perl $pathsFromGraph closure-* > nix-path-registration
8282+if [[ ${#objects[*]} != 0 ]]; then
8383+ cp $closureInfo/registration nix-path-registration
8584 addPath "nix-path-registration" "nix-path-registration"
8685fi
8786
+5-37
nixos/lib/make-squashfs.nix
···11-{ stdenv, squashfsTools, perl, pathsFromGraph
11+{ stdenv, squashfsTools, closureInfo
2233, # The root directory of the squashfs filesystem is filled with the
44 # closures of the Nix store paths listed here.
···88stdenv.mkDerivation {
99 name = "squashfs.img";
10101111- nativeBuildInputs = [perl squashfsTools];
1212-1313- # For obtaining the closure of `storeContents'.
1414- exportReferencesGraph =
1515- map (x: [("closure-" + baseNameOf x) x]) storeContents;
1111+ nativeBuildInputs = [ squashfsTools ];
16121713 buildCommand =
1814 ''
1919- # Add the closures of the top-level store objects.
2020- storePaths=$(perl ${pathsFromGraph} closure-*)
2121-2222- # If a Hydra slave happens to have store paths with bad permissions/mtime,
2323- # abort now so that they don't end up in ISO images in the channel.
2424- # https://github.com/NixOS/nixpkgs/issues/32242
2525- hasBadPaths=""
2626- for path in $storePaths; do
2727- if [ -h "$path" ]; then
2828- continue
2929- fi
3030-3131- mtime=$(stat -c %Y "$path")
3232- mode=$(stat -c %a "$path")
3333-3434- if [ "$mtime" != 1 ]; then
3535- echo "Store path '$path' has an invalid mtime."
3636- hasBadPaths=1
3737- fi
3838- if [ "$mode" != 444 ] && [ "$mode" != 555 ]; then
3939- echo "Store path '$path' has invalid permissions ($mode)."
4040- hasBadPaths=1
4141- fi
4242- done
4343-4444- if [ -n "$hasBadPaths" ]; then
4545- echo "You have bad paths in your store, please fix them."
4646- exit 1
4747- fi
1515+ closureInfo=${closureInfo { rootPaths = storeContents; }}
48164917 # Also include a manifest of the closures in a format suitable
5018 # for nix-store --load-db.
5151- printRegistration=1 perl ${pathsFromGraph} closure-* > nix-path-registration
1919+ cp $closureInfo/registration nix-path-registration
52205321 # Generate the squashfs image.
5454- mksquashfs nix-path-registration $storePaths $out \
2222+ mksquashfs nix-path-registration $(cat $closureInfo/store-paths) $out \
5523 -keep-as-directory -all-root -b 1048576 -comp xz -Xdict-size 100%
5624 '';
5725}
···11+#! @shell@
22+33+set -e
44+55+# Re-exec ourselves in a private mount namespace so that our bind
66+# mounts get cleaned up automatically.
77+if [ -z "$NIXOS_ENTER_REEXEC" ]; then
88+ export NIXOS_ENTER_REEXEC=1
99+ if [ "$(id -u)" != 0 ]; then
1010+ extraFlags="-r"
1111+ fi
1212+ exec unshare --fork --mount --uts --mount-proc --pid $extraFlags -- "$0" "$@"
1313+else
1414+ mount --make-rprivate /
1515+fi
1616+1717+mountPoint=/mnt
1818+command=("bash" "--login")
1919+system=/nix/var/nix/profiles/system
2020+2121+while [ "$#" -gt 0 ]; do
2222+ i="$1"; shift 1
2323+ case "$i" in
2424+ --root)
2525+ mountPoint="$1"; shift 1
2626+ ;;
2727+ --system)
2828+ system="$1"; shift 1
2929+ ;;
3030+ --help)
3131+ exec man nixos-enter
3232+ exit 1
3333+ ;;
3434+ --command|-c)
3535+ command=("bash" "-c" "$1")
3636+ shift 1
3737+ ;;
3838+ --)
3939+ command=("$@")
4040+ break
4141+ ;;
4242+ *)
4343+ echo "$0: unknown option \`$i'"
4444+ exit 1
4545+ ;;
4646+ esac
4747+done
4848+4949+if [[ ! -e $mountPoint/etc/NIXOS ]]; then
5050+ echo "$0: '$mountPoint' is not a NixOS installation" >&2
5151+ exit 126
5252+fi
5353+5454+mkdir -m 0755 -p "$mountPoint/dev"
5555+mount --rbind /dev "$mountPoint/dev"
5656+5757+# Run the activation script. Set $LOCALE_ARCHIVE to supress some Perl locale warnings.
5858+LOCALE_ARCHIVE=$system/sw/lib/locale/locale-archive chroot "$mountPoint" "$system/activate" >&2 || true
5959+6060+exec chroot "$mountPoint" "${command[@]}"
+66-129
nixos/modules/installer/tools/nixos-install.sh
···11#! @shell@
2233-# - make Nix store etc.
44-# - copy closure of Nix to target device
55-# - register validity
66-# - with a chroot to the target device:
77-# * nix-env -p /nix/var/nix/profiles/system -i <nix-expr for the configuration>
88-# * install the boot loader
33+set -e
44+shopt -s nullglob
55+66+export PATH=@path@:$PATH
97108# Ensure a consistent umask.
119umask 0022
12101313-# Re-exec ourselves in a private mount namespace so that our bind
1414-# mounts get cleaned up automatically.
1515-if [ "$(id -u)" = 0 ]; then
1616- if [ -z "$NIXOS_INSTALL_REEXEC" ]; then
1717- export NIXOS_INSTALL_REEXEC=1
1818- exec unshare --mount --uts -- "$0" "$@"
1919- else
2020- mount --make-rprivate /
2121- fi
2222-fi
2323-2411# Parse the command line for the -I flag
2512extraBuildFlags=()
2626-chrootCommand=(/run/current-system/sw/bin/bash)
2727-buildUsersGroup="nixbld"
1313+1414+mountPoint=/mnt
1515+channelPath=
28162917while [ "$#" -gt 0 ]; do
3018 i="$1"; shift 1
3119 case "$i" in
3232- --max-jobs|-j|--cores|-I)
2020+ --max-jobs|-j|--cores|-I|--substituters)
3321 j="$1"; shift 1
3422 extraBuildFlags+=("$i" "$j")
3523 ;;
···4129 --root)
4230 mountPoint="$1"; shift 1
4331 ;;
4444- --closure)
4545- closure="$1"; shift 1
4646- buildUsersGroup=""
3232+ --system|--closure)
3333+ system="$1"; shift 1
3434+ ;;
3535+ --channel)
3636+ channelPath="$1"; shift 1
4737 ;;
4838 --no-channel-copy)
4939 noChannelCopy=1
···5747 --show-trace)
5848 extraBuildFlags+=("$i")
5949 ;;
6060- --chroot)
6161- runChroot=1
6262- if [[ "$@" != "" ]]; then
6363- chrootCommand=("$@")
6464- fi
6565- break
6666- ;;
6750 --help)
6851 exec man nixos-install
6952 exit 1
7053 ;;
5454+ --debug)
5555+ set -x
5656+ ;;
7157 *)
7258 echo "$0: unknown option \`$i'"
7359 exit 1
···7561 esac
7662done
77637878-set -e
7979-shopt -s nullglob
8080-8181-if test -z "$mountPoint"; then
8282- mountPoint=/mnt
8383-fi
8484-8564if ! test -e "$mountPoint"; then
8665 echo "mount point $mountPoint doesn't exist"
8766 exit 1
8867fi
89689069# Get the path of the NixOS configuration file.
9191-if test -z "$NIXOS_CONFIG"; then
9292- NIXOS_CONFIG=/etc/nixos/configuration.nix
7070+if [[ -z $NIXOS_CONFIG ]]; then
7171+ NIXOS_CONFIG=$mountPoint/etc/nixos/configuration.nix
9372fi
94739595-if [ ! -e "$mountPoint/$NIXOS_CONFIG" ] && [ -z "$closure" ]; then
9696- echo "configuration file $mountPoint/$NIXOS_CONFIG doesn't exist"
7474+if [[ ${NIXOS_CONFIG:0:1} != / ]]; then
7575+ echo "$0: \$NIXOS_CONFIG is not an absolute path"
9776 exit 1
9877fi
9978100100-101101-# Builds will use users that are members of this group
102102-extraBuildFlags+=(--option "build-users-group" "$buildUsersGroup")
103103-104104-# Inherit binary caches from the host
105105-# TODO: will this still work with Nix 1.12 now that it has no perl? Probably not...
106106-binary_caches="$(@perl@/bin/perl -I @nix@/lib/perl5/site_perl/*/* -e 'use Nix::Config; Nix::Config::readConfig; print $Nix::Config::config{"binary-caches"};')"
107107-extraBuildFlags+=(--option "binary-caches" "$binary_caches")
108108-109109-# We only need nixpkgs in the path if we don't already have a system closure to install
110110-if [[ -z "$closure" ]]; then
111111- nixpkgs="$(readlink -f "$(nix-instantiate --find-file nixpkgs)")"
112112- export NIX_PATH="nixpkgs=$nixpkgs:nixos-config=$mountPoint/$NIXOS_CONFIG"
7979+if [[ ! -e $NIXOS_CONFIG && -z $system ]]; then
8080+ echo "configuration file $NIXOS_CONFIG doesn't exist"
8181+ exit 1
11382fi
114114-unset NIXOS_CONFIG
11583116116-# These get created in nixos-prepare-root as well, but we want to make sure they're here in case we're
117117-# running with --chroot. TODO: --chroot should just be split into a separate tool.
118118-mkdir -m 0755 -p "$mountPoint/dev" "$mountPoint/proc" "$mountPoint/sys"
119119-120120-# Set up some bind mounts we'll want regardless of chroot or not
121121-mount --rbind /dev "$mountPoint/dev"
122122-mount --rbind /proc "$mountPoint/proc"
123123-mount --rbind /sys "$mountPoint/sys"
124124-125125-# If we asked for a chroot, that means we're not actually installing anything (yeah I was confused too)
126126-# and we just want to run a command in the context of a $mountPoint that we're assuming has already been
127127-# set up by a previous nixos-install invocation. In that case we set up some remaining bind mounts and
128128-# exec the requested command, skipping the rest of the installation procedure.
129129-if [ -n "$runChroot" ]; then
130130- mount -t tmpfs -o "mode=0755" none $mountPoint/run
131131- rm -rf $mountPoint/var/run
132132- ln -s /run $mountPoint/var/run
133133- for f in /etc/resolv.conf /etc/hosts; do rm -f $mountPoint/$f; [ -f "$f" ] && cp -Lf $f $mountPoint/etc/; done
134134- for f in /etc/passwd /etc/group; do touch $mountPoint/$f; [ -f "$f" ] && mount --rbind -o ro $f $mountPoint/$f; done
135135-136136- if ! [ -L $mountPoint/nix/var/nix/profiles/system ]; then
137137- echo "$0: installation not finished; cannot chroot into installation directory"
138138- exit 1
139139- fi
140140- ln -s /nix/var/nix/profiles/system $mountPoint/run/current-system
141141- exec chroot $mountPoint "${chrootCommand[@]}"
142142-fi
143143-144144-# A place to drop temporary closures
8484+# A place to drop temporary stuff.
14585trap "rm -rf $tmpdir" EXIT
14686tmpdir="$(mktemp -d)"
14787148148-# Build a closure (on the host; we then copy it into the guest)
149149-function closure() {
150150- nix-build "${extraBuildFlags[@]}" --no-out-link -E "with import <nixpkgs> {}; runCommand \"closure\" { exportReferencesGraph = [ \"x\" (buildEnv { name = \"env\"; paths = [ ($1) stdenv ]; }) ]; } \"cp x \$out\""
151151-}
8888+sub="auto?trusted=1"
15289153153-system_closure="$tmpdir/system.closure"
154154-# Use a FIFO for piping nix-store --export into nix-store --import, saving disk
155155-# I/O and space. nix-store --import is run by nixos-prepare-root.
156156-mkfifo $system_closure
157157-158158-if [ -z "$closure" ]; then
159159- expr="(import <nixpkgs/nixos> {}).system"
160160- system_root="$(nix-build -E "$expr")"
161161- system_closure="$(closure "$expr")"
162162-else
163163- system_root=$closure
164164- # Create a temporary file ending in .closure (so nixos-prepare-root knows to --import it) to transport the store closure
165165- # to the filesytem we're preparing. Also delete it on exit!
166166- # Run in background to avoid blocking while trying to write to the FIFO
167167- # $system_closure refers to
168168- nix-store --export $(nix-store -qR $closure) > $system_closure &
9090+# Build the system configuration in the target filesystem.
9191+if [[ -z $system ]]; then
9292+ echo "building the configuration in $NIXOS_CONFIG..."
9393+ outLink="$tmpdir/system"
9494+ nix build --out-link "$outLink" --store "$mountPoint" "${extraBuildFlags[@]}" \
9595+ --extra-substituters "$sub" \
9696+ -f '<nixpkgs/nixos>' system -I "nixos-config=$NIXOS_CONFIG"
9797+ system=$(readlink -f $outLink)
16998fi
17099171171-channel_root="$(nix-env -p /nix/var/nix/profiles/per-user/root/channels -q nixos --no-name --out-path 2>/dev/null || echo -n "")"
172172-channel_closure="$tmpdir/channel.closure"
173173-nix-store --export $channel_root > $channel_closure
100100+# Set the system profile to point to the configuration. TODO: combine
101101+# this with the previous step once we have a nix-env replacement with
102102+# a progress bar.
103103+nix-env --store "$mountPoint" "${extraBuildFlags[@]}" \
104104+ --extra-substituters "$sub" \
105105+ -p $mountPoint/nix/var/nix/profiles/system --set "$system"
174106175175-# Populate the target root directory with the basics
176176-@prepare_root@/bin/nixos-prepare-root "$mountPoint" "$channel_root" "$system_root" @nixClosure@ "$system_closure" "$channel_closure"
177177-178178-# nixos-prepare-root doesn't currently do anything with file ownership, so we set it up here instead
179179-chown @root_uid@:@nixbld_gid@ $mountPoint/nix/store
180180-181181-107107+# Copy the NixOS/Nixpkgs sources to the target as the initial contents
108108+# of the NixOS channel.
109109+if [[ -z $noChannelCopy ]]; then
110110+ if [[ -z $channelPath ]]; then
111111+ channelPath="$(nix-env -p /nix/var/nix/profiles/per-user/root/channels -q nixos --no-name --out-path 2>/dev/null || echo -n "")"
112112+ fi
113113+ if [[ -n $channelPath ]]; then
114114+ echo "copying channel..."
115115+ mkdir -p $mountPoint/nix/var/nix/profiles/per-user/root
116116+ nix-env --store "$mountPoint" "${extraBuildFlags[@]}" --extra-substituters "$sub" \
117117+ -p $mountPoint/nix/var/nix/profiles/per-user/root/channels --set "$channelPath" --quiet
118118+ install -m 0700 -d $mountPoint/root/.nix-defexpr
119119+ ln -sfn /nix/var/nix/profiles/per-user/root/channels $mountPoint/root/.nix-defexpr/channels
120120+ fi
121121+fi
182122183183-# Grub needs an mtab.
184184-ln -sfn /proc/mounts $mountPoint/etc/mtab
123123+# Mark the target as a NixOS installation, otherwise switch-to-configuration will chicken out.
124124+mkdir -m 0755 -p "$mountPoint/etc"
125125+touch "$mountPoint/etc/NIXOS"
185126186127# Switch to the new system configuration. This will install Grub with
187128# a menu default pointing at the kernel/initrd/etc of the new
188129# configuration.
189189-echo "finalising the installation..."
190190-if [ -z "$noBootLoader" ]; then
191191- NIXOS_INSTALL_BOOTLOADER=1 chroot $mountPoint \
192192- /nix/var/nix/profiles/system/bin/switch-to-configuration boot
130130+if [[ -z $noBootLoader ]]; then
131131+ echo "installing the boot loader..."
132132+ # Grub needs an mtab.
133133+ ln -sfn /proc/mounts $mountPoint/etc/mtab
134134+ NIXOS_INSTALL_BOOTLOADER=1 nixos-enter --root "$mountPoint" -- /run/current-system/bin/switch-to-configuration boot
193135fi
194136195195-# Run the activation script.
196196-chroot $mountPoint /nix/var/nix/profiles/system/activate
197197-198198-199199-# Ask the user to set a root password.
200200-if [ -z "$noRootPasswd" ] && chroot $mountPoint [ -x /run/wrappers/bin/passwd ] && [ -t 0 ]; then
201201- echo "setting root password..."
202202- chroot $mountPoint /run/wrappers/bin/passwd
137137+# Ask the user to set a root password, but only if the passwd command
138138+# exists (i.e. when mutable user accounts are enabled).
139139+if [[ -z $noRootPasswd ]] && [ -t 0 ]; then
140140+ 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'
203141fi
204204-205142206143echo "installation finished!"
···11-#! @shell@
22-33-# This script's goal is to perform all "static" setup of a filesystem structure from pre-built store paths. Everything
44-# in here should run in a non-root context and inside a Nix builder. It's designed primarily to be called from image-
55-# building scripts and from nixos-install, but because it makes very few assumptions about the context in which it runs,
66-# it could be useful in other contexts as well.
77-#
88-# Current behavior:
99-# - set up basic filesystem structure
1010-# - make Nix store etc.
1111-# - copy Nix, system, channel, and misceallaneous closures to target Nix store
1212-# - register validity of all paths in the target store
1313-# - set up channel and system profiles
1414-1515-# Ensure a consistent umask.
1616-umask 0022
1717-1818-set -e
1919-2020-mountPoint="$1"
2121-channel="$2"
2222-system="$3"
2323-shift 3
2424-closures="$@"
2525-2626-PATH="@coreutils@/bin:@nix@/bin:@perl@/bin:@utillinux@/bin:@rsync@/bin"
2727-2828-if ! test -e "$mountPoint"; then
2929- echo "mount point $mountPoint doesn't exist"
3030- exit 1
3131-fi
3232-3333-# Create a few of the standard directories in the target root directory.
3434-install -m 0755 -d $mountPoint/dev $mountPoint/proc $mountPoint/sys $mountPoint/etc $mountPoint/run $mountPoint/home
3535-install -m 01777 -d $mountPoint/tmp
3636-install -m 0755 -d $mountPoint/tmp/root
3737-install -m 0755 -d $mountPoint/var
3838-install -m 0700 -d $mountPoint/root
3939-4040-ln -sf /run $mountPoint/var/run
4141-4242-# Create the necessary Nix directories on the target device
4343-install -m 0755 -d \
4444- $mountPoint/nix/var/nix/gcroots \
4545- $mountPoint/nix/var/nix/temproots \
4646- $mountPoint/nix/var/nix/userpool \
4747- $mountPoint/nix/var/nix/profiles \
4848- $mountPoint/nix/var/nix/db \
4949- $mountPoint/nix/var/log/nix/drvs
5050-5151-install -m 1775 -d $mountPoint/nix/store
5252-5353-# All Nix operations below should operate on our target store, not /nix/store.
5454-# N.B: this relies on Nix 1.12 or higher
5555-export NIX_REMOTE=local?root=$mountPoint
5656-5757-# Copy our closures to the Nix store on the target mount point, unless they're already there.
5858-for i in $closures; do
5959- # We support closures both in the format produced by `nix-store --export` and by `exportReferencesGraph`,
6060- # mostly because there doesn't seem to be a single format that can be produced outside of a nix build and
6161- # inside one. See https://github.com/NixOS/nix/issues/1242 for more discussion.
6262- if [[ "$i" =~ \.closure$ ]]; then
6363- echo "importing serialized closure $i to $mountPoint..."
6464- nix-store --import < $i
6565- else
6666- # There has to be a better way to do this, right?
6767- echo "copying closure $i to $mountPoint..."
6868- for j in $(perl @pathsFromGraph@ $i); do
6969- echo " $j... "
7070- rsync -a $j $mountPoint/nix/store/
7171- done
7272-7373- nix-store --option build-users-group root --register-validity < $i
7474- fi
7575-done
7676-7777-# Create the required /bin/sh symlink; otherwise lots of things
7878-# (notably the system() function) won't work.
7979-if [ ! -x $mountPoint/@shell@ ]; then
8080- echo "Error: @shell@ wasn't included in the closure" >&2
8181- exit 1
8282-fi
8383-install -m 0755 -d $mountPoint/bin
8484-ln -sf @shell@ $mountPoint/bin/sh
8585-8686-echo "setting the system closure to '$system'..."
8787-nix-env "${extraBuildFlags[@]}" -p $mountPoint/nix/var/nix/profiles/system --set "$system"
8888-8989-ln -sfn /nix/var/nix/profiles/system $mountPoint/run/current-system
9090-9191-# Copy the NixOS/Nixpkgs sources to the target as the initial contents of the NixOS channel.
9292-install -m 0755 -d $mountPoint/nix/var/nix/profiles
9393-install -m 1777 -d $mountPoint/nix/var/nix/profiles/per-user
9494-install -m 0755 -d $mountPoint/nix/var/nix/profiles/per-user/root
9595-9696-if [ -z "$noChannelCopy" ] && [ -n "$channel" ]; then
9797- echo "copying channel..."
9898- nix-env --option build-use-substitutes false "${extraBuildFlags[@]}" -p $mountPoint/nix/var/nix/profiles/per-user/root/channels --set "$channel" --quiet
9999-fi
100100-install -m 0700 -d $mountPoint/root/.nix-defexpr
101101-ln -sfn /nix/var/nix/profiles/per-user/root/channels $mountPoint/root/.nix-defexpr/channels
102102-103103-# Mark the target as a NixOS installation, otherwise switch-to-configuration will chicken out.
104104-touch $mountPoint/etc/NIXOS
···72727373 # To speed up installation a little bit, include the complete
7474 # stdenv in the Nix store on the CD.
7575- system.extraDependencies = with pkgs; [ stdenv stdenvNoCC busybox ];
7575+ system.extraDependencies = with pkgs;
7676+ [
7777+ stdenv
7878+ stdenvNoCC # for runCommand
7979+ busybox
8080+ jq # for closureInfo
8181+ ];
76827783 # Show all debug messages from the kernel but don't log refused packets
7884 # because we have the firewall enabled. This makes installs from the
+2-2
nixos/modules/services/misc/nix-daemon.nix
···3333 sh = pkgs.stdenv.shell;
3434 binshDeps = pkgs.writeReferencesToFile sh;
3535 in
3636- pkgs.runCommand "nix.conf" { extraOptions = cfg.extraOptions; inherit binshDeps; } ''
3636+ pkgs.runCommand "nix.conf" { extraOptions = cfg.extraOptions; } ''
3737 ${optionalString (!isNix20) ''
3838- extraPaths=$(for i in $(cat binshDeps); do if test -d $i; then echo $i; fi; done)
3838+ extraPaths=$(for i in $(cat ${binshDeps}); do if test -d $i; then echo $i; fi; done)
3939 ''}
4040 cat > $out <<END
4141 # WARNING: this file is generated from the nix.* options in
···54545555 environment.systemPackages = [ pkgs.kmod ];
56565757- system.activationScripts.modprobe =
5757+ system.activationScripts.modprobe = stringAfter ["specialfs"]
5858 ''
5959 # Allow the kernel to find our wrapped modprobe (which searches
6060 # in the right location in the Nix store for kernel modules).
···145145 # Check that the daemon works, and that non-root users can run builds (this will build a new profile generation through the daemon)
146146 $machine->succeed("su alice -l -c 'nix-env -iA nixos.procps' >&2");
147147148148- # We need to a writable nix-store on next boot.
148148+ # We need a writable Nix store on next boot.
149149 $machine->copyFileFromHost(
150150 "${ makeConfig { inherit bootLoader grubVersion grubDevice grubIdentifier grubUseEfi extraConfig; forceGrubReinstallCount = 1; } }",
151151 "/etc/nixos/configuration.nix");
···195195 };
196196 nodes = {
197197198198- # The configuration of the machine used to run "nixos-install". It
199199- # also has a web server that simulates cache.nixos.org.
198198+ # The configuration of the machine used to run "nixos-install".
200199 machine =
201200 { config, lib, pkgs, ... }:
202201···208207209208 virtualisation.diskSize = 8 * 1024;
210209 virtualisation.memorySize = 1024;
211211- virtualisation.writableStore = true;
212210213211 # Use a small /dev/vdb as the root disk for the
214212 # installer. This ensures the target disk (/dev/vda) is
···245243 ++ optionals (bootLoader == "grub" && grubVersion == 2) [ pkgs.grub2 pkgs.grub2_efi ];
246244247245 nix.binaryCaches = mkForce [ ];
246246+ nix.extraOptions =
247247+ ''
248248+ hashed-mirrors =
249249+ connect-timeout = 1
250250+ '';
248251 };
249252250253 };
+10-1
nixos/tests/misc.nix
···11# Miscellaneous small tests that don't warrant their own VM run.
2233-import ./make-test.nix ({ pkgs, ...} : {
33+import ./make-test.nix ({ pkgs, ...} : rec {
44 name = "misc";
55 meta = with pkgs.stdenv.lib.maintainers; {
66 maintainers = [ eelco chaoflow ];
77 };
88+99+ foo = pkgs.writeText "foo" "Hello World";
810911 machine =
1012 { config, lib, pkgs, ... }:
···2729 security.sudo = { enable = true; wheelNeedsPassword = false; };
2830 boot.kernel.sysctl."vm.swappiness" = 1;
2931 boot.kernelParams = [ "vsyscall=emulate" ];
3232+ system.extraDependencies = [ foo ];
3033 };
31343235 testScript =
3336 ''
3737+ subtest "nix-db", sub {
3838+ my $json = $machine->succeed("nix path-info --json ${foo}");
3939+ $json =~ /"narHash":"sha256:0afw0d9j1hvwiz066z93jiddc33nxg6i6qyp26vnqyglpyfivlq5"/ or die "narHash not set";
4040+ $json =~ /"narSize":128/ or die "narSize not set";
4141+ };
4242+3443 subtest "nixos-version", sub {
3544 $machine->succeed("[ `nixos-version | wc -w` = 2 ]");
3645 };
···2525done
262627272828-# Get the paths in the closure of `object'.
2929-storePaths=$(perl $pathsFromGraph closure-*)
3030-3131-3228# Paths in cpio archives *must* be relative, otherwise the kernel
3329# won't unpack 'em.
3434-(cd root && cp -prd --parents $storePaths .)
3030+(cd root && cp -prd --parents $(cat $closure/store-paths) .)
353136323733# Put the closure in a gzipped cpio archive.
+2
pkgs/build-support/kernel/paths-from-graph.pl
···11+# NOTE: this script is deprecated. Use closureInfo instead.
22+13# Parses a /nix/store/*-closure file and prints
24# various information.
35# By default, the nodes in the graph are printed to stdout.