fork/home-manager

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

Robert HelgessonMerge PR #421575790441

master
3.0 KiB102 linesraw
1{ config, lib, pkgs, ... }:
2
3with lib;
4
5let
6
7  cfg = config.services.grobi;
8
9  eitherStrBoolIntList = with types;
10    either str (either bool (either int (listOf str)));
11
12in {
13  meta.maintainers = [ maintainers.mbrgm ];
14
15  options = {
16    services.grobi = {
17      enable = mkEnableOption "the grobi display setup daemon";
18
19      executeAfter = mkOption {
20        type = with types; listOf str;
21        default = [ ];
22        example = [ "setxkbmap dvorak" ];
23        description = ''
24          Commands to be run after an output configuration was
25          changed. The Nix value declared here will be translated to
26          JSON and written to the {option}`execute_after` key
27          in {file}`$XDG_CONFIG_HOME/grobi.conf`.
28        '';
29      };
30
31      rules = mkOption {
32        type = with types; listOf (attrsOf eitherStrBoolIntList);
33        default = [ ];
34        example = literalExpression ''
35          [
36            {
37              name = "Home";
38              outputs_connected = [ "DP-2" ];
39              configure_single = "DP-2";
40              primary = true;
41              atomic = true;
42              execute_after = [
43                "${pkgs.xorg.xrandr}/bin/xrandr --dpi 96"
44                "${pkgs.xmonad-with-packages}/bin/xmonad --restart";
45              ];
46            }
47            {
48              name = "Mobile";
49              outputs_disconnected = [ "DP-2" ];
50              configure_single = "eDP-1";
51              primary = true;
52              atomic = true;
53              execute_after = [
54                "${pkgs.xorg.xrandr}/bin/xrandr --dpi 120"
55                "${pkgs.xmonad-with-packages}/bin/xmonad --restart";
56              ];
57            }
58          ]
59        '';
60        description = ''
61          These are the rules grobi tries to match to the current
62          output configuration. The rules are evaluated top to bottom,
63          the first matching rule is applied and processing stops. See
64          <https://github.com/fd0/grobi/blob/master/doc/grobi.conf>
65          for more information. The Nix value declared here will be
66          translated to JSON and written to the {option}`rules`
67          key in {file}`$XDG_CONFIG_HOME/grobi.conf`.
68        '';
69      };
70    };
71  };
72
73  config = mkIf cfg.enable {
74    assertions = [
75      (lib.hm.assertions.assertPlatform "services.grobi" pkgs
76        lib.platforms.linux)
77    ];
78
79    systemd.user.services.grobi = {
80      Unit = {
81        Description = "grobi display auto config daemon";
82        After = [ "graphical-session-pre.target" ];
83        PartOf = [ "graphical-session.target" ];
84      };
85
86      Service = {
87        Type = "simple";
88        ExecStart = "${pkgs.grobi}/bin/grobi watch -v";
89        Restart = "always";
90        RestartSec = "2s";
91        Environment = "PATH=${pkgs.xorg.xrandr}/bin:${pkgs.bash}/bin";
92      };
93
94      Install = { WantedBy = [ "graphical-session.target" ]; };
95    };
96
97    xdg.configFile."grobi.conf".text = builtins.toJSON {
98      execute_after = cfg.executeAfter;
99      rules = cfg.rules;
100    };
101  };
102}