-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpartition.nix
65 lines (58 loc) · 1.64 KB
/
partition.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
fs: disk: { lib, name, config, ... }:
let
inherit (lib) elemAt mkOption toInt;
inherit (lib.types) anything nullOr path str;
listIx = name:
# name is of the form: [definition X-entry Y]
let res = builtins.match "[[]definition ([0-9]+)-entry ([0-9]+)[]]" name; in
assert res != null; {
def = toInt (elemAt res 0);
ent = toInt (elemAt res 1);
};
in
{
options = {
device = mkOption {
description = "Path to the partition device file";
type = path;
default = let ix = listIx name; in
assert ix.def == 1; # there can only be one partition list per disk
"${disk.device}${disk.separator}${toString ix.ent}";
};
type = mkOption {
description = "Partition type for sfdisk";
type = str;
default = if fs.is.swap config.content then "swap" else "linux";
};
size = mkOption {
description = "Size of the partition for sfdisk (null = remaining size)";
type = nullOr str;
default = null;
};
content = mkOption {
description = "Partition content";
inherit (fs) type;
};
_entry = mkOption {
type = str;
readOnly = true;
default = builtins.concatStringsSep "," (
[ "type=${config.type}" ] ++
(if config.size != null then [ "size=${config.size}" ] else [ ])
);
};
_create = mkOption {
type = str;
# readOnly = true;
default = ''
wipefs -af "${config.device}"
${config.content._create config.device}
'';
};
_mounts = mkOption {
type = anything;
readOnly = true;
default = config.content._mounts config.device;
};
};
}