From b4e8d9869fb229d3159a1c6a00aad81643ee0ce6 Mon Sep 17 00:00:00 2001 From: Marius Bergmann Date: Fri, 27 Dec 2019 10:30:06 +0100 Subject: [PATCH] grobi: add module This adds a service module for [grobi](https://github.com/fd0/grobi), which can be used to automatically configure monitors/outputs for Xorg via RANDR. --- modules/misc/news.nix | 8 +++ modules/modules.nix | 1 + modules/services/grobi.nix | 101 +++++++++++++++++++++++++++++++++++++ 3 files changed, 110 insertions(+) create mode 100644 modules/services/grobi.nix diff --git a/modules/misc/news.nix b/modules/misc/news.nix index d5de389ed..63c865b63 100644 --- a/modules/misc/news.nix +++ b/modules/misc/news.nix @@ -1303,6 +1303,14 @@ in A new module is available: 'xsession.windowManager.bspwm'. ''; } + + { + time = "2020-01-26T12:49:40+00:00"; + condition = hostPlatform.isLinux; + message = '' + A new module is available: 'services.grobi'. + ''; + } ]; }; } diff --git a/modules/modules.nix b/modules/modules.nix index 20ed5fad9..dbb3f1dfe 100644 --- a/modules/modules.nix +++ b/modules/modules.nix @@ -115,6 +115,7 @@ let (loadModule ./services/getmail.nix { condition = hostPlatform.isLinux; }) (loadModule ./services/gnome-keyring.nix { }) (loadModule ./services/gpg-agent.nix { }) + (loadModule ./services/grobi.nix { condition = hostPlatform.isLinux; }) (loadModule ./services/hound.nix { condition = hostPlatform.isLinux; }) (loadModule ./services/imapnotify.nix { condition = hostPlatform.isLinux; }) (loadModule ./services/kbfs.nix { }) diff --git a/modules/services/grobi.nix b/modules/services/grobi.nix new file mode 100644 index 000000000..e910bcdfd --- /dev/null +++ b/modules/services/grobi.nix @@ -0,0 +1,101 @@ +{ config, lib, pkgs, ... }: + +with lib; + +let + + cfg = config.services.grobi; + + eitherStrBoolIntList = + with types; either str (either bool (either int (listOf str))); + +in + +{ + meta.maintainers = [ maintainers.mbrgm ]; + + options = { + services.grobi = { + enable = mkEnableOption "the grobi display setup daemon"; + + executeAfter = mkOption { + type = with types; listOf str; + default = []; + example = [ "setxkbmap dvorak" ]; + description = '' + Commands to be run after an output configuration was + changed. The Nix value declared here will be translated to + JSON and written to the key + in ~/.config/grobi.conf. + ''; + }; + + rules = mkOption { + type = with types; listOf (attrsOf eitherStrBoolIntList); + default = []; + example = literalExample '' + [ + { + name = "Home"; + outputs_connected = [ "DP-2" ]; + configure_single = "DP-2"; + primary = true; + atomic = true; + execute_after = [ + "${pkgs.xorg.xrandr}/bin/xrandr --dpi 96" + "${pkgs.xmonad-with-packages}/bin/xmonad --restart"; + ]; + } + { + name = "Mobile"; + outputs_disconnected = [ "DP-2" ]; + configure_single = "eDP-1"; + primary = true; + atomic = true; + execute_after = [ + "${pkgs.xorg.xrandr}/bin/xrandr --dpi 120" + "${pkgs.xmonad-with-packages}/bin/xmonad --restart"; + ]; + } + ] + ''; + description = '' + These are the rules grobi tries to match to the current + output configuration. The rules are evaluated top to bottom, + the first matching rule is applied and processing stops. See + + for more information. The Nix value declared here will be + translated to JSON and written to the + key in ~/.config/grobi.conf. + ''; + }; + }; + }; + + config = mkIf cfg.enable { + systemd.user.services.grobi = { + Unit = { + Description = "grobi display auto config daemon"; + After = [ "graphical-session-pre.target" ]; + PartOf = [ "graphical-session.target" ]; + }; + + Service = { + Type = "simple"; + ExecStart = "${pkgs.grobi}/bin/grobi watch -v"; + Restart = "always"; + RestartSec = "2s"; + Environment = "PATH=${pkgs.xorg.xrandr}/bin:${pkgs.bash}/bin"; + }; + + Install = { + WantedBy = [ "graphical-session.target" ]; + }; + }; + + xdg.configFile."grobi.conf".text = builtins.toJSON { + execute_after = cfg.executeAfter; + rules = cfg.rules; + }; + }; +}