108 lines
2.7 KiB
Nix
108 lines
2.7 KiB
Nix
{ lib, config, ... }:
|
|
let
|
|
inherit (lib) types mkOption;
|
|
cfg = config.valhalla.fileSystems.btrfs;
|
|
|
|
profileType = types.enum [
|
|
"raid0"
|
|
"raid1"
|
|
"raid1c3"
|
|
"raid1c4"
|
|
"raid5"
|
|
"raid6"
|
|
"raid10"
|
|
"dup"
|
|
"single"
|
|
];
|
|
|
|
volumeType = types.submodule (
|
|
{ config, name, ... }: {
|
|
options = {
|
|
mountPoint = mkOption {
|
|
type = types.nullOr types.str;
|
|
description = "The path to mount the volume to.";
|
|
default = null;
|
|
};
|
|
|
|
devices = mkOption {
|
|
type = types.listOf types.str;
|
|
description = "The devices of the btrfs volume.";
|
|
};
|
|
|
|
label = mkOption {
|
|
type = types.nullOr types.str;
|
|
description = "The label of the volume.";
|
|
default = name;
|
|
};
|
|
|
|
dataProfile = mkOption {
|
|
type = types.nullOr profileType;
|
|
description = "The data profile.";
|
|
default = null;
|
|
};
|
|
|
|
metadataProfile = mkOption {
|
|
type = types.nullOr profileType;
|
|
description = "The metadata profile.";
|
|
default = null;
|
|
};
|
|
};
|
|
}
|
|
);
|
|
in
|
|
{
|
|
options = {
|
|
valhalla = {
|
|
fileSystems.btrfs = {
|
|
volumes = mkOption {
|
|
type = types.attrsOf volumeType;
|
|
description = "The btrfs volumes of the system.";
|
|
default = { };
|
|
};
|
|
|
|
script = mkOption {
|
|
type = types.str;
|
|
description = "The script for creating the btrfs volumes.";
|
|
default = lib.strings.concatLines (
|
|
builtins.map
|
|
(
|
|
_: builtins.concatStringsSep " " (
|
|
[ "mkfs.btrfs" "--force" ] ++
|
|
(lib.optionals (_.metadataProfile != null) [ "--metadata" "${_.metadataProfile}" ]) ++
|
|
(lib.optionals (_.dataProfile != null) [ "--data" "${_.dataProfile}" ]) ++
|
|
(lib.optionals (_.label != null) [ "--label" "${_.label}" ]) ++
|
|
_.devices
|
|
)
|
|
)
|
|
(builtins.attrValues cfg.volumes)
|
|
);
|
|
};
|
|
};
|
|
};
|
|
};
|
|
|
|
config = {
|
|
valhalla = {
|
|
linux.programs.btrfs = lib.optionalAttrs
|
|
(builtins.any
|
|
(_: (builtins.length _.devices) > 1)
|
|
(builtins.attrValues cfg.volumes))
|
|
{
|
|
enable = true;
|
|
pools = true;
|
|
};
|
|
|
|
fileSystems.mounts = lib.attrsets.concatMapAttrs
|
|
(
|
|
name: volume:
|
|
if (volume.mountPoint != null) then {
|
|
${volume.mountPoint} = {
|
|
device = builtins.elemAt volume.devices 0;
|
|
fsType = "btrfs";
|
|
};
|
|
} else { }
|
|
)
|
|
cfg.volumes;
|
|
};
|
|
};
|
|
}
|