diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 5967e4f43..4a66e1a78 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -194,6 +194,9 @@ /modules/services/pasystray.nix @pltanton +/modules/services/pbgopy.nix @ivarwithoutbones +/tests/modules/services/pbgopy @ivarwithoutbones + /modules/services/pulseeffects.nix @jonringer /modules/services/random-background.nix @rycee diff --git a/modules/misc/news.nix b/modules/misc/news.nix index 96bd94fe7..1cab8d89b 100644 --- a/modules/misc/news.nix +++ b/modules/misc/news.nix @@ -1767,6 +1767,14 @@ in A new module is available: 'services.wlsunset'. ''; } + + { + time = "2020-12-09T22:34:33+00:00"; + condition = hostPlatform.isLinux; + message = '' + A new module is available: 'services.pbgopy'. + ''; + } ]; }; } diff --git a/modules/modules.nix b/modules/modules.nix index b599fe990..8ecdc462a 100644 --- a/modules/modules.nix +++ b/modules/modules.nix @@ -169,6 +169,7 @@ let (loadModule ./services/parcellite.nix { }) (loadModule ./services/password-store-sync.nix { condition = hostPlatform.isLinux; }) (loadModule ./services/pasystray.nix { }) + (loadModule ./services/pbgopy.nix { condition = hostPlatform.isLinux; }) (loadModule ./services/picom.nix { }) (loadModule ./services/polybar.nix { }) (loadModule ./services/pulseeffects.nix { condition = hostPlatform.isLinux; }) diff --git a/modules/services/pbgopy.nix b/modules/services/pbgopy.nix new file mode 100644 index 000000000..a95ad959f --- /dev/null +++ b/modules/services/pbgopy.nix @@ -0,0 +1,40 @@ +{ config, lib, pkgs, ... }: + +with lib; + +let + cfg = config.services.pbgopy; + package = pkgs.pbgopy; +in { + meta.maintainers = [ maintainers.ivar ]; + + options.services.pbgopy = { + enable = mkEnableOption "pbgopy"; + + cache.ttl = mkOption { + type = types.str; + default = "24h"; + example = "10m"; + description = '' + The TTL for the cache. Use "0s" to disable it. + ''; + }; + }; + + config = mkIf cfg.enable { + home.packages = [ package ]; + + systemd.user.services.pbgopy = { + Unit = { + Description = "pbgopy server for sharing the clipboard between devices"; + After = [ "graphical-session-pre.target" ]; + PartOf = [ "graphical-session.target" ]; + }; + Service = { + ExecStart = "${package}/bin/pbgopy serve --ttl ${cfg.cache.ttl}"; + Restart = "on-abort"; + }; + Install = { WantedBy = [ "graphical-session.target" ]; }; + }; + }; +} diff --git a/tests/default.nix b/tests/default.nix index 1ce1b5a27..1bc54ec9b 100644 --- a/tests/default.nix +++ b/tests/default.nix @@ -95,6 +95,7 @@ import nmt { ./modules/services/fluidsynth ./modules/services/kanshi ./modules/services/lieer + ./modules/services/pbgopy ./modules/services/polybar ./modules/services/sxhkd ./modules/services/window-managers/i3 diff --git a/tests/modules/services/pbgopy/default.nix b/tests/modules/services/pbgopy/default.nix new file mode 100644 index 000000000..c2c9d485d --- /dev/null +++ b/tests/modules/services/pbgopy/default.nix @@ -0,0 +1 @@ +{ pbgopy = import ./service.nix; } diff --git a/tests/modules/services/pbgopy/service.nix b/tests/modules/services/pbgopy/service.nix new file mode 100644 index 000000000..221214394 --- /dev/null +++ b/tests/modules/services/pbgopy/service.nix @@ -0,0 +1,22 @@ +{ config, pkgs, ... }: { + config = { + services.pbgopy.enable = true; + + nixpkgs.overlays = [ + (self: super: { + pbgopy = pkgs.writeScriptBin "dummy-pbgopy" "" // { + outPath = "@pbgopy@"; + }; + }) + ]; + + nmt.script = '' + serviceFile=home-files/.config/systemd/user/pbgopy.service + + assertFileExists $serviceFile + + assertFileContains $serviceFile \ + 'ExecStart=@pbgopy@/bin/pbgopy serve --ttl 24h' + ''; + }; +}