From 9b31147be92551e14c3b906f45096d6c7961e6ff Mon Sep 17 00:00:00 2001 From: Lily Foster Date: Wed, 8 Feb 2023 15:24:10 -0500 Subject: [PATCH 1/4] nixos/tests/systemd-initrd-vconsole: init new test for console.earlySetup --- nixos/tests/all-tests.nix | 1 + nixos/tests/systemd-initrd-vconsole.nix | 33 +++++++++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 nixos/tests/systemd-initrd-vconsole.nix diff --git a/nixos/tests/all-tests.nix b/nixos/tests/all-tests.nix index d8eb00d54537..73d54aaf6f40 100644 --- a/nixos/tests/all-tests.nix +++ b/nixos/tests/all-tests.nix @@ -655,6 +655,7 @@ in { systemd-initrd-shutdown = handleTest ./systemd-shutdown.nix { systemdStage1 = true; }; systemd-initrd-simple = handleTest ./systemd-initrd-simple.nix {}; systemd-initrd-swraid = handleTest ./systemd-initrd-swraid.nix {}; + systemd-initrd-vconsole = handleTest ./systemd-initrd-vconsole.nix {}; systemd-journal = handleTest ./systemd-journal.nix {}; systemd-machinectl = handleTest ./systemd-machinectl.nix {}; systemd-networkd = handleTest ./systemd-networkd.nix {}; diff --git a/nixos/tests/systemd-initrd-vconsole.nix b/nixos/tests/systemd-initrd-vconsole.nix new file mode 100644 index 000000000000..b74df410c422 --- /dev/null +++ b/nixos/tests/systemd-initrd-vconsole.nix @@ -0,0 +1,33 @@ +import ./make-test-python.nix ({ lib, pkgs, ... }: { + name = "systemd-initrd-vconsole"; + + nodes.machine = { pkgs, ... }: { + boot.kernelParams = [ "rd.systemd.unit=rescue.target" ]; + + boot.initrd.systemd = { + enable = true; + emergencyAccess = true; + }; + + console = { + earlySetup = true; + keyMap = "colemak"; + }; + }; + + testScript = '' + # Boot into rescue shell in initrd + machine.start() + machine.wait_for_console_text("Press Enter for maintenance") + machine.send_console("\n") + machine.wait_for_console_text("Logging in with home") + + # Check keymap + machine.send_console("(printf '%s to receive text: \\n' Ready && read text && echo \"$text\") Date: Mon, 20 Feb 2023 07:02:55 -0500 Subject: [PATCH 2/4] make-initrd-ng: support wrapped executables --- .../kernel/make-initrd-ng/src/main.rs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/pkgs/build-support/kernel/make-initrd-ng/src/main.rs b/pkgs/build-support/kernel/make-initrd-ng/src/main.rs index 89a7c08fda7e..c23713b723c3 100644 --- a/pkgs/build-support/kernel/make-initrd-ng/src/main.rs +++ b/pkgs/build-support/kernel/make-initrd-ng/src/main.rs @@ -1,8 +1,9 @@ use std::collections::{HashSet, VecDeque}; use std::env; -use std::ffi::OsStr; +use std::ffi::{OsStr, OsString}; use std::fs; use std::hash::Hash; +use std::iter::FromIterator; use std::io::{BufRead, BufReader, Error}; use std::os::unix; use std::path::{Component, Path, PathBuf}; @@ -163,6 +164,19 @@ fn handle_path( let typ = fs::symlink_metadata(&source)?.file_type(); if typ.is_file() && !target.exists() { copy_file(&source, &target, queue)?; + + if let Some(filename) = source.file_name() { + source.set_file_name(OsString::from_iter([ + OsStr::new("."), + filename, + OsStr::new("-wrapped"), + ])); + + let wrapped_path = source.as_path(); + if wrapped_path.exists() { + queue.push_back(Box::from(wrapped_path)); + } + } } else if typ.is_symlink() { let link_target = fs::read_link(&source)?; From d01bc6f9cb7b0b1851fdd80ab45eaccc07e9730d Mon Sep 17 00:00:00 2001 From: Lily Foster Date: Mon, 20 Feb 2023 07:02:55 -0500 Subject: [PATCH 3/4] make-initrd-ng: document wrapped file behavior --- pkgs/build-support/kernel/make-initrd-ng/README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pkgs/build-support/kernel/make-initrd-ng/README.md b/pkgs/build-support/kernel/make-initrd-ng/README.md index 741eba67e43f..d92b7eab7fe1 100644 --- a/pkgs/build-support/kernel/make-initrd-ng/README.md +++ b/pkgs/build-support/kernel/make-initrd-ng/README.md @@ -38,6 +38,9 @@ object is copied depends on its type. - If it is *also* an ELF file, then all of its direct shared library dependencies are also listed as objects to be copied. + - If an unwrapped file exists as `.[filename]-wrapped`, then it is + also listed as an object to be copied. + 2. A directory's direct children are listed as objects to be copied, and a directory at the same absolute path in the initrd is created. From 1fa1b58c2521cc8aa2e4eca41e1422df4724e199 Mon Sep 17 00:00:00 2001 From: Lily Foster Date: Mon, 20 Feb 2023 07:02:55 -0500 Subject: [PATCH 4/4] nixos/console,nixos/systemd-initrd: remove now-unnecessary wrapped bin inclusions --- nixos/modules/config/console.nix | 1 - nixos/modules/system/boot/systemd/initrd.nix | 3 --- 2 files changed, 4 deletions(-) diff --git a/nixos/modules/config/console.nix b/nixos/modules/config/console.nix index 854d7acf9232..f5db5dc5dfc1 100644 --- a/nixos/modules/config/console.nix +++ b/nixos/modules/config/console.nix @@ -168,7 +168,6 @@ in "${config.boot.initrd.systemd.package.kbd}/bin/setfont" "${config.boot.initrd.systemd.package.kbd}/bin/loadkeys" "${config.boot.initrd.systemd.package.kbd.gzip}/bin/gzip" # Fonts and keyboard layouts are compressed - "${config.boot.initrd.systemd.package.kbd.gzip}/bin/.gzip-wrapped" ] ++ optionals (hasPrefix builtins.storeDir cfg.font) [ "${cfg.font}" ] ++ optionals (hasPrefix builtins.storeDir cfg.keyMap) [ diff --git a/nixos/modules/system/boot/systemd/initrd.nix b/nixos/modules/system/boot/systemd/initrd.nix index 620d76aef20d..08b90efe140d 100644 --- a/nixos/modules/system/boot/systemd/initrd.nix +++ b/nixos/modules/system/boot/systemd/initrd.nix @@ -427,9 +427,6 @@ in { # fido2 support "${cfg.package}/lib/cryptsetup/libcryptsetup-token-systemd-fido2.so" "${pkgs.libfido2}/lib/libfido2.so.1" - - # the unwrapped systemd-cryptsetup executable - "${cfg.package}/lib/systemd/.systemd-cryptsetup-wrapped" ] ++ jobScripts; targets.initrd.aliases = ["default.target"];