diff options
Diffstat (limited to 'nixos')
-rw-r--r-- | nixos/doc/manual/man-nixos-rebuild.xml | 8 | ||||
-rw-r--r-- | nixos/lib/test-driver/test_driver/driver.py | 2 | ||||
-rw-r--r-- | nixos/lib/test-driver/test_driver/logger.py | 8 | ||||
-rwxr-xr-x | nixos/modules/system/activation/switch-to-configuration.pl | 12 | ||||
-rw-r--r-- | nixos/modules/system/activation/top-level.nix | 5 | ||||
-rw-r--r-- | nixos/modules/system/boot/systemd/initrd.nix | 3 | ||||
-rw-r--r-- | nixos/modules/tasks/lvm.nix | 33 | ||||
-rw-r--r-- | nixos/tests/all-tests.nix | 3 | ||||
-rw-r--r-- | nixos/tests/hibernate.nix | 6 | ||||
-rw-r--r-- | nixos/tests/lvm2/default.nix | 20 | ||||
-rw-r--r-- | nixos/tests/lvm2/systemd-stage-1.nix | 104 | ||||
-rw-r--r-- | nixos/tests/mongodb.nix | 4 |
12 files changed, 196 insertions, 12 deletions
diff --git a/nixos/doc/manual/man-nixos-rebuild.xml b/nixos/doc/manual/man-nixos-rebuild.xml index b2ca9f457a2b8..ea96f49fa9772 100644 --- a/nixos/doc/manual/man-nixos-rebuild.xml +++ b/nixos/doc/manual/man-nixos-rebuild.xml @@ -548,6 +548,14 @@ (<replaceable>user@host</replaceable>). You can also set ssh options by defining the <envar>NIX_SSHOPTS</envar> environment variable. </para> + + <para> + Note that <command>nixos-rebuild</command> honors the + <literal>nixpkgs.crossSystem</literal> setting of the given configuration + but disregards the true architecture of the target host. Hence the + <literal>nixpkgs.crossSystem</literal> setting has to match the target + platform or else activation will fail. + </para> </listitem> </varlistentry> diff --git a/nixos/lib/test-driver/test_driver/driver.py b/nixos/lib/test-driver/test_driver/driver.py index 0e5f013193fef..e32f6810ca87f 100644 --- a/nixos/lib/test-driver/test_driver/driver.py +++ b/nixos/lib/test-driver/test_driver/driver.py @@ -86,7 +86,7 @@ class Driver: def subtest(self, name: str) -> Iterator[None]: """Group logs under a given test name""" - with rootlog.nested(name): + with rootlog.nested("subtest: " + name): try: yield return True diff --git a/nixos/lib/test-driver/test_driver/logger.py b/nixos/lib/test-driver/test_driver/logger.py index 5b3091a5129c3..59ed295472315 100644 --- a/nixos/lib/test-driver/test_driver/logger.py +++ b/nixos/lib/test-driver/test_driver/logger.py @@ -1,4 +1,4 @@ -from colorama import Style +from colorama import Style, Fore from contextlib import contextmanager from typing import Any, Dict, Iterator from queue import Queue, Empty @@ -81,7 +81,11 @@ class Logger: @contextmanager def nested(self, message: str, attributes: Dict[str, str] = {}) -> Iterator[None]: - self._eprint(self.maybe_prefix(message, attributes)) + self._eprint( + self.maybe_prefix( + Style.BRIGHT + Fore.GREEN + message + Style.RESET_ALL, attributes + ) + ) self.xml.startElement("nest", attrs={}) self.xml.startElement("head", attributes) diff --git a/nixos/modules/system/activation/switch-to-configuration.pl b/nixos/modules/system/activation/switch-to-configuration.pl index 9e5b760434a05..3f0d976e70b88 100755 --- a/nixos/modules/system/activation/switch-to-configuration.pl +++ b/nixos/modules/system/activation/switch-to-configuration.pl @@ -1,5 +1,17 @@ #! @perl@/bin/perl +# Issue #166838 uncovered a situation in which a configuration not suitable +# for the target architecture caused a cryptic error message instead of +# a clean failure. Due to this mismatch, the perl interpreter in the shebang +# line wasn't able to be executed, causing this script to be misinterpreted +# as a shell script. +# +# Let's detect this situation to give a more meaningful error +# message. The following two lines are carefully written to be both valid Perl +# and Bash. +printf "Perl script erroneously interpreted as shell script,\ndoes target platform match nixpkgs.crossSystem platform?\n" && exit 1 + if 0; + use strict; use warnings; use Config::IniFiles; diff --git a/nixos/modules/system/activation/top-level.nix b/nixos/modules/system/activation/top-level.nix index df8db7f34d0d6..f016fff824c43 100644 --- a/nixos/modules/system/activation/top-level.nix +++ b/nixos/modules/system/activation/top-level.nix @@ -59,7 +59,10 @@ let ${if config.boot.initrd.systemd.enable then '' cp ${config.system.build.bootStage2} $out/prepare-root substituteInPlace $out/prepare-root --subst-var-by systemConfig $out - ln -s "$systemd/lib/systemd/systemd" $out/init + # This must not be a symlink or the abs_path of the grub builder for the tests + # will resolve the symlink and we end up with a path that doesn't point to a + # system closure. + cp "$systemd/lib/systemd/systemd" $out/init '' else '' cp ${config.system.build.bootStage2} $out/init substituteInPlace $out/init --subst-var-by systemConfig $out diff --git a/nixos/modules/system/boot/systemd/initrd.nix b/nixos/modules/system/boot/systemd/initrd.nix index 3af124d06a9d9..c900348619c0d 100644 --- a/nixos/modules/system/boot/systemd/initrd.nix +++ b/nixos/modules/system/boot/systemd/initrd.nix @@ -503,5 +503,8 @@ in { ]; }; }; + + boot.kernelParams = lib.mkIf (config.boot.resumeDevice != "") [ "resume=${config.boot.resumeDevice}" ]; + }; } diff --git a/nixos/modules/tasks/lvm.nix b/nixos/modules/tasks/lvm.nix index 59711f90dce3d..4108b482cce51 100644 --- a/nixos/modules/tasks/lvm.nix +++ b/nixos/modules/tasks/lvm.nix @@ -21,6 +21,10 @@ in { boot.vdo.enable = mkEnableOption "support for booting from VDOLVs"; }; + options.boot.initrd.services.lvm.enable = (mkEnableOption "enable booting from LVM2 in the initrd") // { + visible = false; + }; + config = mkMerge [ ({ # minimal configuration file to make lvmconfig/lvm2-activation-generator happy @@ -31,8 +35,13 @@ in { environment.systemPackages = [ cfg.package ]; systemd.packages = [ cfg.package ]; - # TODO: update once https://github.com/NixOS/nixpkgs/pull/93006 was merged services.udev.packages = [ cfg.package.out ]; + + # We need lvm2 for the device-mapper rules + boot.initrd.services.udev.packages = lib.mkIf config.boot.initrd.services.lvm.enable [ cfg.package ]; + # The device-mapper rules want to call tools from lvm2 + boot.initrd.systemd.initrdBin = lib.mkIf config.boot.initrd.services.lvm.enable [ cfg.package ]; + boot.initrd.services.udev.binPackages = lib.mkIf config.boot.initrd.services.lvm.enable [ cfg.package ]; }) (mkIf cfg.dmeventd.enable { systemd.sockets."dm-event".wantedBy = [ "sockets.target" ]; @@ -47,13 +56,15 @@ in { boot.initrd = { kernelModules = [ "dm-snapshot" "dm-thin-pool" ]; - extraUtilsCommands = '' + systemd.initrdBin = lib.mkIf config.boot.initrd.services.lvm.enable [ pkgs.thin-provisioning-tools ]; + + extraUtilsCommands = mkIf (!config.boot.initrd.systemd.enable) '' for BIN in ${pkgs.thin-provisioning-tools}/bin/*; do copy_bin_and_libs $BIN done ''; - extraUtilsCommandsTest = '' + extraUtilsCommandsTest = mkIf (!config.boot.initrd.systemd.enable) '' ls ${pkgs.thin-provisioning-tools}/bin/ | grep -v pdata_tools | while read BIN; do $out/bin/$(basename $BIN) --help > /dev/null done @@ -71,13 +82,15 @@ in { initrd = { kernelModules = [ "kvdo" ]; - extraUtilsCommands = '' + systemd.initrdBin = lib.mkIf config.boot.initrd.services.lvm.enable [ pkgs.vdo ]; + + extraUtilsCommands = mkIf (!config.boot.initrd.systemd.enable)'' ls ${pkgs.vdo}/bin/ | grep -v adaptLVMVDO | while read BIN; do copy_bin_and_libs ${pkgs.vdo}/bin/$BIN done ''; - extraUtilsCommandsTest = '' + extraUtilsCommandsTest = mkIf (!config.boot.initrd.systemd.enable)'' ls ${pkgs.vdo}/bin/ | grep -v adaptLVMVDO | while read BIN; do $out/bin/$(basename $BIN) --help > /dev/null done @@ -91,7 +104,15 @@ in { environment.systemPackages = [ pkgs.vdo ]; }) (mkIf (cfg.dmeventd.enable || cfg.boot.thin.enable) { - boot.initrd.preLVMCommands = '' + boot.initrd.systemd.contents."/etc/lvm/lvm.conf".text = optionalString (config.boot.initrd.services.lvm.enable && cfg.boot.thin.enable) (concatMapStringsSep "\n" + (bin: "global/${bin}_executable = /bin/${bin}") + [ "thin_check" "thin_dump" "thin_repair" "cache_check" "cache_dump" "cache_repair" ] + ) + "\n" + optionalString cfg.dmeventd.enable '' + dmeventd/executable = /bin/false + activation/monitoring = 0 + ''; + + boot.initrd.preLVMCommands = mkIf (!config.boot.initrd.systemd.enable) '' mkdir -p /etc/lvm cat << EOF >> /etc/lvm/lvm.conf ${optionalString cfg.boot.thin.enable ( diff --git a/nixos/tests/all-tests.nix b/nixos/tests/all-tests.nix index a1d4e2846570c..a229fa65faf6e 100644 --- a/nixos/tests/all-tests.nix +++ b/nixos/tests/all-tests.nix @@ -208,6 +208,7 @@ in # hibernation. This test happens to work on x86_64-linux but # not on other platforms. hibernate = handleTestOn ["x86_64-linux"] ./hibernate.nix {}; + hibernate-systemd-stage-1 = handleTestOn ["x86_64-linux"] ./hibernate.nix { systemdStage1 = true; }; hitch = handleTest ./hitch {}; hledger-web = handleTest ./hledger-web.nix {}; hocker-fetchdocker = handleTest ./hocker-fetchdocker {}; @@ -365,7 +366,7 @@ in nginx-variants = handleTest ./nginx-variants.nix {}; nifi = handleTestOn ["x86_64-linux"] ./web-apps/nifi.nix {}; nitter = handleTest ./nitter.nix {}; - nix-ld = handleTest ./nix-ld {}; + nix-ld = handleTest ./nix-ld.nix {}; nix-serve = handleTest ./nix-serve.nix {}; nix-serve-ssh = handleTest ./nix-serve-ssh.nix {}; nixops = handleTest ./nixops/default.nix {}; diff --git a/nixos/tests/hibernate.nix b/nixos/tests/hibernate.nix index 032ac6527bc71..7a4b331169a39 100644 --- a/nixos/tests/hibernate.nix +++ b/nixos/tests/hibernate.nix @@ -3,6 +3,7 @@ { system ? builtins.currentSystem , config ? {} , pkgs ? import ../.. { inherit system config; } +, systemdStage1 ? false }: with import ../lib/testing-python.nix { inherit system pkgs; }; @@ -29,6 +30,11 @@ let "/".device = "/dev/vda2"; }; swapDevices = mkOverride 0 [ { device = "/dev/vda1"; } ]; + boot.resumeDevice = mkIf systemdStage1 "/dev/vda1"; + boot.initrd.systemd = mkIf systemdStage1 { + enable = true; + emergencyAccess = true; + }; }; installedSystem = (import ../lib/eval-config.nix { inherit system; diff --git a/nixos/tests/lvm2/default.nix b/nixos/tests/lvm2/default.nix index 2ba17809569a6..1eb9f572a4d6d 100644 --- a/nixos/tests/lvm2/default.nix +++ b/nixos/tests/lvm2/default.nix @@ -11,6 +11,24 @@ let thinpool = { test = callTest ./thinpool.nix; kernelFilter = lib.id; }; # we would like to test all versions, but the kernel module currently does not compile against the other versions vdo = { test = callTest ./vdo.nix; kernelFilter = lib.filter (v: v == "5.15"); }; + + + # systemd in stage 1 + raid-sd-stage-1 = { + test = callTest ./systemd-stage-1.nix; + kernelFilter = lib.id; + flavour = "raid"; + }; + thinpool-sd-stage-1 = { + test = callTest ./systemd-stage-1.nix; + kernelFilter = lib.id; + flavour = "thinpool"; + }; + vdo-sd-stage-1 = { + test = callTest ./systemd-stage-1.nix; + kernelFilter = lib.filter (v: v == "5.15"); + flavour = "vdo"; + }; }; in lib.listToAttrs ( @@ -20,7 +38,7 @@ lib.listToAttrs ( v' = lib.replaceStrings [ "." ] [ "_" ] version; in lib.flip lib.mapAttrsToList tests (name: t: - lib.nameValuePair "lvm-${name}-linux-${v'}" (lib.optionalAttrs (builtins.elem version (t.kernelFilter kernelVersionsToTest)) (t.test { kernelPackages = pkgs."linuxPackages_${v'}"; })) + lib.nameValuePair "lvm-${name}-linux-${v'}" (lib.optionalAttrs (builtins.elem version (t.kernelFilter kernelVersionsToTest)) (t.test ({ kernelPackages = pkgs."linuxPackages_${v'}"; } // builtins.removeAttrs t [ "test" "kernelFilter" ]))) ) ) ) diff --git a/nixos/tests/lvm2/systemd-stage-1.nix b/nixos/tests/lvm2/systemd-stage-1.nix new file mode 100644 index 0000000000000..617ba77b1796c --- /dev/null +++ b/nixos/tests/lvm2/systemd-stage-1.nix @@ -0,0 +1,104 @@ +{ kernelPackages ? null, flavour }: let + preparationCode = { + raid = '' + machine.succeed("vgcreate test_vg /dev/vdc /dev/vdd") + machine.succeed("lvcreate -L 512M --type raid0 test_vg -n test_lv") + ''; + + thinpool = '' + machine.succeed("vgcreate test_vg /dev/vdc") + machine.succeed("lvcreate -L 512M -T test_vg/test_thin_pool") + machine.succeed("lvcreate -n test_lv -V 16G --thinpool test_thin_pool test_vg") + ''; + + vdo = '' + machine.succeed("vgcreate test_vg /dev/vdc") + machine.succeed("lvcreate --type vdo -n test_lv -L 6G -V 12G test_vg/vdo_pool_lv") + ''; + }.${flavour}; + + extraConfig = { + raid = { + boot.initrd.kernelModules = [ + "dm-raid" + "raid0" + ]; + }; + + thinpool = { + services.lvm = { + boot.thin.enable = true; + dmeventd.enable = true; + }; + }; + + vdo = { + services.lvm = { + boot.vdo.enable = true; + dmeventd.enable = true; + }; + }; + }.${flavour}; + + extraCheck = { + raid = '' + "test_lv" in machine.succeed("lvs --select segtype=raid0") + ''; + + thinpool = '' + "test_lv" in machine.succeed("lvs --select segtype=thin-pool") + ''; + + vdo = '' + "test_lv" in machine.succeed("lvs --select segtype=vdo") + ''; + }.${flavour}; + +in import ../make-test-python.nix ({ pkgs, ... }: { + name = "lvm2-${flavour}-systemd-stage-1"; + meta.maintainers = with pkgs.lib.maintainers; [ das_j ]; + + nodes.machine = { pkgs, lib, ... }: { + imports = [ extraConfig ]; + # Use systemd-boot + virtualisation = { + emptyDiskImages = [ 8192 8192 ]; + useBootLoader = true; + useEFIBoot = true; + }; + boot.loader.systemd-boot.enable = true; + boot.loader.efi.canTouchEfiVariables = true; + + environment.systemPackages = with pkgs; [ e2fsprogs ]; # for mkfs.ext4 + boot = { + initrd.systemd = { + enable = true; + emergencyAccess = true; + }; + initrd.services.lvm.enable = true; + kernelPackages = lib.mkIf (kernelPackages != null) kernelPackages; + }; + + specialisation.boot-lvm.configuration.virtualisation.bootDevice = "/dev/test_vg/test_lv"; + }; + + testScript = '' + machine.wait_for_unit("multi-user.target") + # Create a VG for the root + ${preparationCode} + machine.succeed("mkfs.ext4 /dev/test_vg/test_lv") + machine.succeed("mkdir -p /mnt && mount /dev/test_vg/test_lv /mnt && echo hello > /mnt/test && umount /mnt") + + # Boot from LVM + machine.succeed("bootctl set-default nixos-generation-1-specialisation-boot-lvm.conf") + machine.succeed("sync") + machine.crash() + machine.wait_for_unit("multi-user.target") + + # Ensure we have successfully booted from LVM + assert "(initrd)" in machine.succeed("systemd-analyze") # booted with systemd in stage 1 + assert "/dev/mapper/test_vg-test_lv on / type ext4" in machine.succeed("mount") + assert "hello" in machine.succeed("cat /test") + ${extraCheck} + ''; +}) diff --git a/nixos/tests/mongodb.nix b/nixos/tests/mongodb.nix index 9c6fdfb1ca76e..edd074f5163c2 100644 --- a/nixos/tests/mongodb.nix +++ b/nixos/tests/mongodb.nix @@ -37,6 +37,8 @@ import ./make-test-python.nix ({ pkgs, ... }: mongodb-3_6 mongodb-4_0 mongodb-4_2 + mongodb-4_4 + mongodb-5_0 ]; }; }; @@ -48,6 +50,8 @@ import ./make-test-python.nix ({ pkgs, ... }: + runMongoDBTest pkgs.mongodb-3_6 + runMongoDBTest pkgs.mongodb-4_0 + runMongoDBTest pkgs.mongodb-4_2 + + runMongoDBTest pkgs.mongodb-4_4 + + runMongoDBTest pkgs.mongodb-5_0 + '' node.shutdown() ''; |