fork/home-manager

git clone https://git.julia.blue/fork/home-manager

Robert HelgessonMerge PR #421575790441

master
1.6 KiB73 linesraw
1{ config, lib, pkgs, ... }:
2
3with lib;
4
5let
6
7  cfg = config.services.pbgopy;
8  package = pkgs.pbgopy;
9
10  commandLine = concatStringsSep " " ([
11    "${package}/bin/pbgopy serve"
12    "--port ${toString cfg.port}"
13    "--ttl ${cfg.cache.ttl}"
14  ] ++ optional (cfg.httpAuth != null)
15    "--basic-auth ${escapeShellArg cfg.httpAuth}");
16
17in {
18  meta.maintainers = [ maintainers.ivar ];
19
20  options.services.pbgopy = {
21    enable = mkEnableOption "pbgopy";
22
23    port = mkOption {
24      type = types.port;
25      default = 9090;
26      example = 8080;
27      description = ''
28        The port to host the pbgopy server on.
29      '';
30    };
31
32    cache.ttl = mkOption {
33      type = types.str;
34      default = "24h";
35      example = "10m";
36      description = ''
37        The TTL for the cache. Use `"0s"` to disable it.
38      '';
39    };
40
41    httpAuth = mkOption {
42      type = types.nullOr types.str;
43      default = null;
44      example = "user:pass";
45      description = ''
46        Basic HTTP authentication's username and password. Both the username and
47        password are escaped.
48      '';
49    };
50  };
51
52  config = mkIf cfg.enable {
53    assertions = [
54      (lib.hm.assertions.assertPlatform "services.pbgopy" pkgs
55        lib.platforms.linux)
56    ];
57
58    home.packages = [ package ];
59
60    systemd.user.services.pbgopy = {
61      Unit = {
62        Description = "pbgopy server for sharing the clipboard between devices";
63        After = [ "graphical-session-pre.target" ];
64        PartOf = [ "graphical-session.target" ];
65      };
66      Service = {
67        ExecStart = commandLine;
68        Restart = "on-abort";
69      };
70      Install = { WantedBy = [ "graphical-session.target" ]; };
71    };
72  };
73}