From cabf9ddd98a6da0806bfab13824f5f326ae54686 Mon Sep 17 00:00:00 2001 From: Nikita Uvarov Date: Sun, 1 Nov 2020 12:28:27 +0100 Subject: [PATCH] caffeine: add service --- .github/CODEOWNERS | 2 ++ modules/misc/news.nix | 8 ++++++++ modules/modules.nix | 1 + modules/services/caffeine.nix | 33 +++++++++++++++++++++++++++++++++ 4 files changed, 44 insertions(+) create mode 100644 modules/services/caffeine.nix diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index b922114a..a5e943be 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -136,6 +136,8 @@ /modules/programs/zsh/prezto.nix @NickHu +/modules/services/caffeine.nix @uvNikita + /modules/services/cbatticon.nix @pmiddend /modules/services/clipmenu.nix @DamienCassou diff --git a/modules/misc/news.nix b/modules/misc/news.nix index 3e5d8d52..92e716b4 100644 --- a/modules/misc/news.nix +++ b/modules/misc/news.nix @@ -1720,6 +1720,14 @@ in A new module is available: 'programs.gh'. ''; } + + { + time = "2020-11-01T11:17:02+00:00"; + condition = hostPlatform.isLinux; + message = '' + A new module is available: 'services.caffeine'. + ''; + } ]; }; } diff --git a/modules/modules.nix b/modules/modules.nix index 26e6d14b..75145e48 100644 --- a/modules/modules.nix +++ b/modules/modules.nix @@ -132,6 +132,7 @@ let (loadModule ./programs/zsh.nix { }) (loadModule ./programs/zsh/prezto.nix { }) (loadModule ./services/blueman-applet.nix { }) + (loadModule ./services/caffeine.nix { condition = hostPlatform.isLinux; }) (loadModule ./services/cbatticon.nix { condition = hostPlatform.isLinux; }) (loadModule ./services/clipmenu.nix { condition = hostPlatform.isLinux; }) (loadModule ./services/compton.nix { }) diff --git a/modules/services/caffeine.nix b/modules/services/caffeine.nix new file mode 100644 index 00000000..bb24a0e0 --- /dev/null +++ b/modules/services/caffeine.nix @@ -0,0 +1,33 @@ +{ config, lib, pkgs, ... }: + +with lib; + +let + + cfg = config.services.caffeine; + +in { + meta.maintainers = [ maintainers.uvnikita ]; + + options = { + services.caffeine = { enable = mkEnableOption "Caffeine service"; }; + }; + + config = mkIf cfg.enable { + systemd.user.services.caffeine = { + Unit = { Description = "caffeine"; }; + + Install = { WantedBy = [ "graphical-session.target" ]; }; + + Service = { + Restart = "on-failure"; + PrivateTmp = true; + ProtectSystem = "full"; + ProtectHome = "yes"; + Type = "exec"; + Slice = "session.slice"; + ExecStart = "${pkgs.caffeine-ng}/bin/caffeine"; + }; + }; + }; +}