!PSmBFWNKoXmlQBzUQf:helsinki-systems.de

Stage 1 systemd

82 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
@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
@janne.hess:helsinki-systems.de@janne.hess:helsinki-systems.de
In reply to @elvishjerricco:matrix.org
we're using systemdMinimal... which has a different path
That doesn't matter. If you're looking at the switch-root.c code, it compares the canonical path of the new systemd not to the path of the current systemd but rather to a constant that we set during compilation
09:31:20
@janne.hess:helsinki-systems.de@janne.hess:helsinki-systems.deThis: https://github.com/NixOS/nixpkgs/blob/master/pkgs/os-specific/linux/systemd/default.nix#L56410:08:45
@janne.hess:helsinki-systems.de@janne.hess:helsinki-systems.de bobvanderlinden: if you fix the one spelling thing in your PR, I'll merge it 10:16:04
@elvishjerricco:matrix.org@elvishjerricco:matrix.orgOh. I very much misunderstood some stuff then :P Nice!10:40:37
@janne.hess:helsinki-systems.de@janne.hess:helsinki-systems.debut you may be right that symlinks should work10:41:04

There are no newer messages yet.


Back to Room ListRoom Version: 6