-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add bcachefs module and mount point configurations
- Loading branch information
Showing
6 changed files
with
118 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
{ | ||
inputs, | ||
cell, | ||
}: { | ||
pkgs, | ||
lib, | ||
config, | ||
... | ||
}: let | ||
l = builtins // lib; | ||
|
||
bcachefsFileSystem = { | ||
name, | ||
config, | ||
... | ||
}: { | ||
options = { | ||
devices = l.mkOption { | ||
type = l.types.listOf l.types.path; | ||
description = lib.mdDoc "The devices to use for the filesystem."; | ||
}; | ||
|
||
options = l.mkOption { | ||
type = l.types.listOf l.types.str; | ||
default = []; | ||
description = lib.mdDoc "Additional options to pass to `mount`."; | ||
}; | ||
}; | ||
}; | ||
|
||
pathToString = path: l.replaceStrings ["/"] ["-"] (l.toString path); | ||
|
||
mkUnit = mountPoint: mountOptions: let | ||
inherit (mountOptions) devices options; | ||
deviceTargets = l.pipe devices [ | ||
(l.map pathToString) | ||
(l.map (l.removePrefix "-")) | ||
(l.map (device: "${device}.device")) | ||
]; | ||
concatDevices = l.concatStringsSep ":" (l.map l.toString devices); | ||
concatOptions = l.concatStringsSep "," options; | ||
in { | ||
description = "Mount bcachefs volume ${mountPoint}"; | ||
bindsTo = deviceTargets; | ||
after = deviceTargets ++ ["local-fs-pre.target"]; | ||
before = ["umount.target" "local-fs.target"]; | ||
conflicts = ["umount.target"]; | ||
wantedBy = ["local-fs.target"]; | ||
unitConfig = { | ||
RequiresMountsFor = mountPoint; | ||
DefaultDependencies = false; | ||
}; | ||
serviceConfig = { | ||
Type = "oneshot"; | ||
RemainAfterExit = true; | ||
ExecStart = "${pkgs.util-linux}/bin/mount -t bcachefs -o ${concatOptions} ${concatDevices} ${mountPoint}"; | ||
ExecStop = "${pkgs.util-linux}/umount ${mountPoint}"; | ||
}; | ||
}; | ||
in { | ||
options = { | ||
bcachefs.fileSystems = l.mkOption { | ||
default = {}; | ||
example = l.literalExpression '' | ||
{ | ||
"/data" = { | ||
device = [ "/dev/sda1" "/dev/sdb1" ]; | ||
options = [ "noatime" ]; | ||
}; | ||
} | ||
''; | ||
type = l.types.attrsOf (l.types.submodule [bcachefsFileSystem]); | ||
}; | ||
}; | ||
|
||
config = { | ||
systemd = { | ||
packages = with pkgs; [bcachefs-tools]; | ||
services = l.mapAttrs' (name: value: | ||
l.nameValuePair | ||
"mount-bcachefs-volume-${pathToString name}" | ||
(mkUnit name value)) | ||
config.bcachefs.fileSystems; | ||
}; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
inputs, | ||
cell, | ||
}: let | ||
inherit (inputs.cells.common.lib) importModules; | ||
in | ||
importModules { | ||
src = ./modules; | ||
args = {inherit inputs cell;}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters