diff options
| author | Kleidi Bujari <mail@4kb.net> | 2025-01-24 12:14:23 -0500 |
|---|---|---|
| committer | Kleidi Bujari <mail@4kb.net> | 2025-01-24 12:14:23 -0500 |
| commit | 32f4cb5cbba313b7af2fce46139c04d9469cb72a (patch) | |
| tree | 3cc7da05d4320a8f89a726d67811110771dae1bf /machines/xnet/persist.nix | |
| parent | 8271e2b89180578ab4dd9ed9eb37142254e5a148 (diff) | |
| download | depot-32f4cb5cbba313b7af2fce46139c04d9469cb72a.tar.gz depot-32f4cb5cbba313b7af2fce46139c04d9469cb72a.tar.bz2 depot-32f4cb5cbba313b7af2fce46139c04d9469cb72a.zip | |
25-jan sprint
Diffstat (limited to 'machines/xnet/persist.nix')
| -rw-r--r-- | machines/xnet/persist.nix | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/machines/xnet/persist.nix b/machines/xnet/persist.nix new file mode 100644 index 0000000..0ace84f --- /dev/null +++ b/machines/xnet/persist.nix @@ -0,0 +1,61 @@ +{ config, lib, ... }: +let + inherit (lib) + concatLists + isString + mkOption + types + ; + +in +{ + options.xnet.persist = mkOption { + type = types.listOf (types.either + types.str + (types.submodule { + options = { + path = mkOption { + type = types.str; + description = "Path to persist"; + }; + user = mkOption { + type = types.nullOr types.str; + default = null; + description = "User ID to set on the persisted directory"; + }; + group = mkOption { + type = types.nullOr types.str; + default = null; + description = "Group ID to set on the persisted directory"; + }; + + mode = mkOption { + type = types.nullOr types.str; + default = null; + description = "Permissions to set"; + }; + }; + })); + default = [ ]; + description = "Automatically persisted state."; + }; + + config.systemd.tmpfiles.rules = + let + mkEntry = entry: + let + path = if isString entry then entry else entry.path; + user = if isString entry then "-" else entry.user; + group = if isString entry then "-" else entry.group; + mode = if isString entry then "-" else entry.mode; + + dent = "d /persist${path} ${mode} ${user} ${group} - -"; + link = "L ${path} - - - - /persist${path}"; + perm = "Z ${mode} ${user} ${group} - -"; + in + [ dent link perm ]; + + entries = map mkEntry config.xnet.persist; + in + concatLists entries; +} |
