!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
19 Mar 2022
@elvishjerricco:matrix.org@elvishjerricco:matrix.org Arian: That wouldn't work exactly, as it wouldn't be compressed. 10:09:31
@elvishjerricco:matrix.org@elvishjerricco:matrix.orgBut something in that direction, like an extra boot stage, is interesting10:09:59
@arianvp:matrix.orgArianstage 1.510:10:13
@elvishjerricco:matrix.org@elvishjerricco:matrix.orgI will not be pursuing this madness for the sake of my own sanity :P10:10:34
@bobvanderlinden_:matrix.orgbobvanderlindenDo any of you have experience with advanced mkOptions and submodules? I'm trying to make the systemd units, services, mounts, etc options reusable for systemd, systemd-user and systemd-initramfs. What would be a good approach? I have worked on a solution that still feels quite dirty, but it is easily reusable: https://github.com/bobvanderlinden/nixpkgs/commit/06fa176a1bab3ca1908188649fb3bd117b42c2f810:12:17
@bobvanderlinden_:matrix.orgbobvanderlindenOh sorry, this commit is more relevant: https://github.com/bobvanderlinden/nixpkgs/commit/e5ad5b33604e9cb7bf2c37df179518140db7e43010:16:00
@bobvanderlinden_:matrix.orgbobvanderlinden

basically, it creates a submodule for each of the unit-types (services, mounts, etc). The submodule has:

{
  options = {
    ${type} = mkOption {
      ...
    };
  };
  config = {
    units = convertToUnit config.${type};
  };
}

That means that such modules need to be merged to get to a systemd module. I'm not sure if nixos config is capable of this or whether I should just write it out, like systemd.nix and systemd-user.nix also do.

10:20:13
@elvishjerricco:matrix.org@elvishjerricco:matrix.org Sidenote, are you moving the systemd.* options to boot.systemd.*? 10:21:58
@elvishjerricco:matrix.org@elvishjerricco:matrix.orgCuz systemd units aren't all about booting10:22:08
@bobvanderlinden_:matrix.orgbobvanderlinden oh sorry, no I get confused by systemd.nix being in nixos/modules/boot/systemd.nix. I did 'move' things to boot.iniramfs.systemd for the stage-1 / inird stuff 10:24:21
@bobvanderlinden_:matrix.orgbobvanderlinden * oh sorry, no I get confused by systemd.nix being in nixos/modules/boot/systemd.nix (while the option sits in systemd.*). I did 'move' things to boot.iniramfs.systemd for the stage-1 / inird stuff 10:24:59
@elvishjerricco:matrix.org@elvishjerricco:matrix.orgAlso, if I may nitpick, the systemd docs recommend to call it initrd even though initramfs is more technically correct. They just have a ton of stuff that calls it initrd and basically ask everyone to just play along10:25:14
@bobvanderlinden_:matrix.orgbobvanderlindenhmm, it's true that system only refers to initrd10:28:19
@elvishjerricco:matrix.org@elvishjerricco:matrix.org bobvanderlinden: btw I had started what I'm doing today on top of your pr-refactor-systemd-module branch. Is that pr-reusable-systemd-module branch (refactor vs reusable) the one you're actually planning to try to get merged? 10:28:50
@bobvanderlinden_:matrix.orgbobvanderlinden

Is that pr-reusable-systemd-module branch (refactor vs reusable) the one you're actually planning to try to get merged?

Yes, though pr-refactor-systemd-module were the commits that I am confident that it will get merged in a form simliar to what it currently is.
pr-reusable-systemd-module might be taking things 'too far' in terms of reusabability. Even though we can use this in 3 places, they way it is using modules and merging will have a higher probability that a reviewer will reject the change.

10:32:08
@elvishjerricco:matrix.org@elvishjerricco:matrix.org

Ok... I'm just gonna keep truckin on the refactor branch for now then :P I did add a smaller unification of my own by placing the types into a common place, at least.

diff --git a/nixos/lib/systemd-types.nix b/nixos/lib/systemd-types.nix
new file mode 100644
index 00000000000..b303335ffc1
--- /dev/null
+++ b/nixos/lib/systemd-types.nix
@@ -0,0 +1,30 @@
+{ lib, systemdUtils }:
+
+with systemdUtils.lib;
+with systemdUtils.unitOptions;
+with lib;
+
+rec {
+  units = with types;
+    attrsOf (submodule ({ name, config, ... }: {
+      options = concreteUnitOptions;
+      config = { unit = mkDefault (systemdUtils.lib.makeUnit name config); };
+    }));
+
+  services = with types; attrsOf (submodule [ { options = serviceOptions; } unitConfig serviceConfig ]);
+  initrdServices = with types; attrsOf (submodule [ { options = serviceOptions; } unitConfig initrdServiceConfig ]);
+
+  targets = with types; attrsOf (submodule [ { options = targetOptions; } unitConfig ]);
+
+  sockets = with types; attrsOf (submodule [ { options = socketOptions; } unitConfig ]);
+
+  timers = with types; attrsOf (submodule [ { options = timerOptions; } unitConfig ]);
+
+  paths = with types; attrsOf (submodule [ { options = pathOptions; } unitConfig ]);
+
+  slices = with types; attrsOf (submodule [ { options = sliceOptions; } unitConfig ]);
+
+  mounts = with types; listOf (submodule [ { options = mountOptions; } unitConfig mountConfig ]);
+
+  automounts = with types; listOf (submodule [ { options = automountOptions; } unitConfig automountConfig ]);
+}
diff --git a/nixos/lib/utils.nix b/nixos/lib/utils.nix
index ae68c3920c5..80341dd48fc 100644
--- a/nixos/lib/utils.nix
+++ b/nixos/lib/utils.nix
@@ -197,5 +197,6 @@ rec {
   systemdUtils = {
     lib = import ./systemd-lib.nix { inherit lib config pkgs; };
     unitOptions = import ./systemd-unit-options.nix { inherit lib systemdUtils; };
+    types = import ./systemd-types.nix { inherit lib systemdUtils; };
   };
 }
diff --git a/nixos/modules/system/boot/systemd.nix b/nixos/modules/system/boot/systemd.nix
index 057474c607a..396457e1a9f 100644
--- a/nixos/modules/system/boot/systemd.nix
+++ b/nixos/modules/system/boot/systemd.nix
@@ -14,10 +14,6 @@ let
     makeUnit
     generateUnits
     makeJobScript
-    unitConfig
-    serviceConfig
-    mountConfig
-    automountConfig
     commonUnitText
     targetToUnit
     serviceToUnit
@@ -185,13 +181,7 @@ in
     systemd.units = mkOption {
       description = "Definition of systemd units.";
       default = {};
-      type = with types; attrsOf (submodule (
-        { name, config, ... }:
-        { options = concreteUnitOptions;
-          config = {
-            unit = mkDefault (makeUnit name config);
-          };
-        }));
+      type = systemdUtils.types.units;
     };
 
     systemd.packages = mkOption {
@@ -203,37 +193,37 @@ in
 
     systemd.targets = mkOption {
       default = {};
-      type = with types; attrsOf (submodule [ { options = targetOptions; } unitConfig] );
+      type = systemdUtils.types.targets;
       description = "Definition of systemd target units.";
     };
 
     systemd.services = mkOption {
       default = {};
-      type = with types; attrsOf (submodule [ { options = serviceOptions; } unitConfig serviceConfig ]);
+      type = systemdUtils.types.services;
       description = "Definition of systemd service units.";
     };
 
     systemd.sockets = mkOption {
       default = {};
-      type = with types; attrsOf (submodule [ { options = socketOptions; } unitConfig ]);
+      type = systemdUtils.types.sockets;
       description = "Definition of systemd socket units.";
     };
 
     systemd.timers = mkOption {
       default = {};
-      type = with types; attrsOf (submodule [ { options = timerOptions; } unitConfig ]);
+      type = systemdUtils.types.timers;
       description = "Definition of systemd timer units.";
     };
 
     systemd.paths = mkOption {
       default = {};
-      type = with types; attrsOf (submodule [ { options = pathOptions; } unitConfig ]);
+      type = systemdUtils.types.paths;
       description = "Definition of systemd path units.";
     };
 
     systemd.mounts = mkOption {
       default = [];
-      type = with types; listOf (submodule [ { options = mountOptions; } unitConfig mountConfig ]);
+      type = systemdUtils.types.mounts;
       description = ''
         Definition of systemd mount units.
         This is a list instead of an attrSet, because systemd mandates the names to be derived from
@@ -243,7 +233,7 @@ in
 
     systemd.automounts = mkOption {
       default = [];
-      type = with types; listOf (submodule [ { options = automountOptions; } unitConfig automountConfig ]);
+      type = systemdUtils.types.automounts;
       description = ''
         Definition of systemd automount units.
         This is a list instead of an attrSet, because systemd mandates the names to be derived from
@@ -253,7 +243,7 @@ in
 
     systemd.slices = mkOption {
       default = {};
-      type = with types; attrsOf (submodule [ { options = sliceOptions; } unitConfig] );
+      type = systemdUtils.types.slices;
       description = "Definition of slice configurations.";
     };
 
diff --git a/nixos/modules/system/boot/systemd/user.nix b/nixos/modules/system/boot/systemd/user.nix
index 6f63292bf9f..c04933263ac 100644
--- a/nixos/modules/system/boot/systemd/user.nix
+++ b/nixos/modules/system/boot/systemd/user.nix
@@ -12,10 +12,6 @@ let
     (systemdUtils.lib)
     makeUnit
     generateUnits
-    makeJobScript
-    unitConfig
-    serviceConfig
-    commonUnitText
     targetToUnit
     serviceToUnit
     socketToUnit
@@ -57,48 +53,42 @@ in {
     systemd.user.units = mkOption {
       description = "Definition of systemd per-user units.";
       default = {};
-      type = with types; attrsOf (submodule (
-        { name, config, ... }:
-        { options = concreteUnitOptions;
-          config = {
-            unit = mkDefault (makeUnit name config);
-          };
-        }));
+      type = systemdUtils.types.units;
     };
 
     systemd.user.paths = mkOption {
       default = {};
-      type = with types; attrsOf (submodule [ { options = pathOptions; } unitConfig ]);
+      type = systemdUtils.types.paths;
       description = "Definition of systemd per-user path units.";
     };
 
     systemd.user.services = mkOption {
       default = {};
-      type = with types; attrsOf (submodule [ { options = serviceOptions; } unitConfig serviceConfig ] );
+      type = systemdUtils.types.services;
       description = "Definition of systemd per-user service units.";
     };
 
     systemd.user.slices = mkOption {
       default = {};
-      type = with types; attrsOf (submodule [ { options = sliceOptions; } unitConfig ] );
+      type = systemdUtils.types.slices;
       description = "Definition of systemd per-user slice units.";
     };
 
     systemd.user.sockets = mkOption {
       default = {};
-      type = with types; attrsOf (submodule [ { options = socketOptions; } unitConfig ] );
+      type = systemdUtils.types.sockets;
       description = "Definition of systemd per-user socket units.";
     };
 
     systemd.user.targets = mkOption {
       default = {};
-      type = with types; attrsOf (submodule [ { options = targetOptions; } unitConfig] );
+      type = systemdUtils.types.targets;
       description = "Definition of systemd per-user target units.";
     };
 
     systemd.user.timers = mkOption {
       default = {};
-      type = with types; attrsOf (submodule [ { options = timerOptions; } unitConfig ] );
+      type = systemdUtils.types.timers;
       description = "Definition of systemd per-user timer units.";
     };
 
10:34:04
@elvishjerricco:matrix.org@elvishjerricco:matrix.orgLets me reuse the types and use "only" 70 lines to copy stuff for the initrd module10:37:03
@bobvanderlinden_:matrix.orgbobvanderlindenah, exactly. that looks similar to what I would've done if the module-reusing is a bit too much 😅10:37:39
@elvishjerricco:matrix.org@elvishjerricco:matrix.orgI do think fully modularizing it would be nice, but definitely not necessary. I think if it hurts eval time at all it's not worth it10:37:41
@bobvanderlinden_:matrix.orgbobvanderlinden btw, initrdServiceConfig? is that different from serviceConfig? 10:37:53
@elvishjerricco:matrix.org@elvishjerricco:matrix.orgBut if not, and the code isn't crazy, then cool10:38:02
@elvishjerricco:matrix.org@elvishjerricco:matrix.org bobvanderlinden: Yes. I couldn't think of a really clean way to have the default path option differ 10:38:20
@elvishjerricco:matrix.org@elvishjerricco:matrix.orgBecause we don't want anything in that by default for initrd10:38:29
@elvishjerricco:matrix.org@elvishjerricco:matrix.org If anyone actually uses path, we'll have no sane choice but to add the whole bin directory for those packages to the initrd because that's the only thing it could mean 10:39:21
@elvishjerricco:matrix.org@elvishjerricco:matrix.orgSo anything in there by default is necessarily excessive10:39:44
@elvishjerricco:matrix.org@elvishjerricco:matrix.org Though I definitely wasn't supposed to put the initrdServices line in that config lol. Supposed to be in the commit that actually adds that stuff 10:41:33
@elvishjerricco:matrix.org@elvishjerricco:matrix.org * Though I definitely wasn't supposed to put the initrdServices line in that commit lol. Supposed to be in the commit that actually adds that stuff 10:41:50
@bobvanderlinden_:matrix.orgbobvanderlinden

ah, I think you refer to:

https://github.com/nixos/nixpkgs/blob/9bc093b30a3ab38f9e5b30a132b08a9fd9b27ade/nixos/lib/systemd-lib.nix#L299

That should refer to a new option config.systemd.path, which for boot/systemd.nix and boot/systemd/user.nix should refer to config.path.

10:42:36
@bobvanderlinden_:matrix.orgbobvanderlindenbut I guess that'll force serviceConfig to be a function again with its added complexity 😅10:43:15
@elvishjerricco:matrix.org@elvishjerricco:matrix.org Yea, so I just... made a mkServiceConfig function that takes an argument for the default path and created serviceConfig and initrdServiceConfig to keep it simple 10:44:05

Show newer messages


Back to Room ListRoom Version: 6