-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathpersist.mod.nix
More file actions
116 lines (103 loc) · 3.24 KB
/
Copy pathpersist.mod.nix
File metadata and controls
116 lines (103 loc) · 3.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
{
flake.nixosModules.persist =
{
lib,
config,
utils,
...
}:
let
inherit (lib.attrsets) genAttrs;
inherit (lib.generators) toINI;
inherit (lib.lists) singleton;
inherit (lib.modules) mkIf;
inherit (lib.options) mkEnableOption mkOption;
inherit (lib.types)
listOf
nullOr
path
str
;
inherit (utils) escapeSystemdPath;
in
{
options.persist = {
enable = mkEnableOption "bcachefs subvolume persistence";
filesystemName = mkOption {
type = str;
default = "persist";
description = "Name of the filesystem.";
};
passwordFile = mkOption {
type = nullOr path;
default = null;
description = "Path to the passphrase file.";
};
extraFormatArgs = mkOption {
type = listOf str;
default = [
"--compression=zstd:9"
"--background_compression=zstd:9"
"--block_size=4096"
];
description = "Extra arguments passed to bcachefs format.";
};
mountpoint = mkOption {
type = path;
default = "/media/${config.persist.filesystemName}";
description = "Mountpoint for the filesystem.";
};
subvolumes = mkOption {
type = listOf path;
default = [ ];
description = "Directories to persist as subvolumes under the root filesystem.";
};
mountOptions = mkOption {
type = listOf str;
default = [
"lazytime"
];
description = "Mount options applied to the filesystem and every subvolume.";
};
};
config = mkIf config.persist.enable {
disko.devices.nodev."root" = {
fsType = "tmpfs";
mountpoint = "/";
mountOptions = [
"defaults"
"size=25%"
"mode=755"
];
};
disko.devices.bcachefs_filesystems.${config.persist.filesystemName} = {
type = "bcachefs_filesystem";
inherit (config.persist)
mountpoint
passwordFile
extraFormatArgs
mountOptions
;
subvolumes = genAttrs config.persist.subvolumes (mountpoint: {
inherit mountpoint;
inherit (config.persist) mountOptions;
});
};
# Suppress nixpkgs's per-mountpoint unlock services.
boot.initrd.systemd.suppressedUnits = mkIf (config.persist.passwordFile != null) (
singleton config.persist.mountpoint ++ config.persist.subvolumes
|> map (mountpoint: "unlock-bcachefs-${escapeSystemdPath mountpoint}.service")
);
boot.initrd.systemd.units."sysroot-${escapeSystemdPath config.persist.mountpoint}.mount" =
mkIf (config.persist.passwordFile != null)
{
overrideStrategy = "asDropin";
text = toINI { } {
Unit.RequiresMountsFor = "/sysroot${dirOf config.persist.passwordFile}";
Mount.StandardInput = "file:/sysroot${config.persist.passwordFile}";
# Mount.KeyringMode = "shared";
};
};
};
};
}