summaryrefslogtreecommitdiffstats
path: root/nixos/modules/programs/wayland/kanshi.nix
blob: 3ad20dfcb7f62c5d92fa843cb1a22a9b86fa388c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
{
  config,
  pkgs,
  lib,
  ...
}:

let
  cfg = config.services.kanshi;
in
{
  options.services.kanshi = {
    enable = lib.mkEnableOption "kanshi, a Wayland daemon that automatically configures outputs";
    package = lib.mkPackageOption pkgs "kanshi" { };
    systemd.target = lib.mkOption {
      type = lib.types.str;
      description = ''
        The systemd target that will automatically start the Kanshi service.
      '';
      default = "graphical-session.target";
    };
  };
  config = lib.mkIf cfg.enable {
    environment.systemPackages = [ pkgs.kanshi ];

    systemd.user.services.kanshi = {
      unitConfig = {
        Description = "Dynamic output configuration";
        Documentation = "man:kanshi(1)";
        ConditionEnvironment = "WAYLAND_DISPLAY";
        PartOf = cfg.systemd.target;
        Requires = cfg.systemd.target;
        After = cfg.systemd.target;
      };

      serviceConfig = {
        Type = "simple";
        ExecStart = "${lib.getExe cfg.package}";
        Restart = "always";
      };

      wantedBy = [ cfg.systemd.target ];
    };
  };
  meta.maintainers = [ lib.maintainers.macaquinyho ];
}