-
Notifications
You must be signed in to change notification settings - Fork 2
/
btrfs.nix
129 lines (114 loc) · 3.5 KB
/
btrfs.nix
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
117
118
119
120
121
122
123
124
125
126
127
128
129
{ config, lib, ... }:
with lib;
let
cfg = config.custom.btrfs;
in
{
options.custom.btrfs = {
# TODO Make this a submodule like all the others that serves as the default for them
default = {
device = mkOption {
description = ''
The default device to use if none is declared.
'';
default = lib.warn "No `custom.btrfs.default.device` declared, proceed with caution!" null;
defaultText = ''
The device specified in `custom.custom.fs.btrfs.device`
This allows for easily extending the defaults without having to re-specify the main device every time
'';
};
options = mkOption {
description = ''
The mount options to use if none are declared.
'';
default = [ ];
};
};
fileSystems = mkOption {
type = types.attrsOf (types.submodule {
options = {
device = mkOption {
description = ''
The device to mount
'';
default = cfg.default.device;
defaultText = ''
The device declared in `custom.btrfs.default.device`
This allows for easily extending custom generic defaults without having to declare the same main device every time
'';
};
compress = {
# TODO Make this on by default
enable = mkOption {
description = ''
Whether to enabe btrfs filesystem compression
'';
default = true;
};
algorithm = mkOption {
description = ''
The compression algorith to use
'';
default = "zstd";
};
level = mkOption {
description = ''
The compression level to use
'';
default = 1;
};
force = mkOption {
description = ''
Whether to force compression or leave btrfs to decide what's compressible and what isn't
'';
default = true;
};
};
subvol = mkOption {
description = ''
Subvolume to mount. Null means default subvol
'';
default = null;
};
options = mkOption {
description = ''
Mount options too add on
'';
default = cfg.default.options;
};
};
});
default = { };
example = literalExample ''
{
"/data" = {
device = "/dev/disk/by-id/ata-foo";
subvolume = "data";
compress.level = 10;
extraOptions = [ "autodefrag" ];
};
"/home" = {
device = "/dev/disk/by-id/ata-foo";
subvolume = "home";
compress = {
force = false;
level = 2;
};
};
};
'';
description = ''
Btrfs fileSystems, declared similar to NixOS' `fileSystems`.
'';
};
};
config.fileSystems = mapAttrs (_: fileSystem: {
fsType = "btrfs";
inherit (fileSystem) device;
options = with fileSystem; let
compressArg = with compress;
optional enable "compress${optionalString force "-force"}=${algorithm + optionalString (level != null) ":${toString level}"}";
subvolArg = optional (subvol != null) "subvol=${subvol}";
in compressArg ++ subvolArg ++ fileSystem.options;
}) cfg.fileSystems;
}