nix/utils/monitors.nix
2024-07-10 19:54:20 +02:00

20 lines
959 B
Nix

# fixme: when rebuiling the commands are ran as some nixos builder user probably and autorandr does not use my config
{ pkgs, ... }: let
autorandr = "${pkgs.autorandr}/bin/autorandr";
rg = "${pkgs.ripgrep}/bin/rg";
rev = "${pkgs.util-linux}/bin/rev";
cut = "${pkgs.coreutils-full}/bin/cut";
# epically stolen from https://git.jacekpoz.pl/jacekpoz/nte/src/branch/master/stdlib.nix
# but i changed lib.strings.readFile to lib.fileContents
inherit (pkgs) lib runCommand;
inherit (lib) fileContents;
run = script: builtins.toString (runCommand "run" {} ''
echo $(${script}) > $out
'');
in {
# this parses "main: renaming display Left to DisplayPort-2"
# and i am interested in "DisplayPort-2"
# and also it's printed to stderr so 2>&1
left = run "${autorandr} --match-edid 2>&1 | ${rg} Left | ${rev} | ${cut} -d' ' -f1 | ${rev}";
right = run "${autorandr} --match-edid 2>&1 | ${rg} Right | ${rev} | ${cut} -d' ' -f1 | ${rev}";
}