!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/5127 Servers

Load older messages


SenderMessageTime
9 Apr 2022
@janne.hess:helsinki-systems.de@janne.hess:helsinki-systems.dehttps://nixos.org/manual/nixos/unstable/index.html#sec-switching-systems13:17:32
@janne.hess:helsinki-systems.de@janne.hess:helsinki-systems.dehere we go upstreaming my garbage: https://github.com/systemd/systemd/pull/2303315:44:59
@janne.hess:helsinki-systems.de@janne.hess:helsinki-systems.de Arian ElvishJerricco : nailed it: https://github.com/NixOS/nixpkgs/pull/167168 16:11:30
@janne.hess:helsinki-systems.de@janne.hess:helsinki-systems.dethis is one commit of fixups, one commit where I use my ugly hack and one where I replace that ugly hack with a systemd patch. My idea is to pop the third commit into a separate PR that goes to staging and have the other two commits go directly to master. This way we get the new functionality without having to wait for staging. They are currently in one PR so you can see the combined diff more easily16:12:32
@elvishjerricco:matrix.org@elvishjerricco:matrix.org Janne Heß: I still don't understand why we need the systemd patch. Why can't we run nixos activation and then leave /sysroot/run mounted, preventing systemd from trying to do it? 23:36:36
10 Apr 2022
@elvishjerricco:matrix.org@elvishjerricco:matrix.orgWell I tried it and it failed spectacularly :P Not sure why01:01:16
@elvishjerricco:matrix.org@elvishjerricco:matrix.org

Janne Heß: This works for me:

diff --git a/nixos/modules/system/boot/systemd/initrd.nix b/nixos/modules/system/boot/systemd/initrd.nix
index 59dd508932f..6a9b8f90926 100644
--- a/nixos/modules/system/boot/systemd/initrd.nix
+++ b/nixos/modules/system/boot/systemd/initrd.nix
@@ -487,27 +487,11 @@ in {
           # and /run/current-system. Also /tmp can be mounted to ensure that
           # it will be empty in stage 2.
           mkdir -p /tmp /sysroot/run /sysroot/tmp
-          mount --bind /run /sysroot/run
-          mount --bind /tmp /sysroot/tmp
-          mount --make-private /sysroot/run
+          mount --rbind /run /sysroot/run
 
           # Initialize the system
           export IN_NIXOS_SYSTEMD_STAGE1=1
-          chroot /sysroot $closure/prepare-root
-
-          # Since the activation script may create new mounts under /run, move these
-          # from /sysroot/run to /run to ensure that systemd moves them later.
-          while read -r _ where _; do
-            if [[ "$where" == /sysroot/run/* ]]; then
-              newWhere="''${where#/sysroot}"
-              mkdir -p "$newWhere"
-              mount --move "$where" "$newWhere"
-            fi
-          done < /proc/self/mounts
-
-          # systemd will only move /run if it's not a mountpoint yet, so unmount it
-          umount /sysroot/run
-          umount /sysroot/tmp
+          exec chroot /sysroot $closure/prepare-root
         '';
       };
 
diff --git a/pkgs/os-specific/linux/systemd/default.nix b/pkgs/os-specific/linux/systemd/default.nix
index f17ce344ce8..e130abbf27f 100644
--- a/pkgs/os-specific/linux/systemd/default.nix
+++ b/pkgs/os-specific/linux/systemd/default.nix
@@ -178,12 +178,6 @@ stdenv.mkDerivation {
     # need (AFAICT).
     # See https://github.com/systemd/systemd/pull/20479 for upstream discussion.
     ./0019-core-handle-lookup-paths-being-symlinks.patch
-
-    # Make systemd compatible with our initrd
-    (fetchpatch {
-      url = "https://github.com/systemd/systemd/commit/7653dfef361c070a14a45ab69b820a5f22e3a58d.patch";
-      sha256 = "0z8axwin1xkp2ldnlvy0mk7biisykbzvkjvza3kpqa8pmp0vn2sm";
-    })
   ] ++ lib.optional stdenv.hostPlatform.isMusl (
     let
       oe-core = fetchzip {
03:12:06
@elvishjerricco:matrix.org@elvishjerricco:matrix.org *

Janne Heß: This works for me:

diff --git a/nixos/modules/system/boot/systemd/initrd.nix b/nixos/modules/system/boot/systemd/initrd.nix
index 59dd508932f..6a9b8f90926 100644
--- a/nixos/modules/system/boot/systemd/initrd.nix
+++ b/nixos/modules/system/boot/systemd/initrd.nix
@@ -487,27 +487,11 @@ in {
           # and /run/current-system. Also /tmp can be mounted to ensure that
           # it will be empty in stage 2.
           mkdir -p /tmp /sysroot/run /sysroot/tmp
-          mount --bind /run /sysroot/run
-          mount --bind /tmp /sysroot/tmp
+          mount --rbind /run /sysroot/run
           mount --make-private /sysroot/run
 
           # Initialize the system
           export IN_NIXOS_SYSTEMD_STAGE1=1
-          chroot /sysroot $closure/prepare-root
-
-          # Since the activation script may create new mounts under /run, move these
-          # from /sysroot/run to /run to ensure that systemd moves them later.
-          while read -r _ where _; do
-            if [[ "$where" == /sysroot/run/* ]]; then
-              newWhere="''${where#/sysroot}"
-              mkdir -p "$newWhere"
-              mount --move "$where" "$newWhere"
-            fi
-          done < /proc/self/mounts
-
-          # systemd will only move /run if it's not a mountpoint yet, so unmount it
-          umount /sysroot/run
-          umount /sysroot/tmp
+          exec chroot /sysroot $closure/prepare-root
         '';
       };
 
diff --git a/pkgs/os-specific/linux/systemd/default.nix b/pkgs/os-specific/linux/systemd/default.nix
index f17ce344ce8..e130abbf27f 100644
--- a/pkgs/os-specific/linux/systemd/default.nix
+++ b/pkgs/os-specific/linux/systemd/default.nix
@@ -178,12 +178,6 @@ stdenv.mkDerivation {
     # need (AFAICT).
     # See https://github.com/systemd/systemd/pull/20479 for upstream discussion.
     ./0019-core-handle-lookup-paths-being-symlinks.patch
-
-    # Make systemd compatible with our initrd
-    (fetchpatch {
-      url = "https://github.com/systemd/systemd/commit/7653dfef361c070a14a45ab69b820a5f22e3a58d.patch";
-      sha256 = "0z8axwin1xkp2ldnlvy0mk7biisykbzvkjvza3kpqa8pmp0vn2sm";
-    })
   ] ++ lib.optional stdenv.hostPlatform.isMusl (
     let
       oe-core = fetchzip {
03:13:58
@elvishjerricco:matrix.org@elvishjerricco:matrix.org *

Janne Heß: This works for me:

diff --git a/nixos/modules/system/boot/systemd/initrd.nix b/nixos/modules/system/boot/systemd/initrd.nix
index 59dd508932f..67b1af5f6d1 100644
--- a/nixos/modules/system/boot/systemd/initrd.nix
+++ b/nixos/modules/system/boot/systemd/initrd.nix
@@ -413,7 +413,7 @@ in {
         "${cfg.package.util-linux}/bin/sulogin"
 
         # so NSS can look up usernames
-        "${pkgs.glibc}/lib/libnss_files.so"
+        "${pkgs.glibc}/lib/libnss_files.so.2"
       ] ++ jobScripts;
 
       targets.initrd.aliases = ["default.target"];
@@ -488,26 +488,11 @@ in {
           # it will be empty in stage 2.
           mkdir -p /tmp /sysroot/run /sysroot/tmp
           mount --bind /run /sysroot/run
-          mount --bind /tmp /sysroot/tmp
           mount --make-private /sysroot/run
 
           # Initialize the system
           export IN_NIXOS_SYSTEMD_STAGE1=1
-          chroot /sysroot $closure/prepare-root
-
-          # Since the activation script may create new mounts under /run, move these
-          # from /sysroot/run to /run to ensure that systemd moves them later.
-          while read -r _ where _; do
-            if [[ "$where" == /sysroot/run/* ]]; then
-              newWhere="''${where#/sysroot}"
-              mkdir -p "$newWhere"
-              mount --move "$where" "$newWhere"
-            fi
-          done < /proc/self/mounts
-
-          # systemd will only move /run if it's not a mountpoint yet, so unmount it
-          umount /sysroot/run
-          umount /sysroot/tmp
+          exec chroot /sysroot $closure/prepare-root
         '';
       };
 
diff --git a/pkgs/os-specific/linux/systemd/default.nix b/pkgs/os-specific/linux/systemd/default.nix
index f17ce344ce8..e130abbf27f 100644
--- a/pkgs/os-specific/linux/systemd/default.nix
+++ b/pkgs/os-specific/linux/systemd/default.nix
@@ -178,12 +178,6 @@ stdenv.mkDerivation {
     # need (AFAICT).
     # See https://github.com/systemd/systemd/pull/20479 for upstream discussion.
     ./0019-core-handle-lookup-paths-being-symlinks.patch
-
-    # Make systemd compatible with our initrd
-    (fetchpatch {
-      url = "https://github.com/systemd/systemd/commit/7653dfef361c070a14a45ab69b820a5f22e3a58d.patch";
-      sha256 = "0z8axwin1xkp2ldnlvy0mk7biisykbzvkjvza3kpqa8pmp0vn2sm";
-    })
   ] ++ lib.optional stdenv.hostPlatform.isMusl (
     let
       oe-core = fetchzip {
03:15:20
@elvishjerricco:matrix.org@elvishjerricco:matrix.org *

Janne Heß: This works for me:

diff --git a/nixos/modules/system/boot/systemd/initrd.nix b/nixos/modules/system/boot/systemd/initrd.nix
index 59dd508932f..515e30b6c9b 100644
--- a/nixos/modules/system/boot/systemd/initrd.nix
+++ b/nixos/modules/system/boot/systemd/initrd.nix
@@ -488,26 +488,11 @@ in {
           # it will be empty in stage 2.
           mkdir -p /tmp /sysroot/run /sysroot/tmp
           mount --bind /run /sysroot/run
-          mount --bind /tmp /sysroot/tmp
           mount --make-private /sysroot/run
 
           # Initialize the system
           export IN_NIXOS_SYSTEMD_STAGE1=1
-          chroot /sysroot $closure/prepare-root
-
-          # Since the activation script may create new mounts under /run, move these
-          # from /sysroot/run to /run to ensure that systemd moves them later.
-          while read -r _ where _; do
-            if [[ "$where" == /sysroot/run/* ]]; then
-              newWhere="''${where#/sysroot}"
-              mkdir -p "$newWhere"
-              mount --move "$where" "$newWhere"
-            fi
-          done < /proc/self/mounts
-
-          # systemd will only move /run if it's not a mountpoint yet, so unmount it
-          umount /sysroot/run
-          umount /sysroot/tmp
+          exec chroot /sysroot $closure/prepare-root
         '';
       };
 
diff --git a/pkgs/os-specific/linux/systemd/default.nix b/pkgs/os-specific/linux/systemd/default.nix
index f17ce344ce8..e130abbf27f 100644
--- a/pkgs/os-specific/linux/systemd/default.nix
+++ b/pkgs/os-specific/linux/systemd/default.nix
@@ -178,12 +178,6 @@ stdenv.mkDerivation {
     # need (AFAICT).
     # See https://github.com/systemd/systemd/pull/20479 for upstream discussion.
     ./0019-core-handle-lookup-paths-being-symlinks.patch
-
-    # Make systemd compatible with our initrd
-    (fetchpatch {
-      url = "https://github.com/systemd/systemd/commit/7653dfef361c070a14a45ab69b820a5f22e3a58d.patch";
-      sha256 = "0z8axwin1xkp2ldnlvy0mk7biisykbzvkjvza3kpqa8pmp0vn2sm";
-    })
   ] ++ lib.optional stdenv.hostPlatform.isMusl (
     let
       oe-core = fetchzip {


03:15:48
@elvishjerricco:matrix.org@elvishjerricco:matrix.org *

Janne Heß: This works for me:

diff --git a/nixos/modules/system/boot/systemd/initrd.nix b/nixos/modules/system/boot/systemd/initrd.nix
index 59dd508932f..b388852e342 100644
--- a/nixos/modules/system/boot/systemd/initrd.nix
+++ b/nixos/modules/system/boot/systemd/initrd.nix
@@ -486,28 +486,13 @@ in {
           # We need to propagate /run for things like /run/booted-system
           # and /run/current-system. Also /tmp can be mounted to ensure that
           # it will be empty in stage 2.
-          mkdir -p /tmp /sysroot/run /sysroot/tmp
+          mkdir -p /sysroot/run
           mount --bind /run /sysroot/run
-          mount --bind /tmp /sysroot/tmp
           mount --make-private /sysroot/run
 
           # Initialize the system
           export IN_NIXOS_SYSTEMD_STAGE1=1
-          chroot /sysroot $closure/prepare-root
-
-          # Since the activation script may create new mounts under /run, move these
-          # from /sysroot/run to /run to ensure that systemd moves them later.
-          while read -r _ where _; do
-            if [[ "$where" == /sysroot/run/* ]]; then
-              newWhere="''${where#/sysroot}"
-              mkdir -p "$newWhere"
-              mount --move "$where" "$newWhere"
-            fi
-          done < /proc/self/mounts
-
-          # systemd will only move /run if it's not a mountpoint yet, so unmount it
-          umount /sysroot/run
-          umount /sysroot/tmp
+          exec chroot /sysroot $closure/prepare-root
         '';
       };
 
diff --git a/pkgs/os-specific/linux/systemd/default.nix b/pkgs/os-specific/linux/systemd/default.nix
index f17ce344ce8..e130abbf27f 100644
--- a/pkgs/os-specific/linux/systemd/default.nix
+++ b/pkgs/os-specific/linux/systemd/default.nix
@@ -178,12 +178,6 @@ stdenv.mkDerivation {
     # need (AFAICT).
     # See https://github.com/systemd/systemd/pull/20479 for upstream discussion.
     ./0019-core-handle-lookup-paths-being-symlinks.patch
-
-    # Make systemd compatible with our initrd
-    (fetchpatch {
-      url = "https://github.com/systemd/systemd/commit/7653dfef361c070a14a45ab69b820a5f22e3a58d.patch";
-      sha256 = "0z8axwin1xkp2ldnlvy0mk7biisykbzvkjvza3kpqa8pmp0vn2sm";
-    })
   ] ++ lib.optional stdenv.hostPlatform.isMusl (
     let
       oe-core = fetchzip {
03:18:14
@elvishjerricco:matrix.org@elvishjerricco:matrix.org *

Janne Heß: This works for me:

diff --git a/nixos/modules/system/boot/systemd/initrd.nix b/nixos/modules/system/boot/systemd/initrd.nix
index 59dd508932f..491984d0347 100644
--- a/nixos/modules/system/boot/systemd/initrd.nix
+++ b/nixos/modules/system/boot/systemd/initrd.nix
@@ -481,37 +481,18 @@ in {
             exit 0
           fi
 
-          echo 'SYSTEMCTL_FORCE_HANDOVER=1' > /etc/switch-root.conf
-
           # We need to propagate /run for things like /run/booted-system
           # and /run/current-system. Also /tmp can be mounted to ensure that
           # it will be empty in stage 2.
-          mkdir -p /tmp /sysroot/run /sysroot/tmp
+          mkdir -p /sysroot/run
           mount --bind /run /sysroot/run
-          mount --bind /tmp /sysroot/tmp
           mount --make-private /sysroot/run
 
           # Initialize the system
           export IN_NIXOS_SYSTEMD_STAGE1=1
-          chroot /sysroot $closure/prepare-root
-
-          # Since the activation script may create new mounts under /run, move these
-          # from /sysroot/run to /run to ensure that systemd moves them later.
-          while read -r _ where _; do
-            if [[ "$where" == /sysroot/run/* ]]; then
-              newWhere="''${where#/sysroot}"
-              mkdir -p "$newWhere"
-              mount --move "$where" "$newWhere"
-            fi
-          done < /proc/self/mounts
-
-          # systemd will only move /run if it's not a mountpoint yet, so unmount it
-          umount /sysroot/run
-          umount /sysroot/tmp
+          exec chroot /sysroot $closure/prepare-root
         '';
       };
-
-      services.initrd-switch-root.serviceConfig.EnvironmentFile = "-/etc/switch-root.conf";
     };
   };
 }
diff --git a/pkgs/os-specific/linux/systemd/default.nix b/pkgs/os-specific/linux/systemd/default.nix
index f17ce344ce8..e130abbf27f 100644
--- a/pkgs/os-specific/linux/systemd/default.nix
+++ b/pkgs/os-specific/linux/systemd/default.nix
@@ -178,12 +178,6 @@ stdenv.mkDerivation {
     # need (AFAICT).
     # See https://github.com/systemd/systemd/pull/20479 for upstream discussion.
     ./0019-core-handle-lookup-paths-being-symlinks.patch
-
-    # Make systemd compatible with our initrd
-    (fetchpatch {
-      url = "https://github.com/systemd/systemd/commit/7653dfef361c070a14a45ab69b820a5f22e3a58d.patch";
-      sha256 = "0z8axwin1xkp2ldnlvy0mk7biisykbzvkjvza3kpqa8pmp0vn2sm";
-    })
   ] ++ lib.optional stdenv.hostPlatform.isMusl (
     let
       oe-core = fetchzip {
03:20:11
@elvishjerricco:matrix.org@elvishjerricco:matrix.org I also had to change libnss_files.so to libnss_files.so.2 for whatever reason 03:23:36
@elvishjerricco:matrix.org@elvishjerricco:matrix.org * I also had to change libnss_files.so to libnss_files.so.2 since for whatever reason the former doesn't exist anymore 03:23:59
@elvishjerricco:matrix.org@elvishjerricco:matrix.org bobvanderlinden: BTW, do you have any desire to revive the work you did to get makeInitrdNG to not copy everything into a scratch directory? 03:25:14
@bobvanderlinden_:matrix.orgbobvanderlinden
In reply to @elvishjerricco:matrix.org
bobvanderlinden: BTW, do you have any desire to revive the work you did to get makeInitrdNG to not copy everything into a scratch directory?
Sure. Just need to find some time again. Previously I worked on https://github.com/NixOS/nixpkgs/pull/167231, is it still useful to work on that further?
06:01:41
@elvishjerricco:matrix.org@elvishjerricco:matrix.org bobvanderlinden: It sounds like Janne Heß or Arian has LUKS covered somehow. Don't think they've opened a PR about it though 06:03:33
@janne.hess:helsinki-systems.de@janne.hess:helsinki-systems.de
In reply to @elvishjerricco:matrix.org
Well I tried it and it failed spectacularly :P Not sure why
Yep, same :P
08:19:43
@janne.hess:helsinki-systems.de@janne.hess:helsinki-systems.de
In reply to @elvishjerricco:matrix.org
bobvanderlinden: It sounds like Janne Heß or Arian has LUKS covered somehow. Don't think they've opened a PR about it though
Yes, I stole bobs code and went on from there. I also added improved udev support and lvm2 (which are both not clean enough yet for a PR)
08:21:18
@janne.hess:helsinki-systems.de@janne.hess:helsinki-systems.deMaybe I can push udev today 08:26:06
@janne.hess:helsinki-systems.de@janne.hess:helsinki-systems.de
In reply to @elvishjerricco:matrix.org

Janne Heß: This works for me:

diff --git a/nixos/modules/system/boot/systemd/initrd.nix b/nixos/modules/system/boot/systemd/initrd.nix
index 59dd508932f..491984d0347 100644
--- a/nixos/modules/system/boot/systemd/initrd.nix
+++ b/nixos/modules/system/boot/systemd/initrd.nix
@@ -481,37 +481,18 @@ in {
             exit 0
           fi
 
-          echo 'SYSTEMCTL_FORCE_HANDOVER=1' > /etc/switch-root.conf
-
           # We need to propagate /run for things like /run/booted-system
           # and /run/current-system. Also /tmp can be mounted to ensure that
           # it will be empty in stage 2.
-          mkdir -p /tmp /sysroot/run /sysroot/tmp
+          mkdir -p /sysroot/run
           mount --bind /run /sysroot/run
-          mount --bind /tmp /sysroot/tmp
           mount --make-private /sysroot/run
 
           # Initialize the system
           export IN_NIXOS_SYSTEMD_STAGE1=1
-          chroot /sysroot $closure/prepare-root
-
-          # Since the activation script may create new mounts under /run, move these
-          # from /sysroot/run to /run to ensure that systemd moves them later.
-          while read -r _ where _; do
-            if [[ "$where" == /sysroot/run/* ]]; then
-              newWhere="''${where#/sysroot}"
-              mkdir -p "$newWhere"
-              mount --move "$where" "$newWhere"
-            fi
-          done < /proc/self/mounts
-
-          # systemd will only move /run if it's not a mountpoint yet, so unmount it
-          umount /sysroot/run
-          umount /sysroot/tmp
+          exec chroot /sysroot $closure/prepare-root
         '';
       };
-
-      services.initrd-switch-root.serviceConfig.EnvironmentFile = "-/etc/switch-root.conf";
     };
   };
 }
diff --git a/pkgs/os-specific/linux/systemd/default.nix b/pkgs/os-specific/linux/systemd/default.nix
index f17ce344ce8..e130abbf27f 100644
--- a/pkgs/os-specific/linux/systemd/default.nix
+++ b/pkgs/os-specific/linux/systemd/default.nix
@@ -178,12 +178,6 @@ stdenv.mkDerivation {
     # need (AFAICT).
     # See https://github.com/systemd/systemd/pull/20479 for upstream discussion.
     ./0019-core-handle-lookup-paths-being-symlinks.patch
-
-    # Make systemd compatible with our initrd
-    (fetchpatch {
-      url = "https://github.com/systemd/systemd/commit/7653dfef361c070a14a45ab69b820a5f22e3a58d.patch";
-      sha256 = "0z8axwin1xkp2ldnlvy0mk7biisykbzvkjvza3kpqa8pmp0vn2sm";
-    })
   ] ++ lib.optional stdenv.hostPlatform.isMusl (
     let
       oe-core = fetchzip {
and systemd-analyze said you had an initrd? :O
09:00:46
@elvishjerricco:matrix.org@elvishjerricco:matrix.org
In reply to @janne.hess:helsinki-systems.de
and systemd-analyze said you had an initrd? :O
Right
09:58:50
@janne.hess:helsinki-systems.de@janne.hess:helsinki-systems.deI'll try that when I get back home10:14:48
@janne.hess:helsinki-systems.de@janne.hess:helsinki-systems.de
In reply to @elvishjerricco:matrix.org
Right
Interestingly enough, it doesn't work on my laptop
17:26:29
@janne.hess:helsinki-systems.de@janne.hess:helsinki-systems.deAlright, since I didn't get your handover code to work, I instead pushed my udev changes and moved the options where people wanted them to be17:57:10
@janne.hess:helsinki-systems.de@janne.hess:helsinki-systems.deSo time to get to work with device-mapper and lvm2 🥳18:00:44
@arianvp:matrix.orgArianI'll review the udev changes later today18:14:38
11 Apr 2022
@elvishjerricco:matrix.org@elvishjerricco:matrix.org
In reply to @janne.hess:helsinki-systems.de
Interestingly enough, it doesn't work on my laptop
What went wrong?
03:09:13
@janne.hess:helsinki-systems.de@janne.hess:helsinki-systems.de
In reply to @elvishjerricco:matrix.org
What went wrong?
It didn't recognize the systemd as a systemd and didn't serialise the state
09:42:56
@elvishjerricco:matrix.org@elvishjerricco:matrix.orgHuh...09:43:31

There are no newer messages yet.


Back to Room ListRoom Version: 6