diff options
| author | spl3g <spleefer6@yandex.ru> | 2025-08-22 22:24:50 +0500 |
|---|---|---|
| committer | spl3g <spleefer6@yandex.ru> | 2025-08-22 22:38:35 +0500 |
| commit | c087d476f03b9e94a879ab1fa752ffe90de3e7f9 (patch) | |
| tree | 1b41316e76715648442654bd97b0f7cbca9714b5 /nixos/serverModules/files.nix | |
| parent | c7117141d2f42f5be5006d07e6d6476238fb96e6 (diff) | |
feat: add server modules
Diffstat (limited to 'nixos/serverModules/files.nix')
| -rw-r--r-- | nixos/serverModules/files.nix | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/nixos/serverModules/files.nix b/nixos/serverModules/files.nix new file mode 100644 index 0000000..037d149 --- /dev/null +++ b/nixos/serverModules/files.nix @@ -0,0 +1,59 @@ +{ config, lib, ... }: +with lib; +let + cfg = config.filesDir; +in +{ + options = { + filesDir = { + enable = mkEnableOption "Enable the creation of a main files directory and nfs binds for it."; + mainDir = mkOption { + type = types.str; + default = "/srv/files"; + description = '' + The main file dir. + ''; + }; + subPaths = mkOption { + type = types.listOf (types.submodule { + options = { + path = mkOption { + type = types.str; + }; + + group = mkOption { + type = types.str; + }; + }; + }); + default = []; + description = '' + Subpaths to create under the files dir. + ''; + }; + }; + }; + + config = mkIf cfg.enable { + systemd.tmpfiles.rules = [ + "d ${cfg.mainDir} 0770 files files" + ] ++ (map (dir: "d ${cfg.mainDir}/${dir.path} 0770 files ${dir.group}") cfg.subPaths); + + users = + let + extraGroups = (map (dir: dir.group) cfg.subPaths); + in { + groups = { + files = {}; + } // genAttrs extraGroups (group: {}); + + users.files = { + isNormalUser = true; + group = "files"; + home = cfg.mainDir; + homeMode = "770"; + inherit extraGroups; + }; + }; + }; +} |
