lol

Merge branch 'nix-2.0'

+393 -417
+4 -2
nixos/doc/manual/development/testing-installer.xml
··· 11 11 properly: 12 12 13 13 <screen> 14 - $ nix-build -A config.system.build.nixos-install 15 14 # mount -t tmpfs none /mnt 15 + # nixos-generate-config --root /mnt 16 + $ nix-build '&lt;nixpkgs/nixos>' -A config.system.build.nixos-install 16 17 # ./result/bin/nixos-install</screen> 17 18 18 19 To start a login shell in the new NixOS installation in 19 20 <filename>/mnt</filename>: 20 21 21 22 <screen> 22 - # ./result/bin/nixos-install --chroot 23 + $ nix-build '&lt;nixpkgs/nixos>' -A config.system.build.nixos-enter 24 + # ./result/bin/nixos-enter 23 25 </screen> 24 26 25 27 </para>
+119
nixos/doc/manual/man-nixos-enter.xml
··· 1 + <refentry xmlns="http://docbook.org/ns/docbook" 2 + xmlns:xlink="http://www.w3.org/1999/xlink" 3 + xmlns:xi="http://www.w3.org/2001/XInclude"> 4 + 5 + <refmeta> 6 + <refentrytitle><command>nixos-enter</command></refentrytitle> 7 + <manvolnum>8</manvolnum> 8 + <refmiscinfo class="source">NixOS</refmiscinfo> 9 + <!-- <refmiscinfo class="version"><xi:include href="version.txt" parse="text"/></refmiscinfo> --> 10 + </refmeta> 11 + 12 + <refnamediv> 13 + <refname><command>nixos-enter</command></refname> 14 + <refpurpose>run a command in a NixOS chroot environment</refpurpose> 15 + </refnamediv> 16 + 17 + <refsynopsisdiv> 18 + <cmdsynopsis> 19 + <command>nixos-enter</command> 20 + <arg> 21 + <arg choice='plain'><option>--root</option></arg> 22 + <replaceable>root</replaceable> 23 + </arg> 24 + <arg> 25 + <arg choice='plain'><option>--system</option></arg> 26 + <replaceable>system</replaceable> 27 + </arg> 28 + <arg> 29 + <arg choice='plain'><option>-c</option></arg> 30 + <replaceable>shell-command</replaceable> 31 + </arg> 32 + <arg> 33 + <arg choice='plain'><option>--help</option></arg> 34 + </arg> 35 + <arg> 36 + <arg choice='plain'><option>--</option></arg> 37 + <replaceable>arguments</replaceable> 38 + </arg> 39 + </cmdsynopsis> 40 + </refsynopsisdiv> 41 + 42 + 43 + <refsection><title>Description</title> 44 + 45 + <para>This command runs a command in a NixOS chroot environment, that 46 + is, in a filesystem hierarchy previously prepared using 47 + <command>nixos-install</command>.</para> 48 + 49 + </refsection> 50 + 51 + <refsection><title>Options</title> 52 + 53 + <para>This command accepts the following options:</para> 54 + 55 + <variablelist> 56 + 57 + <varlistentry> 58 + <term><option>--root</option></term> 59 + <listitem> 60 + <para>The path to the NixOS system you want to enter. It defaults to <filename>/mnt</filename>.</para> 61 + </listitem> 62 + </varlistentry> 63 + 64 + <varlistentry> 65 + <term><option>--system</option></term> 66 + <listitem> 67 + <para>The NixOS system configuration to use. It defaults to 68 + <filename>/nix/var/nix/profiles/system</filename>. You can enter 69 + a previous NixOS configuration by specifying a path such as 70 + <filename>/nix/var/nix/profiles/system-106-link</filename>.</para> 71 + </listitem> 72 + </varlistentry> 73 + 74 + <varlistentry> 75 + <term><option>--command</option></term> 76 + <term><option>-c</option></term> 77 + <listitem> 78 + <para>The bash command to execute.</para> 79 + </listitem> 80 + </varlistentry> 81 + 82 + <varlistentry> 83 + <term><option>--</option></term> 84 + 85 + <listitem><para>Interpret the remaining arguments as the program 86 + name and arguments to be invoked. The program is not executed in a 87 + shell.</para></listitem> 88 + 89 + </varlistentry> 90 + 91 + </variablelist> 92 + 93 + </refsection> 94 + 95 + 96 + <refsection><title>Examples</title> 97 + 98 + <para>Start an interactive shell in the NixOS installation in 99 + <filename>/mnt</filename>:</para> 100 + 101 + <screen> 102 + # nixos-enter /mnt 103 + </screen> 104 + 105 + <para>Run a shell command:</para> 106 + 107 + <screen> 108 + # nixos-enter -c 'ls -l /; cat /proc/mounts' 109 + </screen> 110 + 111 + <para>Run a non-shell command:</para> 112 + 113 + <screen> 114 + # nixos-enter -- cat /proc/mounts 115 + </screen> 116 + 117 + </refsection> 118 + 119 + </refentry>
+3 -3
nixos/doc/manual/man-nixos-install.xml
··· 26 26 <replaceable>root</replaceable> 27 27 </arg> 28 28 <arg> 29 - <arg choice='plain'><option>--closure</option></arg> 30 - <replaceable>closure</replaceable> 29 + <arg choice='plain'><option>--system</option></arg> 30 + <replaceable>path</replaceable> 31 31 </arg> 32 32 <arg> 33 33 <arg choice='plain'><option>--no-channel-copy</option></arg> ··· 118 118 </varlistentry> 119 119 120 120 <varlistentry> 121 - <term><option>--closure</option></term> 121 + <term><option>--system</option></term> 122 122 <listitem> 123 123 <para>If this option is provided, <command>nixos-install</command> will install the specified closure 124 124 rather than attempt to build one from <filename>/mnt/etc/nixos/configuration.nix</filename>.</para>
+2 -1
nixos/doc/manual/man-pages.xml
··· 15 15 </author> 16 16 17 17 <copyright> 18 - <year>2007-2015</year> 18 + <year>2007-2018</year> 19 19 <holder>Eelco Dolstra</holder> 20 20 </copyright> 21 21 ··· 25 25 <xi:include href="man-nixos-build-vms.xml" /> 26 26 <xi:include href="man-nixos-generate-config.xml" /> 27 27 <xi:include href="man-nixos-install.xml" /> 28 + <xi:include href="man-nixos-enter.xml" /> 28 29 <xi:include href="man-nixos-option.xml" /> 29 30 <xi:include href="man-nixos-rebuild.xml" /> 30 31 <xi:include href="man-nixos-version.xml" />
+7
nixos/doc/manual/release-notes/rl-1803.xml
··· 20 20 <itemizedlist> 21 21 <listitem> 22 22 <para> 23 + Nix now defaults to 2.0; see its 24 + <link xlink:href="https://nixos.org/nix/manual/#ssec-relnotes-2.0">release notes</link>. 25 + </para> 26 + </listitem> 27 + 28 + <listitem> 29 + <para> 23 30 Linux kernel defaults to the 4.14 branch (it was 4.9). 24 31 </para> 25 32 </listitem>
+26 -22
nixos/lib/make-disk-image.nix
··· 51 51 52 52 let format' = format; in let 53 53 54 - format = if (format' == "qcow2-compressed") then "qcow2" else format'; 54 + format = if format' == "qcow2-compressed" then "qcow2" else format'; 55 55 56 56 compress = optionalString (format' == "qcow2-compressed") "-c"; 57 57 ··· 84 84 85 85 nixpkgs = cleanSource pkgs.path; 86 86 87 + # FIXME: merge with channel.nix / make-channel.nix. 87 88 channelSources = pkgs.runCommand "nixos-${config.system.nixos.version}" {} '' 88 89 mkdir -p $out 89 90 cp -prd ${nixpkgs} $out/nixos ··· 95 96 echo -n ${config.system.nixos.versionSuffix} > $out/nixos/.version-suffix 96 97 ''; 97 98 98 - metaClosure = pkgs.writeText "meta" '' 99 - ${config.system.build.toplevel} 100 - ${config.nix.package.out} 101 - ${channelSources} 102 - ''; 103 - 104 - prepareImageInputs = with pkgs; [ rsync utillinux parted e2fsprogs lkl fakeroot config.system.build.nixos-prepare-root ] ++ stdenv.initialPath; 99 + binPath = with pkgs; makeBinPath ( 100 + [ rsync 101 + utillinux 102 + parted 103 + e2fsprogs 104 + lkl 105 + config.system.build.nixos-install 106 + config.system.build.nixos-enter 107 + nix 108 + ] ++ stdenv.initialPath); 105 109 106 110 # I'm preserving the line below because I'm going to search for it across nixpkgs to consolidate 107 111 # image building logic. The comment right below this now appears in 4 different places in nixpkgs :) ··· 109 113 sources = map (x: x.source) contents; 110 114 targets = map (x: x.target) contents; 111 115 116 + closureInfo = pkgs.closureInfo { rootPaths = [ config.system.build.toplevel channelSources ]; }; 117 + 112 118 prepareImage = '' 113 - export PATH=${makeBinPath prepareImageInputs} 119 + export PATH=${binPath} 114 120 115 121 # Yes, mkfs.ext4 takes different units in different contexts. Fun. 116 122 sectorsToKilobytes() { ··· 168 174 fi 169 175 done 170 176 171 - # TODO: Nix really likes to chown things it creates to its current user... 172 - fakeroot nixos-prepare-root $root ${channelSources} ${config.system.build.toplevel} closure 177 + export HOME=$TMPDIR 173 178 174 - # fakeroot seems to always give the owner write permissions, which we do not want 175 - find $root/nix/store -mindepth 1 -maxdepth 1 -type f -o -type d | xargs chmod -R a-w 179 + # Provide a Nix database so that nixos-install can copy closures. 180 + export NIX_STATE_DIR=$TMPDIR/state 181 + nix-store --load-db < ${closureInfo}/registration 182 + 183 + echo "running nixos-install..." 184 + nixos-install --root $root --no-bootloader --no-root-passwd \ 185 + --system ${config.system.build.toplevel} --channel ${channelSources} --substituters "" 176 186 177 187 echo "copying staging root to image..." 178 188 cptofs -p ${optionalString (partitionTableType != "none") "-P ${rootPartition}"} -t ${fsType} -i $diskImage $root/* / ··· 181 191 pkgs.runCommand name 182 192 { preVM = prepareImage; 183 193 buildInputs = with pkgs; [ utillinux e2fsprogs dosfstools ]; 184 - exportReferencesGraph = [ "closure" metaClosure ]; 185 194 postVM = '' 186 195 ${if format == "raw" then '' 187 196 mv $diskImage $out/${filename} ··· 194 203 memSize = 1024; 195 204 } 196 205 '' 206 + export PATH=${binPath}:$PATH 207 + 197 208 rootDisk=${if partitionTableType != "none" then "/dev/vda${rootPartition}" else "/dev/vda"} 198 209 199 210 # Some tools assume these exist ··· 218 229 cp ${configFile} /mnt/etc/nixos/configuration.nix 219 230 ''} 220 231 221 - mount --rbind /dev $mountPoint/dev 222 - mount --rbind /proc $mountPoint/proc 223 - mount --rbind /sys $mountPoint/sys 224 - 225 232 # Set up core system link, GRUB, etc. 226 - NIXOS_INSTALL_BOOTLOADER=1 chroot $mountPoint /nix/var/nix/profiles/system/bin/switch-to-configuration boot 227 - 228 - # TODO: figure out if I should activate, but for now I won't 229 - # chroot $mountPoint /nix/var/nix/profiles/system/activate 233 + NIXOS_INSTALL_BOOTLOADER=1 nixos-enter --root $mountPoint -- /nix/var/nix/profiles/system/bin/switch-to-configuration boot 230 234 231 235 # The above scripts will generate a random machine-id and we don't want to bake a single ID into all our images 232 236 rm -f $mountPoint/etc/machine-id
+4 -5
nixos/lib/make-iso9660-image.nix
··· 1 - { stdenv, perl, pathsFromGraph, xorriso, syslinux 1 + { stdenv, perl, closureInfo, xorriso, syslinux 2 2 3 3 , # The file name of the resulting ISO image. 4 4 isoName ? "cd.iso" ··· 48 48 stdenv.mkDerivation { 49 49 name = isoName; 50 50 builder = ./make-iso9660-image.sh; 51 - buildInputs = [perl xorriso syslinux]; 51 + buildInputs = [ xorriso syslinux ]; 52 52 53 - inherit isoName bootable bootImage compressImage volumeID pathsFromGraph efiBootImage efiBootable isohybridMbrImage usbBootable; 53 + inherit isoName bootable bootImage compressImage volumeID efiBootImage efiBootable isohybridMbrImage usbBootable; 54 54 55 55 # !!! should use XML. 56 56 sources = map (x: x.source) contents; ··· 61 61 symlinks = map (x: x.symlink) storeContents; 62 62 63 63 # For obtaining the closure of `storeContents'. 64 - exportReferencesGraph = 65 - map (x: [("closure-" + baseNameOf x.object) x.object]) storeContents; 64 + closureInfo = closureInfo { rootPaths = map (x: x.object) storeContents; }; 66 65 }
+3 -4
nixos/lib/make-iso9660-image.sh
··· 72 72 73 73 74 74 # Add the closures of the top-level store objects. 75 - storePaths=$(perl $pathsFromGraph closure-*) 76 - for i in $storePaths; do 75 + for i in $(< $closureInfo/store-paths); do 77 76 addPath "${i:1}" "$i" 78 77 done 79 78 80 79 81 80 # Also include a manifest of the closures in a format suitable for 82 81 # nix-store --load-db. 83 - if [ -n "$object" ]; then 84 - printRegistration=1 perl $pathsFromGraph closure-* > nix-path-registration 82 + if [[ ${#objects[*]} != 0 ]]; then 83 + cp $closureInfo/registration nix-path-registration 85 84 addPath "nix-path-registration" "nix-path-registration" 86 85 fi 87 86
+5 -37
nixos/lib/make-squashfs.nix
··· 1 - { stdenv, squashfsTools, perl, pathsFromGraph 1 + { stdenv, squashfsTools, closureInfo 2 2 3 3 , # The root directory of the squashfs filesystem is filled with the 4 4 # closures of the Nix store paths listed here. ··· 8 8 stdenv.mkDerivation { 9 9 name = "squashfs.img"; 10 10 11 - nativeBuildInputs = [perl squashfsTools]; 12 - 13 - # For obtaining the closure of `storeContents'. 14 - exportReferencesGraph = 15 - map (x: [("closure-" + baseNameOf x) x]) storeContents; 11 + nativeBuildInputs = [ squashfsTools ]; 16 12 17 13 buildCommand = 18 14 '' 19 - # Add the closures of the top-level store objects. 20 - storePaths=$(perl ${pathsFromGraph} closure-*) 21 - 22 - # If a Hydra slave happens to have store paths with bad permissions/mtime, 23 - # abort now so that they don't end up in ISO images in the channel. 24 - # https://github.com/NixOS/nixpkgs/issues/32242 25 - hasBadPaths="" 26 - for path in $storePaths; do 27 - if [ -h "$path" ]; then 28 - continue 29 - fi 30 - 31 - mtime=$(stat -c %Y "$path") 32 - mode=$(stat -c %a "$path") 33 - 34 - if [ "$mtime" != 1 ]; then 35 - echo "Store path '$path' has an invalid mtime." 36 - hasBadPaths=1 37 - fi 38 - if [ "$mode" != 444 ] && [ "$mode" != 555 ]; then 39 - echo "Store path '$path' has invalid permissions ($mode)." 40 - hasBadPaths=1 41 - fi 42 - done 43 - 44 - if [ -n "$hasBadPaths" ]; then 45 - echo "You have bad paths in your store, please fix them." 46 - exit 1 47 - fi 15 + closureInfo=${closureInfo { rootPaths = storeContents; }} 48 16 49 17 # Also include a manifest of the closures in a format suitable 50 18 # for nix-store --load-db. 51 - printRegistration=1 perl ${pathsFromGraph} closure-* > nix-path-registration 19 + cp $closureInfo/registration nix-path-registration 52 20 53 21 # Generate the squashfs image. 54 - mksquashfs nix-path-registration $storePaths $out \ 22 + mksquashfs nix-path-registration $(cat $closureInfo/store-paths) $out \ 55 23 -keep-as-directory -all-root -b 1048576 -comp xz -Xdict-size 100% 56 24 ''; 57 25 }
+3
nixos/modules/config/users-groups.nix
··· 529 529 530 530 system.activationScripts.users = stringAfter [ "stdio" ] 531 531 '' 532 + install -m 0700 -d /root 533 + install -m 0755 -d /home 534 + 532 535 ${pkgs.perl}/bin/perl -w \ 533 536 -I${pkgs.perlPackages.FileSlurp}/lib/perl5/site_perl \ 534 537 -I${pkgs.perlPackages.JSON}/lib/perl5/site_perl \
+2 -6
nixos/modules/installer/cd-dvd/iso-image.nix
··· 331 331 config.system.build.toplevel.drvPath; 332 332 333 333 # Create the squashfs image that contains the Nix store. 334 - system.build.squashfsStore = import ../../../lib/make-squashfs.nix { 335 - inherit (pkgs) stdenv squashfsTools perl pathsFromGraph; 334 + system.build.squashfsStore = pkgs.callPackage ../../../lib/make-squashfs.nix { 336 335 storeContents = config.isoImage.storeContents; 337 336 }; 338 337 ··· 383 382 boot.loader.timeout = 10; 384 383 385 384 # Create the ISO image. 386 - system.build.isoImage = import ../../../lib/make-iso9660-image.nix ({ 387 - inherit (pkgs) stdenv perl pathsFromGraph xorriso syslinux; 388 - 385 + system.build.isoImage = pkgs.callPackage ../../../lib/make-iso9660-image.nix ({ 389 386 inherit (config.isoImage) isoName compressImage volumeID contents; 390 - 391 387 bootable = true; 392 388 bootImage = "/isolinux/isolinux.bin"; 393 389 } // optionalAttrs config.isoImage.makeUsbBootable {
+4 -4
nixos/modules/installer/tools/nix-fallback-paths.nix
··· 1 1 { 2 - x86_64-linux = "/nix/store/gy4yv67gv3j6in0lalw37j353zdmfcwm-nix-1.11.16"; 3 - i686-linux = "/nix/store/ifmyq5ryfxhhrzh62hiq65xyz1fwffga-nix-1.11.16"; 4 - aarch64-linux = "/nix/store/y9mfv3sx75mbfibf1zna1kq9v98fk2nb-nix-1.11.16"; 5 - x86_64-darwin = "/nix/store/hwpp7kia2f0in5ns2hiw41q38k30jpj2-nix-1.11.16"; 2 + x86_64-linux = "/nix/store/6p2gambjac7xdkd2a7w1dsxdk1q5cq4d-nix-2.0"; 3 + i686-linux = "/nix/store/zznnaijjk3nwx0cmpczxsvngmqzhl7r4-nix-2.0"; 4 + aarch64-linux = "/nix/store/ci96w9kxfkmlc7x2vwqiz4da0r6abxnq-nix-2.0"; 5 + x86_64-darwin = "/nix/store/xmi4fylvx4qc79ji9v5q3zfy9vfdy4sv-nix-2.0"; 6 6 }
+60
nixos/modules/installer/tools/nixos-enter.sh
··· 1 + #! @shell@ 2 + 3 + set -e 4 + 5 + # Re-exec ourselves in a private mount namespace so that our bind 6 + # mounts get cleaned up automatically. 7 + if [ -z "$NIXOS_ENTER_REEXEC" ]; then 8 + export NIXOS_ENTER_REEXEC=1 9 + if [ "$(id -u)" != 0 ]; then 10 + extraFlags="-r" 11 + fi 12 + exec unshare --fork --mount --uts --mount-proc --pid $extraFlags -- "$0" "$@" 13 + else 14 + mount --make-rprivate / 15 + fi 16 + 17 + mountPoint=/mnt 18 + command=("bash" "--login") 19 + system=/nix/var/nix/profiles/system 20 + 21 + while [ "$#" -gt 0 ]; do 22 + i="$1"; shift 1 23 + case "$i" in 24 + --root) 25 + mountPoint="$1"; shift 1 26 + ;; 27 + --system) 28 + system="$1"; shift 1 29 + ;; 30 + --help) 31 + exec man nixos-enter 32 + exit 1 33 + ;; 34 + --command|-c) 35 + command=("bash" "-c" "$1") 36 + shift 1 37 + ;; 38 + --) 39 + command=("$@") 40 + break 41 + ;; 42 + *) 43 + echo "$0: unknown option \`$i'" 44 + exit 1 45 + ;; 46 + esac 47 + done 48 + 49 + if [[ ! -e $mountPoint/etc/NIXOS ]]; then 50 + echo "$0: '$mountPoint' is not a NixOS installation" >&2 51 + exit 126 52 + fi 53 + 54 + mkdir -m 0755 -p "$mountPoint/dev" 55 + mount --rbind /dev "$mountPoint/dev" 56 + 57 + # Run the activation script. Set $LOCALE_ARCHIVE to supress some Perl locale warnings. 58 + LOCALE_ARCHIVE=$system/sw/lib/locale/locale-archive chroot "$mountPoint" "$system/activate" >&2 || true 59 + 60 + exec chroot "$mountPoint" "${command[@]}"
+66 -129
nixos/modules/installer/tools/nixos-install.sh
··· 1 1 #! @shell@ 2 2 3 - # - make Nix store etc. 4 - # - copy closure of Nix to target device 5 - # - register validity 6 - # - with a chroot to the target device: 7 - # * nix-env -p /nix/var/nix/profiles/system -i <nix-expr for the configuration> 8 - # * install the boot loader 3 + set -e 4 + shopt -s nullglob 5 + 6 + export PATH=@path@:$PATH 9 7 10 8 # Ensure a consistent umask. 11 9 umask 0022 12 10 13 - # Re-exec ourselves in a private mount namespace so that our bind 14 - # mounts get cleaned up automatically. 15 - if [ "$(id -u)" = 0 ]; then 16 - if [ -z "$NIXOS_INSTALL_REEXEC" ]; then 17 - export NIXOS_INSTALL_REEXEC=1 18 - exec unshare --mount --uts -- "$0" "$@" 19 - else 20 - mount --make-rprivate / 21 - fi 22 - fi 23 - 24 11 # Parse the command line for the -I flag 25 12 extraBuildFlags=() 26 - chrootCommand=(/run/current-system/sw/bin/bash) 27 - buildUsersGroup="nixbld" 13 + 14 + mountPoint=/mnt 15 + channelPath= 28 16 29 17 while [ "$#" -gt 0 ]; do 30 18 i="$1"; shift 1 31 19 case "$i" in 32 - --max-jobs|-j|--cores|-I) 20 + --max-jobs|-j|--cores|-I|--substituters) 33 21 j="$1"; shift 1 34 22 extraBuildFlags+=("$i" "$j") 35 23 ;; ··· 41 29 --root) 42 30 mountPoint="$1"; shift 1 43 31 ;; 44 - --closure) 45 - closure="$1"; shift 1 46 - buildUsersGroup="" 32 + --system|--closure) 33 + system="$1"; shift 1 34 + ;; 35 + --channel) 36 + channelPath="$1"; shift 1 47 37 ;; 48 38 --no-channel-copy) 49 39 noChannelCopy=1 ··· 57 47 --show-trace) 58 48 extraBuildFlags+=("$i") 59 49 ;; 60 - --chroot) 61 - runChroot=1 62 - if [[ "$@" != "" ]]; then 63 - chrootCommand=("$@") 64 - fi 65 - break 66 - ;; 67 50 --help) 68 51 exec man nixos-install 69 52 exit 1 70 53 ;; 54 + --debug) 55 + set -x 56 + ;; 71 57 *) 72 58 echo "$0: unknown option \`$i'" 73 59 exit 1 ··· 75 61 esac 76 62 done 77 63 78 - set -e 79 - shopt -s nullglob 80 - 81 - if test -z "$mountPoint"; then 82 - mountPoint=/mnt 83 - fi 84 - 85 64 if ! test -e "$mountPoint"; then 86 65 echo "mount point $mountPoint doesn't exist" 87 66 exit 1 88 67 fi 89 68 90 69 # Get the path of the NixOS configuration file. 91 - if test -z "$NIXOS_CONFIG"; then 92 - NIXOS_CONFIG=/etc/nixos/configuration.nix 70 + if [[ -z $NIXOS_CONFIG ]]; then 71 + NIXOS_CONFIG=$mountPoint/etc/nixos/configuration.nix 93 72 fi 94 73 95 - if [ ! -e "$mountPoint/$NIXOS_CONFIG" ] && [ -z "$closure" ]; then 96 - echo "configuration file $mountPoint/$NIXOS_CONFIG doesn't exist" 74 + if [[ ${NIXOS_CONFIG:0:1} != / ]]; then 75 + echo "$0: \$NIXOS_CONFIG is not an absolute path" 97 76 exit 1 98 77 fi 99 78 100 - 101 - # Builds will use users that are members of this group 102 - extraBuildFlags+=(--option "build-users-group" "$buildUsersGroup") 103 - 104 - # Inherit binary caches from the host 105 - # TODO: will this still work with Nix 1.12 now that it has no perl? Probably not... 106 - binary_caches="$(@perl@/bin/perl -I @nix@/lib/perl5/site_perl/*/* -e 'use Nix::Config; Nix::Config::readConfig; print $Nix::Config::config{"binary-caches"};')" 107 - extraBuildFlags+=(--option "binary-caches" "$binary_caches") 108 - 109 - # We only need nixpkgs in the path if we don't already have a system closure to install 110 - if [[ -z "$closure" ]]; then 111 - nixpkgs="$(readlink -f "$(nix-instantiate --find-file nixpkgs)")" 112 - export NIX_PATH="nixpkgs=$nixpkgs:nixos-config=$mountPoint/$NIXOS_CONFIG" 79 + if [[ ! -e $NIXOS_CONFIG && -z $system ]]; then 80 + echo "configuration file $NIXOS_CONFIG doesn't exist" 81 + exit 1 113 82 fi 114 - unset NIXOS_CONFIG 115 83 116 - # These get created in nixos-prepare-root as well, but we want to make sure they're here in case we're 117 - # running with --chroot. TODO: --chroot should just be split into a separate tool. 118 - mkdir -m 0755 -p "$mountPoint/dev" "$mountPoint/proc" "$mountPoint/sys" 119 - 120 - # Set up some bind mounts we'll want regardless of chroot or not 121 - mount --rbind /dev "$mountPoint/dev" 122 - mount --rbind /proc "$mountPoint/proc" 123 - mount --rbind /sys "$mountPoint/sys" 124 - 125 - # If we asked for a chroot, that means we're not actually installing anything (yeah I was confused too) 126 - # and we just want to run a command in the context of a $mountPoint that we're assuming has already been 127 - # set up by a previous nixos-install invocation. In that case we set up some remaining bind mounts and 128 - # exec the requested command, skipping the rest of the installation procedure. 129 - if [ -n "$runChroot" ]; then 130 - mount -t tmpfs -o "mode=0755" none $mountPoint/run 131 - rm -rf $mountPoint/var/run 132 - ln -s /run $mountPoint/var/run 133 - for f in /etc/resolv.conf /etc/hosts; do rm -f $mountPoint/$f; [ -f "$f" ] && cp -Lf $f $mountPoint/etc/; done 134 - for f in /etc/passwd /etc/group; do touch $mountPoint/$f; [ -f "$f" ] && mount --rbind -o ro $f $mountPoint/$f; done 135 - 136 - if ! [ -L $mountPoint/nix/var/nix/profiles/system ]; then 137 - echo "$0: installation not finished; cannot chroot into installation directory" 138 - exit 1 139 - fi 140 - ln -s /nix/var/nix/profiles/system $mountPoint/run/current-system 141 - exec chroot $mountPoint "${chrootCommand[@]}" 142 - fi 143 - 144 - # A place to drop temporary closures 84 + # A place to drop temporary stuff. 145 85 trap "rm -rf $tmpdir" EXIT 146 86 tmpdir="$(mktemp -d)" 147 87 148 - # Build a closure (on the host; we then copy it into the guest) 149 - function closure() { 150 - nix-build "${extraBuildFlags[@]}" --no-out-link -E "with import <nixpkgs> {}; runCommand \"closure\" { exportReferencesGraph = [ \"x\" (buildEnv { name = \"env\"; paths = [ ($1) stdenv ]; }) ]; } \"cp x \$out\"" 151 - } 88 + sub="auto?trusted=1" 152 89 153 - system_closure="$tmpdir/system.closure" 154 - # Use a FIFO for piping nix-store --export into nix-store --import, saving disk 155 - # I/O and space. nix-store --import is run by nixos-prepare-root. 156 - mkfifo $system_closure 157 - 158 - if [ -z "$closure" ]; then 159 - expr="(import <nixpkgs/nixos> {}).system" 160 - system_root="$(nix-build -E "$expr")" 161 - system_closure="$(closure "$expr")" 162 - else 163 - system_root=$closure 164 - # Create a temporary file ending in .closure (so nixos-prepare-root knows to --import it) to transport the store closure 165 - # to the filesytem we're preparing. Also delete it on exit! 166 - # Run in background to avoid blocking while trying to write to the FIFO 167 - # $system_closure refers to 168 - nix-store --export $(nix-store -qR $closure) > $system_closure & 90 + # Build the system configuration in the target filesystem. 91 + if [[ -z $system ]]; then 92 + echo "building the configuration in $NIXOS_CONFIG..." 93 + outLink="$tmpdir/system" 94 + nix build --out-link "$outLink" --store "$mountPoint" "${extraBuildFlags[@]}" \ 95 + --extra-substituters "$sub" \ 96 + -f '<nixpkgs/nixos>' system -I "nixos-config=$NIXOS_CONFIG" 97 + system=$(readlink -f $outLink) 169 98 fi 170 99 171 - channel_root="$(nix-env -p /nix/var/nix/profiles/per-user/root/channels -q nixos --no-name --out-path 2>/dev/null || echo -n "")" 172 - channel_closure="$tmpdir/channel.closure" 173 - nix-store --export $channel_root > $channel_closure 100 + # Set the system profile to point to the configuration. TODO: combine 101 + # this with the previous step once we have a nix-env replacement with 102 + # a progress bar. 103 + nix-env --store "$mountPoint" "${extraBuildFlags[@]}" \ 104 + --extra-substituters "$sub" \ 105 + -p $mountPoint/nix/var/nix/profiles/system --set "$system" 174 106 175 - # Populate the target root directory with the basics 176 - @prepare_root@/bin/nixos-prepare-root "$mountPoint" "$channel_root" "$system_root" @nixClosure@ "$system_closure" "$channel_closure" 177 - 178 - # nixos-prepare-root doesn't currently do anything with file ownership, so we set it up here instead 179 - chown @root_uid@:@nixbld_gid@ $mountPoint/nix/store 180 - 181 - 107 + # Copy the NixOS/Nixpkgs sources to the target as the initial contents 108 + # of the NixOS channel. 109 + if [[ -z $noChannelCopy ]]; then 110 + if [[ -z $channelPath ]]; then 111 + channelPath="$(nix-env -p /nix/var/nix/profiles/per-user/root/channels -q nixos --no-name --out-path 2>/dev/null || echo -n "")" 112 + fi 113 + if [[ -n $channelPath ]]; then 114 + echo "copying channel..." 115 + mkdir -p $mountPoint/nix/var/nix/profiles/per-user/root 116 + nix-env --store "$mountPoint" "${extraBuildFlags[@]}" --extra-substituters "$sub" \ 117 + -p $mountPoint/nix/var/nix/profiles/per-user/root/channels --set "$channelPath" --quiet 118 + install -m 0700 -d $mountPoint/root/.nix-defexpr 119 + ln -sfn /nix/var/nix/profiles/per-user/root/channels $mountPoint/root/.nix-defexpr/channels 120 + fi 121 + fi 182 122 183 - # Grub needs an mtab. 184 - ln -sfn /proc/mounts $mountPoint/etc/mtab 123 + # Mark the target as a NixOS installation, otherwise switch-to-configuration will chicken out. 124 + mkdir -m 0755 -p "$mountPoint/etc" 125 + touch "$mountPoint/etc/NIXOS" 185 126 186 127 # Switch to the new system configuration. This will install Grub with 187 128 # a menu default pointing at the kernel/initrd/etc of the new 188 129 # configuration. 189 - echo "finalising the installation..." 190 - if [ -z "$noBootLoader" ]; then 191 - NIXOS_INSTALL_BOOTLOADER=1 chroot $mountPoint \ 192 - /nix/var/nix/profiles/system/bin/switch-to-configuration boot 130 + if [[ -z $noBootLoader ]]; then 131 + echo "installing the boot loader..." 132 + # Grub needs an mtab. 133 + ln -sfn /proc/mounts $mountPoint/etc/mtab 134 + NIXOS_INSTALL_BOOTLOADER=1 nixos-enter --root "$mountPoint" -- /run/current-system/bin/switch-to-configuration boot 193 135 fi 194 136 195 - # Run the activation script. 196 - chroot $mountPoint /nix/var/nix/profiles/system/activate 197 - 198 - 199 - # Ask the user to set a root password. 200 - if [ -z "$noRootPasswd" ] && chroot $mountPoint [ -x /run/wrappers/bin/passwd ] && [ -t 0 ]; then 201 - echo "setting root password..." 202 - chroot $mountPoint /run/wrappers/bin/passwd 137 + # Ask the user to set a root password, but only if the passwd command 138 + # exists (i.e. when mutable user accounts are enabled). 139 + if [[ -z $noRootPasswd ]] && [ -t 0 ]; then 140 + 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' 203 141 fi 204 - 205 142 206 143 echo "installation finished!"
-104
nixos/modules/installer/tools/nixos-prepare-root.sh
··· 1 - #! @shell@ 2 - 3 - # This script's goal is to perform all "static" setup of a filesystem structure from pre-built store paths. Everything 4 - # in here should run in a non-root context and inside a Nix builder. It's designed primarily to be called from image- 5 - # building scripts and from nixos-install, but because it makes very few assumptions about the context in which it runs, 6 - # it could be useful in other contexts as well. 7 - # 8 - # Current behavior: 9 - # - set up basic filesystem structure 10 - # - make Nix store etc. 11 - # - copy Nix, system, channel, and misceallaneous closures to target Nix store 12 - # - register validity of all paths in the target store 13 - # - set up channel and system profiles 14 - 15 - # Ensure a consistent umask. 16 - umask 0022 17 - 18 - set -e 19 - 20 - mountPoint="$1" 21 - channel="$2" 22 - system="$3" 23 - shift 3 24 - closures="$@" 25 - 26 - PATH="@coreutils@/bin:@nix@/bin:@perl@/bin:@utillinux@/bin:@rsync@/bin" 27 - 28 - if ! test -e "$mountPoint"; then 29 - echo "mount point $mountPoint doesn't exist" 30 - exit 1 31 - fi 32 - 33 - # Create a few of the standard directories in the target root directory. 34 - install -m 0755 -d $mountPoint/dev $mountPoint/proc $mountPoint/sys $mountPoint/etc $mountPoint/run $mountPoint/home 35 - install -m 01777 -d $mountPoint/tmp 36 - install -m 0755 -d $mountPoint/tmp/root 37 - install -m 0755 -d $mountPoint/var 38 - install -m 0700 -d $mountPoint/root 39 - 40 - ln -sf /run $mountPoint/var/run 41 - 42 - # Create the necessary Nix directories on the target device 43 - install -m 0755 -d \ 44 - $mountPoint/nix/var/nix/gcroots \ 45 - $mountPoint/nix/var/nix/temproots \ 46 - $mountPoint/nix/var/nix/userpool \ 47 - $mountPoint/nix/var/nix/profiles \ 48 - $mountPoint/nix/var/nix/db \ 49 - $mountPoint/nix/var/log/nix/drvs 50 - 51 - install -m 1775 -d $mountPoint/nix/store 52 - 53 - # All Nix operations below should operate on our target store, not /nix/store. 54 - # N.B: this relies on Nix 1.12 or higher 55 - export NIX_REMOTE=local?root=$mountPoint 56 - 57 - # Copy our closures to the Nix store on the target mount point, unless they're already there. 58 - for i in $closures; do 59 - # We support closures both in the format produced by `nix-store --export` and by `exportReferencesGraph`, 60 - # mostly because there doesn't seem to be a single format that can be produced outside of a nix build and 61 - # inside one. See https://github.com/NixOS/nix/issues/1242 for more discussion. 62 - if [[ "$i" =~ \.closure$ ]]; then 63 - echo "importing serialized closure $i to $mountPoint..." 64 - nix-store --import < $i 65 - else 66 - # There has to be a better way to do this, right? 67 - echo "copying closure $i to $mountPoint..." 68 - for j in $(perl @pathsFromGraph@ $i); do 69 - echo " $j... " 70 - rsync -a $j $mountPoint/nix/store/ 71 - done 72 - 73 - nix-store --option build-users-group root --register-validity < $i 74 - fi 75 - done 76 - 77 - # Create the required /bin/sh symlink; otherwise lots of things 78 - # (notably the system() function) won't work. 79 - if [ ! -x $mountPoint/@shell@ ]; then 80 - echo "Error: @shell@ wasn't included in the closure" >&2 81 - exit 1 82 - fi 83 - install -m 0755 -d $mountPoint/bin 84 - ln -sf @shell@ $mountPoint/bin/sh 85 - 86 - echo "setting the system closure to '$system'..." 87 - nix-env "${extraBuildFlags[@]}" -p $mountPoint/nix/var/nix/profiles/system --set "$system" 88 - 89 - ln -sfn /nix/var/nix/profiles/system $mountPoint/run/current-system 90 - 91 - # Copy the NixOS/Nixpkgs sources to the target as the initial contents of the NixOS channel. 92 - install -m 0755 -d $mountPoint/nix/var/nix/profiles 93 - install -m 1777 -d $mountPoint/nix/var/nix/profiles/per-user 94 - install -m 0755 -d $mountPoint/nix/var/nix/profiles/per-user/root 95 - 96 - if [ -z "$noChannelCopy" ] && [ -n "$channel" ]; then 97 - echo "copying channel..." 98 - nix-env --option build-use-substitutes false "${extraBuildFlags[@]}" -p $mountPoint/nix/var/nix/profiles/per-user/root/channels --set "$channel" --quiet 99 - fi 100 - install -m 0700 -d $mountPoint/root/.nix-defexpr 101 - ln -sfn /nix/var/nix/profiles/per-user/root/channels $mountPoint/root/.nix-defexpr/channels 102 - 103 - # Mark the target as a NixOS installation, otherwise switch-to-configuration will chicken out. 104 - touch $mountPoint/etc/NIXOS
+11 -21
nixos/modules/installer/tools/tools.nix
··· 1 1 # This module generates nixos-install, nixos-rebuild, 2 2 # nixos-generate-config, etc. 3 3 4 - { config, pkgs, modulesPath, ... }: 4 + { config, lib, pkgs, modulesPath, ... }: 5 + 6 + with lib; 5 7 6 8 let 7 9 cfg = config.installer; ··· 16 18 src = ./nixos-build-vms/nixos-build-vms.sh; 17 19 }; 18 20 19 - nixos-prepare-root = makeProg { 20 - name = "nixos-prepare-root"; 21 - src = ./nixos-prepare-root.sh; 22 - 23 - nix = pkgs.nixUnstable; 24 - inherit (pkgs) perl pathsFromGraph rsync utillinux coreutils; 25 - }; 26 - 27 21 nixos-install = makeProg { 28 22 name = "nixos-install"; 29 23 src = ./nixos-install.sh; 30 - 31 - inherit (pkgs) perl pathsFromGraph rsync; 32 24 nix = config.nix.package.out; 33 - cacert = "${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt"; 34 - root_uid = config.ids.uids.root; 35 - nixbld_gid = config.ids.gids.nixbld; 36 - prepare_root = nixos-prepare-root; 37 - 38 - nixClosure = pkgs.runCommand "closure" 39 - { exportReferencesGraph = ["refs" config.nix.package.out]; } 40 - "cp refs $out"; 25 + path = makeBinPath [ nixos-enter ]; 41 26 }; 42 27 43 28 nixos-rebuild = ··· 69 54 inherit (config.system.nixos) version codeName revision; 70 55 }; 71 56 57 + nixos-enter = makeProg { 58 + name = "nixos-enter"; 59 + src = ./nixos-enter.sh; 60 + }; 61 + 72 62 in 73 63 74 64 { ··· 77 67 78 68 environment.systemPackages = 79 69 [ nixos-build-vms 80 - nixos-prepare-root 81 70 nixos-install 82 71 nixos-rebuild 83 72 nixos-generate-config 84 73 nixos-option 85 74 nixos-version 75 + nixos-enter 86 76 ]; 87 77 88 78 system.build = { 89 - inherit nixos-install nixos-prepare-root nixos-generate-config nixos-option nixos-rebuild; 79 + inherit nixos-install nixos-prepare-root nixos-generate-config nixos-option nixos-rebuild nixos-enter; 90 80 }; 91 81 92 82 };
+7 -1
nixos/modules/profiles/installation-device.nix
··· 72 72 73 73 # To speed up installation a little bit, include the complete 74 74 # stdenv in the Nix store on the CD. 75 - system.extraDependencies = with pkgs; [ stdenv stdenvNoCC busybox ]; 75 + system.extraDependencies = with pkgs; 76 + [ 77 + stdenv 78 + stdenvNoCC # for runCommand 79 + busybox 80 + jq # for closureInfo 81 + ]; 76 82 77 83 # Show all debug messages from the kernel but don't log refused packets 78 84 # because we have the firewall enabled. This makes installs from the
+2 -2
nixos/modules/services/misc/nix-daemon.nix
··· 33 33 sh = pkgs.stdenv.shell; 34 34 binshDeps = pkgs.writeReferencesToFile sh; 35 35 in 36 - pkgs.runCommand "nix.conf" { extraOptions = cfg.extraOptions; inherit binshDeps; } '' 36 + pkgs.runCommand "nix.conf" { extraOptions = cfg.extraOptions; } '' 37 37 ${optionalString (!isNix20) '' 38 - extraPaths=$(for i in $(cat binshDeps); do if test -d $i; then echo $i; fi; done) 38 + extraPaths=$(for i in $(cat ${binshDeps}); do if test -d $i; then echo $i; fi; done) 39 39 ''} 40 40 cat > $out <<END 41 41 # WARNING: this file is generated from the nix.* options in
+1 -8
nixos/modules/system/activation/activation-script.nix
··· 117 117 118 118 config = { 119 119 120 - system.activationScripts.stdio = 121 - '' 122 - # Needed by some programs. 123 - ln -sfn /proc/self/fd /dev/fd 124 - ln -sfn /proc/self/fd/0 /dev/stdin 125 - ln -sfn /proc/self/fd/1 /dev/stdout 126 - ln -sfn /proc/self/fd/2 /dev/stderr 127 - ''; 120 + system.activationScripts.stdio = ""; # obsolete 128 121 129 122 system.activationScripts.var = 130 123 ''
+1 -1
nixos/modules/system/boot/modprobe.nix
··· 54 54 55 55 environment.systemPackages = [ pkgs.kmod ]; 56 56 57 - system.activationScripts.modprobe = 57 + system.activationScripts.modprobe = stringAfter ["specialfs"] 58 58 '' 59 59 # Allow the kernel to find our wrapped modprobe (which searches 60 60 # in the right location in the Nix store for kernel modules).
-1
nixos/modules/system/boot/stage-2-init.sh
··· 82 82 mkdir -m 01777 -p /tmp 83 83 mkdir -m 0755 -p /var/{log,lib,db} /nix/var /etc/nixos/ \ 84 84 /run/lock /home /bin # for the /bin/sh symlink 85 - install -m 0700 -d /root 86 85 87 86 88 87 # Miscellaneous boot time cleanup.
+4
nixos/release-small.nix
··· 50 50 separateBoot 51 51 simple; 52 52 }; 53 + boot = { 54 + inherit (nixos'.tests.boot) 55 + biosCdrom; 56 + }; 53 57 }; 54 58 }; 55 59
+6
nixos/tests/boot.nix
··· 24 24 my $machine = createMachine({ ${machineConfig}, qemuFlags => '-m 768' }); 25 25 $machine->start; 26 26 $machine->waitForUnit("multi-user.target"); 27 + $machine->succeed("nix verify -r --no-trust /run/current-system"); 28 + 29 + # Test whether the channel got installed correctly. 30 + $machine->succeed("nix-instantiate --dry-run '<nixpkgs>' -A hello"); 31 + $machine->succeed("nix-env --dry-run -iA nixos.procps"); 32 + 27 33 $machine->shutdown; 28 34 ''; 29 35 };
+7 -4
nixos/tests/installer.nix
··· 145 145 # Check that the daemon works, and that non-root users can run builds (this will build a new profile generation through the daemon) 146 146 $machine->succeed("su alice -l -c 'nix-env -iA nixos.procps' >&2"); 147 147 148 - # We need to a writable nix-store on next boot. 148 + # We need a writable Nix store on next boot. 149 149 $machine->copyFileFromHost( 150 150 "${ makeConfig { inherit bootLoader grubVersion grubDevice grubIdentifier grubUseEfi extraConfig; forceGrubReinstallCount = 1; } }", 151 151 "/etc/nixos/configuration.nix"); ··· 195 195 }; 196 196 nodes = { 197 197 198 - # The configuration of the machine used to run "nixos-install". It 199 - # also has a web server that simulates cache.nixos.org. 198 + # The configuration of the machine used to run "nixos-install". 200 199 machine = 201 200 { config, lib, pkgs, ... }: 202 201 ··· 208 207 209 208 virtualisation.diskSize = 8 * 1024; 210 209 virtualisation.memorySize = 1024; 211 - virtualisation.writableStore = true; 212 210 213 211 # Use a small /dev/vdb as the root disk for the 214 212 # installer. This ensures the target disk (/dev/vda) is ··· 245 243 ++ optionals (bootLoader == "grub" && grubVersion == 2) [ pkgs.grub2 pkgs.grub2_efi ]; 246 244 247 245 nix.binaryCaches = mkForce [ ]; 246 + nix.extraOptions = 247 + '' 248 + hashed-mirrors = 249 + connect-timeout = 1 250 + ''; 248 251 }; 249 252 250 253 };
+10 -1
nixos/tests/misc.nix
··· 1 1 # Miscellaneous small tests that don't warrant their own VM run. 2 2 3 - import ./make-test.nix ({ pkgs, ...} : { 3 + import ./make-test.nix ({ pkgs, ...} : rec { 4 4 name = "misc"; 5 5 meta = with pkgs.stdenv.lib.maintainers; { 6 6 maintainers = [ eelco chaoflow ]; 7 7 }; 8 + 9 + foo = pkgs.writeText "foo" "Hello World"; 8 10 9 11 machine = 10 12 { config, lib, pkgs, ... }: ··· 27 29 security.sudo = { enable = true; wheelNeedsPassword = false; }; 28 30 boot.kernel.sysctl."vm.swappiness" = 1; 29 31 boot.kernelParams = [ "vsyscall=emulate" ]; 32 + system.extraDependencies = [ foo ]; 30 33 }; 31 34 32 35 testScript = 33 36 '' 37 + subtest "nix-db", sub { 38 + my $json = $machine->succeed("nix path-info --json ${foo}"); 39 + $json =~ /"narHash":"sha256:0afw0d9j1hvwiz066z93jiddc33nxg6i6qyp26vnqyglpyfivlq5"/ or die "narHash not set"; 40 + $json =~ /"narSize":128/ or die "narSize not set"; 41 + }; 42 + 34 43 subtest "nixos-version", sub { 35 44 $machine->succeed("[ `nixos-version | wc -w` = 2 ]"); 36 45 };
+17 -41
pkgs/build-support/closure-info.nix
··· 4 4 # "nix-store --load-db" and "nix-store --register-validity 5 5 # --hash-given". 6 6 7 - { stdenv, coreutils, jq, perl, pathsFromGraph }: 7 + { stdenv, coreutils, jq }: 8 8 9 9 { rootPaths }: 10 10 11 - #if builtins.langVersion >= 5 then 12 - # FIXME: it doesn't work on Hydra, failing to find mkdir; 13 - # perhaps .attrs.sh clobbers PATH with new nix? 14 - if false then 11 + assert builtins.langVersion >= 5; 15 12 16 - # Nix >= 1.12: Include NAR hash / size info. 17 - 18 - stdenv.mkDerivation { 19 - name = "closure-info"; 20 - 21 - __structuredAttrs = true; 13 + stdenv.mkDerivation { 14 + name = "closure-info"; 22 15 23 - exportReferencesGraph.closure = rootPaths; 24 - 25 - PATH = "${coreutils}/bin:${jq}/bin"; 26 - 27 - builder = builtins.toFile "builder" 28 - '' 29 - if [ -e .attrs.sh ]; then . .attrs.sh; fi 30 - 31 - out=''${outputs[out]} 32 - 33 - mkdir $out 34 - 35 - jq -r '.closure | map([.path, .narHash, .narSize, "", (.references | length)] + .references) | add | map("\(.)\n") | add' < .attrs.json | head -n -1 > $out/registration 36 - jq -r .closure[].path < .attrs.json > $out/store-paths 37 - ''; 38 - } 16 + __structuredAttrs = true; 39 17 40 - else 18 + exportReferencesGraph.closure = rootPaths; 41 19 42 - # Nix < 1.12 20 + PATH = "${coreutils}/bin:${jq}/bin"; 43 21 44 - stdenv.mkDerivation { 45 - name = "closure-info"; 22 + builder = builtins.toFile "builder" 23 + '' 24 + . .attrs.sh 46 25 47 - exportReferencesGraph = 48 - map (x: [("closure-" + baseNameOf x) x]) rootPaths; 26 + out=''${outputs[out]} 49 27 50 - buildInputs = [ perl ]; 28 + mkdir $out 51 29 52 - buildCommand = 53 - '' 54 - mkdir $out 55 - printRegistration=1 perl ${pathsFromGraph} closure-* > $out/registration 56 - perl ${pathsFromGraph} closure-* > $out/store-paths 57 - ''; 58 - } 30 + jq -r ".closure | map(.narSize) | add" < .attrs.json > $out/total-nar-size 31 + jq -r '.closure | map([.path, .narHash, .narSize, "", (.references | length)] + .references) | add | map("\(.)\n") | add' < .attrs.json | head -n -1 > $out/registration 32 + jq -r .closure[].path < .attrs.json > $out/store-paths 33 + ''; 34 + }
+3 -6
pkgs/build-support/kernel/make-initrd.nix
··· 12 12 # `contents = {object = ...; symlink = /init;}' is a typical 13 13 # argument. 14 14 15 - { stdenv, perl, cpio, contents, compressor, prepend, ubootTools 15 + { stdenv, closureInfo, cpio, contents, compressor, prepend, ubootTools 16 16 , hostPlatform 17 17 }: 18 18 ··· 22 22 23 23 makeUInitrd = hostPlatform.platform.kernelTarget == "uImage"; 24 24 25 - nativeBuildInputs = [ perl cpio ] 25 + nativeBuildInputs = [ cpio ] 26 26 ++ stdenv.lib.optional makeUInitrd ubootTools; 27 27 28 28 # !!! should use XML. ··· 30 30 symlinks = map (x: x.symlink) contents; 31 31 suffices = map (x: if x ? suffix then x.suffix else "none") contents; 32 32 33 - # For obtaining the closure of `contents'. 34 - exportReferencesGraph = 35 - map (x: [("closure-" + baseNameOf x.symlink) x.object]) contents; 36 - pathsFromGraph = ./paths-from-graph.pl; 33 + closure = closureInfo { rootPaths = (map (x: x.object) contents); }; 37 34 38 35 inherit compressor prepend; 39 36 }
+1 -5
pkgs/build-support/kernel/make-initrd.sh
··· 25 25 done 26 26 27 27 28 - # Get the paths in the closure of `object'. 29 - storePaths=$(perl $pathsFromGraph closure-*) 30 - 31 - 32 28 # Paths in cpio archives *must* be relative, otherwise the kernel 33 29 # won't unpack 'em. 34 - (cd root && cp -prd --parents $storePaths .) 30 + (cd root && cp -prd --parents $(cat $closure/store-paths) .) 35 31 36 32 37 33 # Put the closure in a gzipped cpio archive.
+2
pkgs/build-support/kernel/paths-from-graph.pl
··· 1 + # NOTE: this script is deprecated. Use closureInfo instead. 2 + 1 3 # Parses a /nix/store/*-closure file and prints 2 4 # various information. 3 5 # By default, the nodes in the graph are printed to stdout.
+9 -1
pkgs/tools/package-management/nix/default.nix
··· 116 116 117 117 nix = nixStable; 118 118 119 - nixStable = (common rec { 119 + nix1 = (common rec { 120 120 name = "nix-1.11.16"; 121 121 src = fetchurl { 122 122 url = "http://nixos.org/releases/nix/${name}/${name}.tar.xz"; 123 123 sha256 = "0ca5782fc37d62238d13a620a7b4bff6a200bab1bd63003709249a776162357c"; 124 124 }; 125 125 }) // { perl-bindings = nixStable; }; 126 + 127 + nixStable = (common rec { 128 + name = "nix-2.0"; 129 + src = fetchurl { 130 + url = "http://nixos.org/releases/nix/${name}/${name}.tar.xz"; 131 + sha256 = "7024d327314bf92c1d3e6cccd944929828a44b24093954036bfb0115a92f5a14"; 132 + }; 133 + }) // { perl-bindings = perl-bindings { nix = nixStable; }; }; 126 134 127 135 nixUnstable = (lib.lowPrio (common rec { 128 136 name = "nix-2.0${suffix}";
+4 -8
pkgs/top-level/all-packages.nix
··· 4047 4047 4048 4048 p7zip = callPackage ../tools/archivers/p7zip { }; 4049 4049 4050 - packagekit = callPackage ../tools/package-management/packagekit { 4051 - nix = nixUnstable; 4052 - }; 4050 + packagekit = callPackage ../tools/package-management/packagekit { }; 4053 4051 4054 4052 packagekit-qt = libsForQt5.callPackage ../tools/package-management/packagekit/qt.nix { }; 4055 4053 ··· 6978 6976 mujs = callPackage ../development/interpreters/mujs { }; 6979 6977 6980 6978 nix-exec = callPackage ../development/interpreters/nix-exec { 6981 - nix = nixUnstable; 6982 - 6983 6979 git = gitMinimal; 6984 6980 }; 6985 6981 ··· 10573 10569 }; 10574 10570 libnghttp2 = nghttp2.lib; 10575 10571 10576 - nix-plugins = callPackage ../development/libraries/nix-plugins 10577 - { nix = nixUnstable; }; 10572 + nix-plugins = callPackage ../development/libraries/nix-plugins { }; 10578 10573 10579 10574 nlohmann_json = callPackage ../development/libraries/nlohmann_json { }; 10580 10575 ··· 20231 20226 stateDir = config.nix.stateDir or "/nix/var"; 20232 20227 }) 20233 20228 nix 20229 + nix1 20234 20230 nixStable 20235 20231 nixUnstable; 20236 20232 ··· 20242 20238 20243 20239 nixui = callPackage ../tools/package-management/nixui { node_webkit = nwjs_0_12; }; 20244 20240 20245 - nix-bundle = callPackage ../tools/package-management/nix-bundle { nix = nixUnstable; }; 20241 + nix-bundle = callPackage ../tools/package-management/nix-bundle { }; 20246 20242 20247 20243 nix-delegate = haskell.lib.justStaticExecutables haskellPackages.nix-delegate; 20248 20244 nix-deploy = haskell.lib.justStaticExecutables haskellPackages.nix-deploy;