!PSmBFWNKoXmlQBzUQf:helsinki-systems.de

Stage 1 systemd

83 Members
systemd in NixOs's stage 1, replacing the current bash tooling https://github.com/NixOS/nixpkgs/projects/5126 Servers

Load older messages


SenderMessageTime
20 Mar 2022
@janne.hess:helsinki-systems.de@janne.hess:helsinki-systems.dethe modification that broke it was my Environment= stuff20:19:41
@elvishjerricco:matrix.org@elvishjerricco:matrix.orgSystemd needs to find mke2fs on PATH20:20:20
@elvishjerricco:matrix.org@elvishjerricco:matrix.orgDoes setting Environment= override PATH even if you don't use it to set PATH?20:22:04
@elvishjerricco:matrix.org@elvishjerricco:matrix.orgEr, no, emergency.service uses it to set HOME=/root, and that doesn't break PATH in my emergency shell20:22:27
@janne.hess:helsinki-systems.de@janne.hess:helsinki-systems.de ah yeah for some reason it sets PATH=:. I'll take a look at this later because it turns out the argument passing doesn't work :/ 20:24:33
@elvishjerricco:matrix.org@elvishjerricco:matrix.orgOh20:24:42
@elvishjerricco:matrix.org@elvishjerricco:matrix.orgI bet I know what's up with that20:24:47
@elvishjerricco:matrix.org@elvishjerricco:matrix.org The code that converts services.foo.path to services.foo.environment.PATH 20:25:16
@elvishjerricco:matrix.org@elvishjerricco:matrix.orgIt's not conditional, so it'll always set it to empty20:25:29
@elvishjerricco:matrix.org@elvishjerricco:matrix.org (and apparently incorrectly, as it does : :P) 20:25:42
@janne.hess:helsinki-systems.de@janne.hess:helsinki-systems.deah because there is a default path in stage 2?20:25:47
@elvishjerricco:matrix.org@elvishjerricco:matrix.orgright20:25:54
@elvishjerricco:matrix.org@elvishjerricco:matrix.orgYea so that's a bug20:26:05
@elvishjerricco:matrix.org@elvishjerricco:matrix.org So we probably want to add the paths from DefaultEnvironment to the path -> PATH conversion 20:28:09
@elvishjerricco:matrix.org@elvishjerricco:matrix.org

Or, hah, this probably works:

diff --git a/nixos/lib/systemd-lib.nix b/nixos/lib/systemd-lib.nix
index 3129fbe7bdb..4ee40f2fa08 100644
--- a/nixos/lib/systemd-lib.nix
+++ b/nixos/lib/systemd-lib.nix
@@ -332,7 +332,7 @@ in rec {
     systemd
   ];
 
-  initrdServiceConfig = mkServiceConfig [];
+  initrdServiceConfig = mkServiceConfig ["/"];
 
   mountConfig = { config, ... }: {
     config = {
20:29:27
@elvishjerricco:matrix.org@elvishjerricco:matrix.orghighly jank20:29:39
@janne.hess:helsinki-systems.de@janne.hess:helsinki-systems.deoof20:30:05
@elvishjerricco:matrix.org@elvishjerricco:matrix.orgI'm going to take off again for a while. Let me know if you figure anything out20:30:39
@janne.hess:helsinki-systems.de@janne.hess:helsinki-systems.de

okay so about the PATH stuff: I came up with this:

diff --git a/nixos/lib/systemd-lib.nix b/nixos/lib/systemd-lib.nix
index 3129fbe7bdb..7850d5f4524 100644
--- a/nixos/lib/systemd-lib.nix
+++ b/nixos/lib/systemd-lib.nix
@@ -396,6 +396,12 @@ in rec {
       text = commonUnitText def +
         ''
           [Service]
+          ${concatMapStrings (n:
+              let s = optionalString (def.environment.${n} != null && n == "PATH" -> def.environment.${n} != ":")
+                (lib.traceValSeq "Environment=${builtins.toJSON "${n}=${def.environment.${n}}"}\n");
+              # systemd max line length is now 1MiB
+              # https://github.com/systemd/systemd/commit/e6dde451a51dc5aaa7f4d98d39b8fe735f73d2af
+              in if stringLength s >= 1048576 then throw "The value of the environment variable ‘${n}’ in systemd service ‘${name}.service’ is too long." else s) (attrNames def.environment)}
           ${attrsToSection def.serviceConfig}
         '';
     };
23:17:31
@janne.hess:helsinki-systems.de@janne.hess:helsinki-systems.deabout the serialization stuff: I spent some hours patching systemd and it works in theory now. This does however not work when we run stage-2-init.sh in between the systemd executions because there is a short time where the shell script is running and no systemd which causes systemd to miss signals, causing it to hang forever in bootup (sounds strange but makes sense when going into details I'm too tired to write down)23:19:11
@janne.hess:helsinki-systems.de@janne.hess:helsinki-systems.de There's also a way to get around patching systemd entirely. initrd-switch-root.service calls ExecStart=systemctl --no-block switch-root /sysroot. If the second argument to systemctl is /run/current-system/systemd/lib/systemd/systemd (EXACTLY that string) or if init=/run/current-system/systemd/lib/systemd/systemd is set on the cmdline (EXACTLY that string), then the handover between the systemds works 23:21:03
@janne.hess:helsinki-systems.de@janne.hess:helsinki-systems.de * There's also a way to get around patching systemd entirely. initrd-switch-root.service calls ExecStart=systemctl --no-block switch-root /sysroot. If adding an argument to systemctl that is /run/current-system/systemd/lib/systemd/systemd (EXACTLY that string) or if init=/run/current-system/systemd/lib/systemd/systemd is set on the cmdline (EXACTLY that string), then the handover between the systemds works 23:21:20
21 Mar 2022
@elvishjerricco:matrix.org@elvishjerricco:matrix.org Janne Heß: Wouldn't it be better to simply not set environment.PATH when path == []? Like environment.PATH = mkIf (path != []) ... 00:58:19
@elvishjerricco:matrix.org@elvishjerricco:matrix.org

Yea I think this'll work:

$ git diff
diff --git a/nixos/lib/systemd-lib.nix b/nixos/lib/systemd-lib.nix
index 3129fbe7bdb..9c240f83c38 100644
--- a/nixos/lib/systemd-lib.nix
+++ b/nixos/lib/systemd-lib.nix
@@ -295,7 +295,7 @@ in rec {
     config = mkMerge
       [ { # Default path for systemd services.  Should be quite minimal.
           path = mkAfter path;
-          environment.PATH = "${makeBinPath config.path}:${makeSearchPathOutput "bin" "sbin" config.path}";
+          environment.PATH = mkIf (config.path != []) "${makeBinPath config.path}:${makeSearchPathOutput "bin" "sbin" config.path}";
         }
         (mkIf (config.preStart != "")
           { serviceConfig.ExecStartPre =

$ nix eval -f test.nix config.boot.initrd.systemd.services.foo.environment
{ }
01:00:59
@elvishjerricco:matrix.org@elvishjerricco:matrix.org Janne Heß: I've pushed something that should work. Let me know if it solves your issue 01:05:41
@elvishjerricco:matrix.org@elvishjerricco:matrix.org As for the serialization stuff, yea I think we're just going to have to switch-root to the systemd binary. And FWIW, it doesn't have to be exactly /run/current-system/systemd/lib/systemd/systemd; it has to have a canonical path that's exactly ${systemd}/lib/systemd/systemd. 01:31:49
@elvishjerricco:matrix.org@elvishjerricco:matrix.orgoh but that's going to be a problem01:32:58
@elvishjerricco:matrix.org@elvishjerricco:matrix.orgwe're using systemdMinimal... which has a different path01:33:07
@elvishjerricco:matrix.org@elvishjerricco:matrix.orgdrat01:33:13
@elvishjerricco:matrix.org@elvishjerricco:matrix.orgAnd using regular systemd instead increases the initrd size by more than double01:35:24

Show newer messages


Back to Room ListRoom Version: 6