Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to Nix 2.0 #34636

Merged
merged 38 commits into from
Mar 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
294a4e6
Use nixUnstable as the default temporarily
edolstra Feb 5, 2018
60cb230
Add a "nixos-enter" command
edolstra Feb 5, 2018
e88f289
nixos-install: Make compatible with Nix 2.0
edolstra Feb 5, 2018
1346923
modprobe activation: Order after specialfs
edolstra Feb 5, 2018
f9e64db
nixos-enter: Don't mount special filesystems
edolstra Feb 5, 2018
cc0caac
Move creation of /root to the activation script
edolstra Feb 5, 2018
5193807
VM tests: Initialize the Nix database with correct NAR hashes/sizes
edolstra Feb 7, 2018
df117ac
ISO images: Initialize the Nix database with correct NAR hashes/sizes
edolstra Feb 7, 2018
f0979ca
nixos-install: Don't require root
edolstra Feb 7, 2018
bb030ec
nixos-enter: Check whether --root denotes a NixOS installation
edolstra Feb 7, 2018
16bdaf3
Remove creation of /dev/{fd,stdin,stdout,stderr}
edolstra Feb 7, 2018
da702a4
nixos-enter: Don't require root
edolstra Feb 7, 2018
6daad9b
nixos-install: Fix --closure
edolstra Feb 7, 2018
598a3f5
nixos-install: Create /etc
edolstra Feb 7, 2018
e76849d
nixUnstable: 2.0pre5889_c287d731 -> 2.0pre5914_48c192ca
edolstra Feb 7, 2018
f64a4af
Fix comments
edolstra Feb 7, 2018
5d8860b
nixos-install: Accept --substituters
edolstra Feb 7, 2018
9802da5
make-disk-image.nix: Use nixos-install again
edolstra Feb 7, 2018
0f5d597
nixos-prepare-root: Remove
edolstra Feb 7, 2018
847ea13
Doh
edolstra Feb 7, 2018
32af695
nix: 1.11.16 -> 2.0
edolstra Feb 22, 2018
bae19ef
Doh
edolstra Feb 22, 2018
fab1218
Doh
edolstra Feb 22, 2018
d12c991
Merge remote-tracking branch 'origin/master' into nix-2.0
edolstra Feb 22, 2018
776a5e6
makeInitrd: Use closureInfo
edolstra Feb 8, 2018
adf8074
closureInfo: Report the total closure size.
shlevy Feb 23, 2018
8c6f922
Merge pull request #35402 from shlevy/closure-info-total-size
edolstra Feb 23, 2018
cc2eeef
Fix installing the Nixpkgs channel on the installation media
edolstra Feb 27, 2018
0d00215
Cleanup
edolstra Feb 27, 2018
212dd84
Cleanup
edolstra Feb 27, 2018
0867f30
Add the boot test to release-small.nix
edolstra Feb 27, 2018
b14d9e1
Add jq to the installation media
edolstra Feb 27, 2018
84f93dd
nixos-install: Create /root/.nix-defexpr
edolstra Feb 27, 2018
9e8cf40
nixos/tests/installer.nix: Don't use a writable store
edolstra Feb 27, 2018
9fc786c
Create /home with the right permissions
edolstra Feb 27, 2018
ceb0a28
Don't try hashed mirrors in the installer test
edolstra Feb 27, 2018
b70c93f
Merge branch 'master' into nix-2.0
vcunat Mar 3, 2018
729d72f
18.03 release notes: nix-2.0 by default
vcunat Mar 3, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions nixos/doc/manual/development/testing-installer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,17 @@ tedious, so here is a quick way to see if the installer works
properly:

<screen>
$ nix-build -A config.system.build.nixos-install
# mount -t tmpfs none /mnt
# nixos-generate-config --root /mnt
$ nix-build '&lt;nixpkgs/nixos>' -A config.system.build.nixos-install
# ./result/bin/nixos-install</screen>

To start a login shell in the new NixOS installation in
<filename>/mnt</filename>:

<screen>
# ./result/bin/nixos-install --chroot
$ nix-build '&lt;nixpkgs/nixos>' -A config.system.build.nixos-enter
# ./result/bin/nixos-enter
</screen>

</para>
Expand Down
119 changes: 119 additions & 0 deletions nixos/doc/manual/man-nixos-enter.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
<refentry xmlns="http://docbook.org/ns/docbook"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:xi="http://www.w3.org/2001/XInclude">

<refmeta>
<refentrytitle><command>nixos-enter</command></refentrytitle>
<manvolnum>8</manvolnum>
<refmiscinfo class="source">NixOS</refmiscinfo>
<!-- <refmiscinfo class="version"><xi:include href="version.txt" parse="text"/></refmiscinfo> -->
</refmeta>

<refnamediv>
<refname><command>nixos-enter</command></refname>
<refpurpose>run a command in a NixOS chroot environment</refpurpose>
</refnamediv>

<refsynopsisdiv>
<cmdsynopsis>
<command>nixos-enter</command>
<arg>
<arg choice='plain'><option>--root</option></arg>
<replaceable>root</replaceable>
</arg>
<arg>
<arg choice='plain'><option>--system</option></arg>
<replaceable>system</replaceable>
</arg>
<arg>
<arg choice='plain'><option>-c</option></arg>
<replaceable>shell-command</replaceable>
</arg>
<arg>
<arg choice='plain'><option>--help</option></arg>
</arg>
<arg>
<arg choice='plain'><option>--</option></arg>
<replaceable>arguments</replaceable>
</arg>
</cmdsynopsis>
</refsynopsisdiv>


<refsection><title>Description</title>

<para>This command runs a command in a NixOS chroot environment, that
is, in a filesystem hierarchy previously prepared using
<command>nixos-install</command>.</para>

</refsection>

<refsection><title>Options</title>

<para>This command accepts the following options:</para>

<variablelist>

<varlistentry>
<term><option>--root</option></term>
<listitem>
<para>The path to the NixOS system you want to enter. It defaults to <filename>/mnt</filename>.</para>
</listitem>
</varlistentry>

<varlistentry>
<term><option>--system</option></term>
<listitem>
<para>The NixOS system configuration to use. It defaults to
<filename>/nix/var/nix/profiles/system</filename>. You can enter
a previous NixOS configuration by specifying a path such as
<filename>/nix/var/nix/profiles/system-106-link</filename>.</para>
</listitem>
</varlistentry>

<varlistentry>
<term><option>--command</option></term>
<term><option>-c</option></term>
<listitem>
<para>The bash command to execute.</para>
</listitem>
</varlistentry>

<varlistentry>
<term><option>--</option></term>

<listitem><para>Interpret the remaining arguments as the program
name and arguments to be invoked. The program is not executed in a
shell.</para></listitem>

</varlistentry>

</variablelist>

</refsection>


<refsection><title>Examples</title>

<para>Start an interactive shell in the NixOS installation in
<filename>/mnt</filename>:</para>

<screen>
# nixos-enter /mnt
</screen>

<para>Run a shell command:</para>

<screen>
# nixos-enter -c 'ls -l /; cat /proc/mounts'
</screen>

<para>Run a non-shell command:</para>

<screen>
# nixos-enter -- cat /proc/mounts
</screen>

</refsection>

</refentry>
6 changes: 3 additions & 3 deletions nixos/doc/manual/man-nixos-install.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
<replaceable>root</replaceable>
</arg>
<arg>
<arg choice='plain'><option>--closure</option></arg>
<replaceable>closure</replaceable>
<arg choice='plain'><option>--system</option></arg>
<replaceable>path</replaceable>
</arg>
<arg>
<arg choice='plain'><option>--no-channel-copy</option></arg>
Expand Down Expand Up @@ -118,7 +118,7 @@ it.</para>
</varlistentry>

<varlistentry>
<term><option>--closure</option></term>
<term><option>--system</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>
Expand Down
3 changes: 2 additions & 1 deletion nixos/doc/manual/man-pages.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
</author>

<copyright>
<year>2007-2015</year>
<year>2007-2018</year>
<holder>Eelco Dolstra</holder>
</copyright>

Expand All @@ -25,6 +25,7 @@
<xi:include href="man-nixos-build-vms.xml" />
<xi:include href="man-nixos-generate-config.xml" />
<xi:include href="man-nixos-install.xml" />
<xi:include href="man-nixos-enter.xml" />
<xi:include href="man-nixos-option.xml" />
<xi:include href="man-nixos-rebuild.xml" />
<xi:include href="man-nixos-version.xml" />
Expand Down
7 changes: 7 additions & 0 deletions nixos/doc/manual/release-notes/rl-1803.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@
has the following highlights: </para>

<itemizedlist>
<listitem>
<para>
Nix now defaults to 2.0; see its
<link xlink:href="https://nixos.org/nix/manual/#ssec-relnotes-2.0">release notes</link>.
</para>
</listitem>

<listitem>
<para>
Linux kernel defaults to the 4.14 branch (it was 4.9).
Expand Down
48 changes: 26 additions & 22 deletions nixos/lib/make-disk-image.nix
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ with lib;

let format' = format; in let

format = if (format' == "qcow2-compressed") then "qcow2" else format';
format = if format' == "qcow2-compressed" then "qcow2" else format';

compress = optionalString (format' == "qcow2-compressed") "-c";

Expand Down Expand Up @@ -84,6 +84,7 @@ let format' = format; in let

nixpkgs = cleanSource pkgs.path;

# FIXME: merge with channel.nix / make-channel.nix.
channelSources = pkgs.runCommand "nixos-${config.system.nixos.version}" {} ''
mkdir -p $out
cp -prd ${nixpkgs} $out/nixos
Expand All @@ -95,22 +96,27 @@ let format' = format; in let
echo -n ${config.system.nixos.versionSuffix} > $out/nixos/.version-suffix
'';

metaClosure = pkgs.writeText "meta" ''
${config.system.build.toplevel}
${config.nix.package.out}
${channelSources}
'';

prepareImageInputs = with pkgs; [ rsync utillinux parted e2fsprogs lkl fakeroot config.system.build.nixos-prepare-root ] ++ stdenv.initialPath;
binPath = with pkgs; makeBinPath (
[ rsync
utillinux
parted
e2fsprogs
lkl
config.system.build.nixos-install
config.system.build.nixos-enter
nix
] ++ stdenv.initialPath);

# I'm preserving the line below because I'm going to search for it across nixpkgs to consolidate
# image building logic. The comment right below this now appears in 4 different places in nixpkgs :)
# !!! should use XML.
sources = map (x: x.source) contents;
targets = map (x: x.target) contents;

closureInfo = pkgs.closureInfo { rootPaths = [ config.system.build.toplevel channelSources ]; };

prepareImage = ''
export PATH=${makeBinPath prepareImageInputs}
export PATH=${binPath}

# Yes, mkfs.ext4 takes different units in different contexts. Fun.
sectorsToKilobytes() {
Expand Down Expand Up @@ -168,11 +174,15 @@ let format' = format; in let
fi
done

# TODO: Nix really likes to chown things it creates to its current user...
fakeroot nixos-prepare-root $root ${channelSources} ${config.system.build.toplevel} closure
export HOME=$TMPDIR

# Provide a Nix database so that nixos-install can copy closures.
export NIX_STATE_DIR=$TMPDIR/state
nix-store --load-db < ${closureInfo}/registration

# fakeroot seems to always give the owner write permissions, which we do not want
find $root/nix/store -mindepth 1 -maxdepth 1 -type f -o -type d | xargs chmod -R a-w
echo "running nixos-install..."
nixos-install --root $root --no-bootloader --no-root-passwd \
--system ${config.system.build.toplevel} --channel ${channelSources} --substituters ""

echo "copying staging root to image..."
cptofs -p ${optionalString (partitionTableType != "none") "-P ${rootPartition}"} -t ${fsType} -i $diskImage $root/* /
Expand All @@ -181,7 +191,6 @@ in pkgs.vmTools.runInLinuxVM (
pkgs.runCommand name
{ preVM = prepareImage;
buildInputs = with pkgs; [ utillinux e2fsprogs dosfstools ];
exportReferencesGraph = [ "closure" metaClosure ];
postVM = ''
${if format == "raw" then ''
mv $diskImage $out/${filename}
Expand All @@ -194,6 +203,8 @@ in pkgs.vmTools.runInLinuxVM (
memSize = 1024;
}
''
export PATH=${binPath}:$PATH

rootDisk=${if partitionTableType != "none" then "/dev/vda${rootPartition}" else "/dev/vda"}

# Some tools assume these exist
Expand All @@ -218,15 +229,8 @@ in pkgs.vmTools.runInLinuxVM (
cp ${configFile} /mnt/etc/nixos/configuration.nix
''}

mount --rbind /dev $mountPoint/dev
mount --rbind /proc $mountPoint/proc
mount --rbind /sys $mountPoint/sys

# Set up core system link, GRUB, etc.
NIXOS_INSTALL_BOOTLOADER=1 chroot $mountPoint /nix/var/nix/profiles/system/bin/switch-to-configuration boot

# TODO: figure out if I should activate, but for now I won't
# chroot $mountPoint /nix/var/nix/profiles/system/activate
NIXOS_INSTALL_BOOTLOADER=1 nixos-enter --root $mountPoint -- /nix/var/nix/profiles/system/bin/switch-to-configuration boot

# The above scripts will generate a random machine-id and we don't want to bake a single ID into all our images
rm -f $mountPoint/etc/machine-id
Expand Down
9 changes: 4 additions & 5 deletions nixos/lib/make-iso9660-image.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ stdenv, perl, pathsFromGraph, xorriso, syslinux
{ stdenv, perl, closureInfo, xorriso, syslinux

, # The file name of the resulting ISO image.
isoName ? "cd.iso"
Expand Down Expand Up @@ -48,9 +48,9 @@ assert usbBootable -> isohybridMbrImage != "";
stdenv.mkDerivation {
name = isoName;
builder = ./make-iso9660-image.sh;
buildInputs = [perl xorriso syslinux];
buildInputs = [ xorriso syslinux ];

inherit isoName bootable bootImage compressImage volumeID pathsFromGraph efiBootImage efiBootable isohybridMbrImage usbBootable;
inherit isoName bootable bootImage compressImage volumeID efiBootImage efiBootable isohybridMbrImage usbBootable;

# !!! should use XML.
sources = map (x: x.source) contents;
Expand All @@ -61,6 +61,5 @@ stdenv.mkDerivation {
symlinks = map (x: x.symlink) storeContents;

# For obtaining the closure of `storeContents'.
exportReferencesGraph =
map (x: [("closure-" + baseNameOf x.object) x.object]) storeContents;
closureInfo = closureInfo { rootPaths = map (x: x.object) storeContents; };
}
7 changes: 3 additions & 4 deletions nixos/lib/make-iso9660-image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,15 @@ done


# Add the closures of the top-level store objects.
storePaths=$(perl $pathsFromGraph closure-*)
for i in $storePaths; do
for i in $(< $closureInfo/store-paths); do
addPath "${i:1}" "$i"
done


# Also include a manifest of the closures in a format suitable for
# nix-store --load-db.
if [ -n "$object" ]; then
printRegistration=1 perl $pathsFromGraph closure-* > nix-path-registration
if [[ ${#objects[*]} != 0 ]]; then
cp $closureInfo/registration nix-path-registration
addPath "nix-path-registration" "nix-path-registration"
fi

Expand Down
Loading