refactor
This commit is contained in:
55
modules/storage-box-mounts.nix
Normal file
55
modules/storage-box-mounts.nix
Normal file
@@ -0,0 +1,55 @@
|
||||
{ lib, config, pkgs, ... }:
|
||||
let
|
||||
types = {
|
||||
mount = lib.types.submodule {
|
||||
options = {
|
||||
path = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
default = "/";
|
||||
};
|
||||
user = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
};
|
||||
uid = lib.mkOption {
|
||||
type = lib.types.nullOr lib.types.int;
|
||||
default = null;
|
||||
};
|
||||
gid = lib.mkOption {
|
||||
type = lib.types.nullOr lib.types.int;
|
||||
default = null;
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
cfg = config.modules.storageBoxMounts;
|
||||
mountOptions = { uid, gid, ... }: [
|
||||
"x-systemd.automount"
|
||||
"auto"
|
||||
"x-systemd.device-timeout=5s"
|
||||
"x-systemd.mount-timeout=5s"
|
||||
"credentials=/var/secrets/storage-box-credentials"
|
||||
] ++ (
|
||||
if (uid != null) then [ "uid=${toString uid}" ] else [ ]
|
||||
) ++ (
|
||||
if (gid != null) then [ "gid=${toString gid}" ] else [ ]
|
||||
);
|
||||
in
|
||||
{
|
||||
options.modules.storageBoxMounts = lib.mkOption {
|
||||
type = lib.types.attrsOf types.mount;
|
||||
default = { };
|
||||
};
|
||||
|
||||
config = {
|
||||
fileSystems = lib.mapAttrs
|
||||
(_: { path, user, ... }@options: {
|
||||
device = "//${user}.your-storagebox.de${path}";
|
||||
fsType = "cifs";
|
||||
options = mountOptions options;
|
||||
})
|
||||
cfg;
|
||||
|
||||
environment.systemPackages = lib.mkIf ((lib.length (lib.attrNames cfg)) > 0) [ pkgs.cifs-utils ];
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user