Files
nixos/modules/storage-box-mounts.nix
Joakim Repomaa 913d3d1238 refactor
2025-02-08 21:17:11 +02:00

56 lines
1.3 KiB
Nix

{ 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 ];
};
}