···
+
systemd.tmpfiles.settings = mkOption {
+
description = lib.mdDoc ''
+
Declare systemd-tmpfiles rules to create, delete, and clean up volatile
+
and temporary files and directories.
+
Even though the service is called `*tmp*files` you can also create
+
"/var/lib/my-service/statefolder".d = {
+
type = types.attrsOf (types.attrsOf (types.attrsOf (types.submodule ({ name, config, ... }: {
+
options.type = mkOption {
+
description = lib.mdDoc ''
+
The type of operation to perform on the file.
+
The type consists of a single letter and optionally one or more
+
Please see the upstream documentation for the available types and
+
<https://www.freedesktop.org/software/systemd/man/tmpfiles.d>
+
options.mode = mkOption {
+
description = lib.mdDoc ''
+
The file access mode to use when creating this file or directory.
+
options.user = mkOption {
+
description = lib.mdDoc ''
+
This may either be a numeric ID or a user/group name.
+
If omitted or when set to `"-"`, the user and group of the user who
+
invokes systemd-tmpfiles is used.
+
options.group = mkOption {
+
description = lib.mdDoc ''
+
This may either be a numeric ID or a user/group name.
+
If omitted or when set to `"-"`, the user and group of the user who
+
invokes systemd-tmpfiles is used.
+
options.age = mkOption {
+
description = lib.mdDoc ''
+
Delete a file when it reaches a certain age.
+
If a file or directory is older than the current time minus the age
+
If set to `"-"` no automatic clean-up is done.
+
options.argument = mkOption {
+
description = lib.mdDoc ''
+
An argument whose meaning depends on the type of operation.
+
Please see the upstream documentation for the meaning of this
+
parameter in different situations:
+
<https://www.freedesktop.org/software/systemd/man/tmpfiles.d>
systemd.tmpfiles.packages = mkOption {
type = types.listOf types.package;
···
${concatStringsSep "\n" cfg.rules}
+
] ++ (mapAttrsToList (name: paths:
+
pkgs.writeTextDir "lib/tmpfiles.d/${name}.conf" (concatStrings (mapAttrsToList (path: types:
+
concatStrings (mapAttrsToList (_type: entry: ''
+
'${entry.type}' '${path}' '${entry.mode}' '${entry.user}' '${entry.group}' '${entry.age}' ${entry.argument}
systemd.tmpfiles.rules = [
"d /nix/var 0755 root root - -"