From 0fe984d575b2d0b65cd5e639eb1ccaab21d0862d Mon Sep 17 00:00:00 2001 From: dawidsowa Date: Thu, 30 Apr 2020 15:54:54 +0200 Subject: [PATCH] tmpfiles: add module PR #1144 --- .github/CODEOWNERS | 2 ++ modules/misc/tmpfiles.nix | 49 +++++++++++++++++++++++++++++++++++++++ modules/modules.nix | 1 + 3 files changed, 52 insertions(+) create mode 100644 modules/misc/tmpfiles.nix diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 1c88f0094..ab79da03e 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -18,6 +18,8 @@ /modules/misc/submodule-support.nix @rycee +/modules/misc/tmpfiles.nix @dawidsowa + /modules/misc/xdg-mime-apps.nix @pacien /modules/misc/xdg-user-dirs.nix @pacien diff --git a/modules/misc/tmpfiles.nix b/modules/misc/tmpfiles.nix new file mode 100644 index 000000000..c46fe2c55 --- /dev/null +++ b/modules/misc/tmpfiles.nix @@ -0,0 +1,49 @@ +{ config, lib, pkgs, ... }: + +with lib; + +let + + cfg = config.systemd.user.tmpfiles; + +in { + meta.maintainers = [ maintainers.dawidsowa ]; + + options.systemd.user.tmpfiles.rules = mkOption { + type = types.listOf types.str; + default = [ ]; + example = [ "L /home/user/Documents - - - - /mnt/data/Documents" ]; + description = '' + Rules for creating and cleaning up temporary files + automatically. See + + tmpfiles.d + 5 + + for the exact format. + ''; + }; + + config = mkIf (cfg.rules != [ ]) { + xdg = { + dataFile."user-tmpfiles.d/home-manager.conf" = { + text = '' + # This file is created automatically and should not be modified. + # Please change the option ‘systemd.user.tmpfiles.rules’ instead. + ${concatStringsSep "\n" cfg.rules} + ''; + onChange = "${pkgs.systemd}/bin/systemd-tmpfiles --user --create"; + }; + configFile = { + "systemd/user/basic.target.wants/systemd-tmpfiles-setup.service".source = + "${pkgs.systemd}/example/systemd/user/systemd-tmpfiles-setup.service"; + "systemd/user/systemd-tmpfiles-setup.service".source = + "${pkgs.systemd}/example/systemd/user/systemd-tmpfiles-setup.service"; + "systemd/user/timers.target.wants/systemd-tmpfiles-clean.timer".source = + "${pkgs.systemd}/example/systemd/user/systemd-tmpfiles-clean.timer"; + "systemd/user/systemd-tmpfiles-clean.service".source = + "${pkgs.systemd}/example/systemd/user/systemd-tmpfiles-clean.service"; + }; + }; + }; +} diff --git a/modules/modules.nix b/modules/modules.nix index d07531009..1ca6fe4cf 100644 --- a/modules/modules.nix +++ b/modules/modules.nix @@ -36,6 +36,7 @@ let (loadModule ./misc/pam.nix { }) (loadModule ./misc/qt.nix { }) (loadModule ./misc/submodule-support.nix { }) + (loadModule ./misc/tmpfiles.nix { condition = hostPlatform.isLinux; }) (loadModule ./misc/version.nix { }) (loadModule ./misc/xdg-mime.nix { condition = hostPlatform.isLinux; }) (loadModule ./misc/xdg-mime-apps.nix { condition = hostPlatform.isLinux; })