1{ config, lib, pkgs, ... }:
2
3with lib;
4
5let
6
7 cfg = config.services.autorandr;
8
9in {
10
11 options = {
12
13 services.autorandr = {
14 enable = mkEnableOption "handling of hotplug and sleep events by autorandr";
15
16 defaultTarget = mkOption {
17 default = "default";
18 type = types.str;
19 description = ''
20 Fallback if no monitor layout can be detected. See the docs
21 (https://github.com/phillipberndt/autorandr/blob/v1.0/README.md#how-to-use)
22 for further reference.
23 '';
24 };
25 };
26
27 };
28
29 config = mkIf cfg.enable {
30
31 services.udev.packages = [ pkgs.autorandr ];
32
33 environment.systemPackages = [ pkgs.autorandr ];
34
35 systemd.services.autorandr = {
36 wantedBy = [ "sleep.target" ];
37 description = "Autorandr execution hook";
38 after = [ "sleep.target" ];
39
40 serviceConfig = {
41 StartLimitInterval = 5;
42 StartLimitBurst = 1;
43 ExecStart = "${pkgs.autorandr}/bin/autorandr --batch --change --default ${cfg.defaultTarget}";
44 Type = "oneshot";
45 RemainAfterExit = false;
46 };
47 };
48
49 };
50
51 meta.maintainers = with maintainers; [ gnidorah ma27 ];
52}