-
-
Notifications
You must be signed in to change notification settings - Fork 294
Expand file tree
/
Copy pathbcachefs.nix
More file actions
100 lines (100 loc) · 3.93 KB
/
bcachefs.nix
File metadata and controls
100 lines (100 loc) · 3.93 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
{
config,
device,
diskoLib,
lib,
options,
parent,
...
}:
{
options = {
type = lib.mkOption {
type = lib.types.enum [ "bcachefs" ];
internal = true;
description = "Type.";
};
device = lib.mkOption {
type = lib.types.str;
default = device;
description = "Device to use.";
example = "/dev/sda";
};
filesystem = lib.mkOption {
type = lib.types.str;
description = "Name of the bcachefs filesystem this partition belongs to.";
example = "main_bcachefs_filesystem";
};
# These are passed as arguments to the device corresponding to this one in the invocation of the `bcachefs format` command
# in the bcachefs_filesystem type defined in bcachefs_filesystem.nix used to format the bcachefs filesystem that this device is a part of.
extraFormatArgs = lib.mkOption {
type = lib.types.listOf lib.types.str;
default = [ ];
description = "Extra arguments passed to the bcachefs format command.";
example = [ "--discard" ];
};
# This value is passed to the `--label` option for the device corresponding to this one in the invocation of the `bcachefs format` command
# in the bcachefs_filesystem type defined in bcachefs_filesystem.nix used to format the bcachefs filesystem that this device is a part of.
label = lib.mkOption {
type = lib.types.str;
default = "";
description = ''
Label to use for this device.
This value is passed as the `--label` argument to the `bcachefs format` command when formatting the device.
'';
example = "group_a.sda2";
};
_parent = lib.mkOption {
internal = true;
default = parent;
};
_meta = lib.mkOption {
internal = true;
readOnly = true;
type = lib.types.functionTo diskoLib.jsonType;
# Ensures that this file's `_create` will be ran for all member devices that are part of the filesystem being created,
# before the `_create` in bcachefs_filesystem.nix is ran.
default = dev: {
deviceDependencies.bcachefs_filesystems.${config.filesystem} = [ dev ];
};
};
_create = diskoLib.mkCreateOption {
inherit config options;
# The bcachefs_filesystem type defined in bcachefs_filesystem.nix will include this device when formatting and mounting the filesystem.
# The current file should not run the `bcachefs format` command. Instead, the`bcachefs format` command will be ran
# in the `_create` attribute in bcachefs_filesystem.nix, once it has collected and generated the arguments specifying the devices that should be part of the filesystem.
default = ''
# Write device arguments to temporary directory for bcachefs_filesystem.
{
${lib.optionalString (config.label != "") ''printf '%s\n' '--label=${config.label}';''}
${lib.concatMapStrings (args: ''printf '%s\n' '${args}';'') config.extraFormatArgs}
printf '%s\n' '${config.device}';
} >> "$disko_devices_dir/bcachefs-${lib.escapeShellArg config.filesystem}";
'';
};
_mount = diskoLib.mkMountOption {
inherit config options;
# Empty, since mounting will be handled by the bcachefs_filesystem type defined in bcachefs_filesystem.nix.
default = { };
};
_unmount = diskoLib.mkUnmountOption {
inherit config options;
# Empty, since unmounting will be handled by the bcachefs_filesystem type defined in bcachefs_filesystem.nix.
default = { };
};
_config = lib.mkOption {
internal = true;
readOnly = true;
# Empty, since NixOS configuration will be handled by the bcachefs_filesystem type defined in bcachefs_filesystem.nix.
default = { };
description = "NixOS configuration.";
};
_pkgs = lib.mkOption {
internal = true;
readOnly = true;
type = lib.types.functionTo (lib.types.listOf lib.types.package);
default = pkgs: [ ];
description = "Packages.";
};
};
}