88 lines
2.3 KiB
Nix
88 lines
2.3 KiB
Nix
{ lib, config, ... }:
|
|
let
|
|
inherit (lib) types mkOption;
|
|
cfg = config.valhalla.fileSystems;
|
|
|
|
mountType = types.submodule (
|
|
{ config, name, ... }: {
|
|
options = {
|
|
device = mkOption {
|
|
type = types.nullOr types.str;
|
|
description = "The device to mount.";
|
|
default = null;
|
|
};
|
|
|
|
mountPoint = mkOption {
|
|
type = types.str;
|
|
description = "The path to mount the device to.";
|
|
default = name;
|
|
};
|
|
|
|
fsType = mkOption {
|
|
type = types.nullOr types.str;
|
|
description = "The file system type of the mount.";
|
|
default = null;
|
|
};
|
|
|
|
options = mkOption {
|
|
type = types.listOf types.str;
|
|
description = "The options of the mount.";
|
|
default = [ ];
|
|
};
|
|
};
|
|
}
|
|
);
|
|
in
|
|
{
|
|
imports = [
|
|
./fileSystems/btrfs.nix
|
|
./fileSystems/disks.nix
|
|
];
|
|
|
|
options = {
|
|
valhalla = {
|
|
|
|
fileSystems = {
|
|
mounts = mkOption {
|
|
type = types.attrsOf mountType;
|
|
description = "The devices to mount.";
|
|
default = { };
|
|
};
|
|
|
|
script = mkOption {
|
|
type = types.str;
|
|
description = "The script for preparing the system's mounts.";
|
|
};
|
|
};
|
|
};
|
|
};
|
|
|
|
config = {
|
|
valhalla = {
|
|
fileSystems = {
|
|
script =
|
|
let
|
|
devices = (builtins.attrValues cfg.diskSetup.devices);
|
|
in
|
|
''
|
|
#!/bin/bash
|
|
set -o errexit
|
|
${cfg.diskSetup.scripts.init}
|
|
${lib.strings.concatLines (lib.optionals ((builtins.length devices) > 0) [
|
|
''echo $(tput setaf 3)=== WARNING ====$(jtput sgr0)"''
|
|
(''echo "Continuing this script will alter the partitions of ''
|
|
+ (lib.strings.concatStringsSep ", " (builtins.map (_: "${_.deviceVariable}") (lib.lists.init devices)))
|
|
+ (if (builtins.length devices) > 1 then " and " else "") + (lib.lists.last devices).deviceVariable + ''"'')
|
|
''
|
|
if ! fish ${./fileSystems/confirm.fish} "Are you sure you want to continue?" "n"; then
|
|
exit 1
|
|
fi
|
|
''
|
|
])}
|
|
${cfg.diskSetup.scripts.partition}
|
|
${cfg.diskSetup.scripts.mount}
|
|
'';
|
|
};
|
|
};
|
|
};
|
|
}
|