aboutsummaryrefslogtreecommitdiff
path: root/nixos/serverModules/directories.nix
diff options
context:
space:
mode:
authorspl3g <spleefer6@yandex.ru>2025-10-27 23:33:33 +0300
committerspl3g <spleefer6@yandex.ru>2025-10-27 23:33:33 +0300
commite6f739deb5369556f2895b523ffa1b02b74c60b1 (patch)
tree3a3f0a983b3452b1573f894eb6c3319e17edad84 /nixos/serverModules/directories.nix
parent7c6e3be17875286d25a8ec2a2ad7c71c56258250 (diff)
feat: rewrite files to be more generic
Diffstat (limited to 'nixos/serverModules/directories.nix')
-rw-r--r--nixos/serverModules/directories.nix90
1 files changed, 90 insertions, 0 deletions
diff --git a/nixos/serverModules/directories.nix b/nixos/serverModules/directories.nix
new file mode 100644
index 0000000..f5c769f
--- /dev/null
+++ b/nixos/serverModules/directories.nix
@@ -0,0 +1,90 @@
+{
+ config,
+ lib,
+ ...
+}:
+with lib; let
+ cfg = config.createPaths;
+ pathAttrsToListRec = pathsAttrSet: parentPath: parentConfig:
+ lib.flatten (lib.mapAttrsToList (path: config: let
+ filteredConfig = lib.filterAttrs (n: v: v != null) (builtins.removeAttrs config ["subPaths"]);
+ out =
+ {
+ path =
+ if parentPath == ""
+ then path
+ else parentPath + "/" + path;
+ }
+ // parentConfig // filteredConfig;
+ in
+ if config ? subPaths
+ then [out] ++ (pathAttrsToListRec config.subPaths path filteredConfig)
+ else [out])
+ pathsAttrSet);
+ pathConfig = {
+ options = {
+ group = mkOption {
+ type = types.nullOr types.str;
+ default = null;
+ };
+ owner = mkOption {
+ type = types.nullOr types.str;
+ default = null;
+ };
+ permissions = mkOption {
+ type = types.nullOr types.str;
+ default = null;
+ };
+ subPaths = mkOption {
+ type = types.attrsOf (types.submodule pathConfig);
+ default = {};
+ };
+ };
+ };
+ pathList = pathAttrsToListRec cfg "" {};
+in rec {
+ options = {
+ createPaths = mkOption {
+ type = types.attrsOf (types.submodule {
+ options = {
+ group = mkOption {
+ type = types.nullOr types.str;
+ default = null;
+ };
+ owner = mkOption {
+ type = types.nullOr types.str;
+ default = null;
+ };
+ permissions = mkOption {
+ type = types.nullOr types.str;
+ default = null;
+ };
+ subPaths = mkOption {
+ type = types.attrsOf (types.submodule pathConfig);
+ default = {};
+ description = ''
+ SubPaths to create using systemd tmpfiles.
+ '';
+ };
+ };
+ });
+ default = {};
+ description = ''
+ Paths to create using systemd tmpfiles.
+ '';
+ };
+ };
+
+ config = mkIf (cfg != {}) {
+ systemd.tmpfiles.rules =
+ map
+ (dir: "d ${dir.path} ${dir.permissions} ${dir.owner} ${dir.group}")
+ pathList;
+
+ users = let
+ extraGroups = map (path: path.group) pathList;
+ in {
+ groups = genAttrs extraGroups (group: {});
+ };
+ };
+}