diff --git a/files/autorandr.txt b/files/autorandr.txt new file mode 100644 index 0000000..6a997bf --- /dev/null +++ b/files/autorandr.txt @@ -0,0 +1,3 @@ +main: renaming display Left to DisplayPort-2 +main: renaming display Right to HDMI-A-0 +main (detected) diff --git a/misc/nix.nix b/misc/nix.nix index 0a5a629..0123d39 100644 --- a/misc/nix.nix +++ b/misc/nix.nix @@ -6,6 +6,15 @@ args @ { pkgs, ... }: "freeimage-unstable-2021-11-01" ]; + home-manager.users.krizej.home.packages = [ + (pkgs.writeShellScriptBin "rebuild" '' + # hack: update autorandr stuffs + autorandr --match-edid --dry-run &> ~/nix/files/autorandr.txt + + sudo nixos-rebuild switch --flake ~/nix --show-trace -v + '') + ]; + nixpkgs.overlays = import ../pkgs args; nixpkgs.config.allowUnfree = true; } diff --git a/misc/system.nix b/misc/system.nix index 2bf7243..6e144a1 100644 --- a/misc/system.nix +++ b/misc/system.nix @@ -1,4 +1,4 @@ -{ pkgs, ... }: +args @ { pkgs, ... }: { boot = { loader = { @@ -12,9 +12,11 @@ }; }; # this doesn't even work - kernelParams = [ - "video=DP-3:1920x1080@240" - "video=HDMI-1:1920x1080@75" + kernelParams = let + monitors = import ../utils/monitors.nix args; + in [ + "video=${monitors.left}:1920x1080@240" + "video=${monitors.right}:1920x1080@75" ]; initrd.kernelModules = [ "amdgpu" ]; }; @@ -28,6 +30,12 @@ system.stateVersion = "23.11"; + system.userActivationScripts = { + test2 = '' + ${pkgs.autorandr}/bin/autorandr --match-edid --dry-run &> /home/krizej/dupaa + ''; + }; + users.users.krizej = { isNormalUser = true; extraGroups = [ "wheel" "input" ]; diff --git a/programs/i3.nix b/programs/i3.nix index 4d0ae99..c2fbec3 100644 --- a/programs/i3.nix +++ b/programs/i3.nix @@ -51,8 +51,8 @@ in { defaultWorkspace = "workspace number 1"; workspaceOutputAssign = [ - { workspace = "1"; output = "DisplayPort-2"; } # monitors.left; } - { workspace = "2"; output = "HDMI-A-0"; } # monitors.right; } + { workspace = "1"; output = monitors.left; } + { workspace = "2"; output = monitors.right; } ]; focus = { @@ -241,7 +241,6 @@ in { home.file = { ".config/i3/workspace2.json".source = ../files/workspace2.json; ".config/i3/i3gtk.css".source = ../files/i3gtk.css; - "dupa".text = "[${monitors.left}][${monitors.right}]"; }; }; } diff --git a/services/xserver.nix b/services/xserver.nix index 7ab315f..cac1a6d 100644 --- a/services/xserver.nix +++ b/services/xserver.nix @@ -7,6 +7,7 @@ displayManager = { # THIS SHIT DOESN'T WORK!!! + # TODO: REPLACE MONITOR NAMES HERE WHEN I START CARING setupCommands = '' xrandr --output DP-3 --mode 1920x1080 --rate 239.76 --primary xrandr --output HDMI-1 --off diff --git a/utils/monitors.nix b/utils/monitors.nix index 3e9ba7e..a6f3b40 100644 --- a/utils/monitors.nix +++ b/utils/monitors.nix @@ -1,32 +1,23 @@ -# fixme: when rebuiling the commands are ran as some nixos builder user probably and autorandr does not use my config -# fixme: main issue here is that xrandr can't open a display as the nixbld user -{ pkgs, ... }: let - autorandr = "${pkgs.autorandr}/bin/autorandr"; +# problem: +# fucking xorg changes my output names randomly !!! +# solution: +# 1. i use the `rebuild` command to rebuild my nixos system (see misc/nix.nix) +# 2. that command updates the file files/autorandr.txt BEFORE running nixos-rebuild +# 3. i extract the corrected monitor names and set them to `left` and `right` in this attrset +{ pkgs, lib, ... }: let + # thanks to poz for the base of this run function thing + inherit (pkgs) runCommand; + inherit (lib) fileContents; + run = script: fileContents (runCommand "run" { AUTORANDR_TXT = fileContents ../files/autorandr.txt; } '' + bash -c '${script}' > $out + ''); + printf = "${pkgs.coreutils-full}/bin/printf"; # echo removes the newlines or some shit rg = "${pkgs.ripgrep}/bin/rg"; rev = "${pkgs.util-linux}/bin/rev"; cut = "${pkgs.coreutils-full}/bin/cut"; - xrandr = "${pkgs.xorg.xrandr}/bin/xrandr"; - # epically stolen from https://git.jacekpoz.pl/jacekpoz/nte/src/branch/master/stdlib.nix - # and modified - inherit (pkgs) lib runCommandLocal; - inherit (lib.strings) readFile; - run = script: readFile (runCommandLocal "run" {} '' - bash -c '${script}' &> $out || true - ''); 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 "XDG_CONFIG_HOME=/home/krizej/.config/; ${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}"; - -right = run '' - mkdir autorandr - mkdir autorandr/main - touch autorandr/main/config - touch autorandr/main/status - PATH=$PATH:${pkgs.xorg.xrandr}/bin; ${autorandr} --list - ''; - - left = ""; + left = run "${printf} \"$AUTORANDR_TXT\" | ${rg} Left | ${rev} | ${cut} -d\" \" -f1 | ${rev}"; + right = run "${printf} \"$AUTORANDR_TXT\" | ${rg} Right | ${rev} | ${cut} -d\" \" -f1 | ${rev}"; }