{ 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; secrets = config.age.secrets; mountOptions = { uid, gid, ... }: [ "x-systemd.automount" "auto" "x-systemd.device-timeout=5s" "x-systemd.mount-timeout=5s" "credentials=${secrets.storage-box-credentials.path}" ] ++ (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 ]; }; }