aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarius Bergmann <marius@mtbit.de>2019-12-27 10:30:06 +0100
committerRobert Helgesson <robert@rycee.net>2020-01-26 13:57:49 +0100
commitb4e8d9869fb229d3159a1c6a00aad81643ee0ce6 (patch)
treeb8932e093bfa02f187a603440d50e7acb03e935a
parentb270fcef2fdbf9144c1f4b3528d35b455e116082 (diff)
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.
-rw-r--r--modules/misc/news.nix8
-rw-r--r--modules/modules.nix1
-rw-r--r--modules/services/grobi.nix101
3 files changed, 110 insertions, 0 deletions
diff --git a/modules/misc/news.nix b/modules/misc/news.nix
index d5de389edee..63c865b637d 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 20ed5fad9cb..dbb3f1dfee3 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 00000000000..e910bcdfd35
--- /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 <option>execute_after</option> key
+ in <filename>~/.config/grobi.conf</filename>.
+ '';
+ };
+
+ 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
+ <link xlink:href="https://github.com/fd0/grobi/blob/master/doc/grobi.conf"/>
+ for more information. The Nix value declared here will be
+ translated to JSON and written to the <option>rules</option>
+ key in <filename>~/.config/grobi.conf</filename>.
+ '';
+ };
+ };
+ };
+
+ 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;
+ };
+ };
+}