19 Mar 2022 |
@elvishjerricco:matrix.org | Also, on some systems I'm pretty sure the decompression of the initramfs is extremely costly | 10:07:14 |
Arian | but what if we have a /boot/nix/store and initrd is just a small thing mounting that :Exploding head: | 10:07:23 |
@elvishjerricco:matrix.org | my rpi boots with EFI and Grub and it takes 3 minutes to reach the kernel | 10:07:27 |
Arian | then we can have garbage collection etc :P | 10:07:31 |
@elvishjerricco:matrix.org | that's... actually an incredibly interesting idea lol | 10:07:51 |
@elvishjerricco:matrix.org | In reply to @bobvanderlinden_:matrix.org Hmm, at the moment, mine is 18M (/boot/kernels/9cvnrh9wh6r707klrv7aawl8zm8w22rs-initrd-linux-5.15.27-initrd ) That's impressive | 10:08:06 |
@elvishjerricco:matrix.org | Er, is that the systemd one or a regular one | 10:08:24 |
@elvishjerricco:matrix.org | * Er, is that the systemd one or a regular one? | 10:08:26 |
Arian | current one I suppose | 10:08:31 |
Arian | Does FAT32 support hardlinks? | 10:08:38 |
Arian | probably not right? | 10:08:49 |
@elvishjerricco:matrix.org | no idea | 10:08:55 |
| * colemickens had historically seen that on rpi but it went away after some recent updates to grub/uboot or the rpi firmware iirc | 10:08:59 |
Arian | still. proper nix store on the ESP doesn't sound too wild. Sounds like a good idea | 10:09:08 |
@elvishjerricco:matrix.org | Arian: That wouldn't work exactly, as it wouldn't be compressed. | 10:09:31 |
@elvishjerricco:matrix.org | But something in that direction, like an extra boot stage, is interesting | 10:09:59 |
Arian | stage 1.5 | 10:10:13 |
@elvishjerricco:matrix.org | I will not be pursuing this madness for the sake of my own sanity :P | 10:10:34 |
bobvanderlinden | Do 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/06fa176a1bab3ca1908188649fb3bd117b42c2f8 | 10:12:17 |
bobvanderlinden | Oh sorry, this commit is more relevant: https://github.com/bobvanderlinden/nixpkgs/commit/e5ad5b33604e9cb7bf2c37df179518140db7e430 | 10:16:00 |
bobvanderlinden | 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 | Sidenote, are you moving the systemd.* options to boot.systemd.* ? | 10:21:58 |
@elvishjerricco:matrix.org | Cuz systemd units aren't all about booting | 10:22:08 |
bobvanderlinden | 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 | * 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 | Also, 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 along | 10:25:14 |
bobvanderlinden | hmm, it's true that system only refers to initrd | 10:28:19 |
@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 |
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 | 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 |