···
1
-
{ config, pkgs, lib, ... }:
1
+
{ config, pkgs, lib, utils, ... }:
cfg = config.systemd.repart;
···
29
-
boot.initrd.systemd.repart.enable = lib.mkEnableOption (lib.mdDoc "systemd-repart") // {
30
-
description = lib.mdDoc ''
31
-
Grow and add partitions to a partition table at boot time in the initrd.
32
-
systemd-repart only works with GPT partition tables.
29
+
boot.initrd.systemd.repart = {
30
+
enable = lib.mkEnableOption (lib.mdDoc "systemd-repart") // {
31
+
description = lib.mdDoc ''
32
+
Grow and add partitions to a partition table at boot time in the initrd.
33
+
systemd-repart only works with GPT partition tables.
34
-
To run systemd-repart after the initrd, see
35
-
`options.systemd.repart.enable`.
35
+
To run systemd-repart after the initrd, see
36
+
`options.systemd.repart.enable`.
40
+
device = lib.mkOption {
41
+
type = with lib.types; nullOr str;
42
+
description = lib.mdDoc ''
43
+
The device to operate on.
45
+
If `device == null`, systemd-repart will operate on the device
46
+
backing the root partition. So in order to dynamically *create* the
47
+
root partition in the initrd you need to set a device.
50
+
example = "/dev/vda";
···
contents."/etc/repart.d".source = definitionsDirectory;
# Override defaults in upstream unit.
87
-
services.systemd-repart = {
88
-
# systemd-repart tries to create directories in /var/tmp by default to
89
-
# store large temporary files that benefit from persistence on disk. In
90
-
# the initrd, however, /var/tmp does not provide more persistence than
91
-
# /tmp, so we re-use it here.
92
-
environment."TMPDIR" = "/tmp";
95
-
" " # required to unset the previous value.
96
-
# When running in the initrd, systemd-repart by default searches
97
-
# for definition files in /sysroot or /sysusr. We tell it to look
98
-
# in the initrd itself.
99
-
''${config.boot.initrd.systemd.package}/bin/systemd-repart \
102
+
services.systemd-repart =
104
+
deviceUnit = "${utils.escapeSystemdPath initrdCfg.device}.device";
107
+
# systemd-repart tries to create directories in /var/tmp by default to
108
+
# store large temporary files that benefit from persistence on disk. In
109
+
# the initrd, however, /var/tmp does not provide more persistence than
110
+
# /tmp, so we re-use it here.
111
+
environment."TMPDIR" = "/tmp";
114
+
" " # required to unset the previous value.
115
+
# When running in the initrd, systemd-repart by default searches
116
+
# for definition files in /sysroot or /sysusr. We tell it to look
117
+
# in the initrd itself.
118
+
''${config.boot.initrd.systemd.package}/bin/systemd-repart \
--definitions=/etc/repart.d \
120
+
--dry-run=no ${lib.optionalString (initrdCfg.device != null) initrdCfg.device}
124
+
# systemd-repart needs to run after /sysroot (or /sysuser, but we
125
+
# don't have it) has been mounted because otherwise it cannot
126
+
# determine the device (i.e disk) to operate on. If you want to run
127
+
# systemd-repart without /sysroot (i.e. to create the root
128
+
# partition), you have to explicitly tell it which device to operate
129
+
# on. The service then needs to be ordered to run after this device
131
+
requires = lib.mkIf (initrdCfg.device != null) [ deviceUnit ];
133
+
if initrdCfg.device == null then
134
+
[ "sysroot.mount" ]
105
-
# systemd-repart needs to run after /sysroot (or /sysuser, but we don't
106
-
# have it) has been mounted because otherwise it cannot determine the
107
-
# device (i.e disk) to operate on. If you want to run systemd-repart
108
-
# without /sysroot, you have to explicitly tell it which device to
110
-
after = [ "sysroot.mount" ];
environment.etc = lib.mkIf cfg.enable {