auto monitor name thingy!!!!

This commit is contained in:
krizej 2024-07-10 22:10:55 +02:00
parent def13f7226
commit abbea019f7
6 changed files with 43 additions and 32 deletions

3
files/autorandr.txt Normal file
View file

@ -0,0 +1,3 @@
main: renaming display Left to DisplayPort-2
main: renaming display Right to HDMI-A-0
main (detected)

View file

@ -6,6 +6,15 @@ args @ { pkgs, ... }:
"freeimage-unstable-2021-11-01" "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.overlays = import ../pkgs args;
nixpkgs.config.allowUnfree = true; nixpkgs.config.allowUnfree = true;
} }

View file

@ -1,4 +1,4 @@
{ pkgs, ... }: args @ { pkgs, ... }:
{ {
boot = { boot = {
loader = { loader = {
@ -12,9 +12,11 @@
}; };
}; };
# this doesn't even work # this doesn't even work
kernelParams = [ kernelParams = let
"video=DP-3:1920x1080@240" monitors = import ../utils/monitors.nix args;
"video=HDMI-1:1920x1080@75" in [
"video=${monitors.left}:1920x1080@240"
"video=${monitors.right}:1920x1080@75"
]; ];
initrd.kernelModules = [ "amdgpu" ]; initrd.kernelModules = [ "amdgpu" ];
}; };
@ -28,6 +30,12 @@
system.stateVersion = "23.11"; system.stateVersion = "23.11";
system.userActivationScripts = {
test2 = ''
${pkgs.autorandr}/bin/autorandr --match-edid --dry-run &> /home/krizej/dupaa
'';
};
users.users.krizej = { users.users.krizej = {
isNormalUser = true; isNormalUser = true;
extraGroups = [ "wheel" "input" ]; extraGroups = [ "wheel" "input" ];

View file

@ -51,8 +51,8 @@ in {
defaultWorkspace = "workspace number 1"; defaultWorkspace = "workspace number 1";
workspaceOutputAssign = [ workspaceOutputAssign = [
{ workspace = "1"; output = "DisplayPort-2"; } # monitors.left; } { workspace = "1"; output = monitors.left; }
{ workspace = "2"; output = "HDMI-A-0"; } # monitors.right; } { workspace = "2"; output = monitors.right; }
]; ];
focus = { focus = {
@ -241,7 +241,6 @@ in {
home.file = { home.file = {
".config/i3/workspace2.json".source = ../files/workspace2.json; ".config/i3/workspace2.json".source = ../files/workspace2.json;
".config/i3/i3gtk.css".source = ../files/i3gtk.css; ".config/i3/i3gtk.css".source = ../files/i3gtk.css;
"dupa".text = "[${monitors.left}][${monitors.right}]";
}; };
}; };
} }

View file

@ -7,6 +7,7 @@
displayManager = { displayManager = {
# THIS SHIT DOESN'T WORK!!! # THIS SHIT DOESN'T WORK!!!
# TODO: REPLACE MONITOR NAMES HERE WHEN I START CARING
setupCommands = '' setupCommands = ''
xrandr --output DP-3 --mode 1920x1080 --rate 239.76 --primary xrandr --output DP-3 --mode 1920x1080 --rate 239.76 --primary
xrandr --output HDMI-1 --off xrandr --output HDMI-1 --off

View file

@ -1,32 +1,23 @@
# fixme: when rebuiling the commands are ran as some nixos builder user probably and autorandr does not use my config # problem:
# fixme: main issue here is that xrandr can't open a display as the nixbld user # fucking xorg changes my output names randomly !!!
{ pkgs, ... }: let # solution:
autorandr = "${pkgs.autorandr}/bin/autorandr"; # 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"; rg = "${pkgs.ripgrep}/bin/rg";
rev = "${pkgs.util-linux}/bin/rev"; rev = "${pkgs.util-linux}/bin/rev";
cut = "${pkgs.coreutils-full}/bin/cut"; 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 { in {
# this parses "main: renaming display Left to DisplayPort-2" # this parses "main: renaming display Left to DisplayPort-2"
# and i am interested in "DisplayPort-2" # and i am interested in "DisplayPort-2"
# and also it's printed to stderr so 2>&1 left = run "${printf} \"$AUTORANDR_TXT\" | ${rg} Left | ${rev} | ${cut} -d\" \" -f1 | ${rev}";
# left = run "XDG_CONFIG_HOME=/home/krizej/.config/; ${autorandr} --match-edid 2>&1 | ${rg} Left | ${rev} | ${cut} -d\" \" -f1 | ${rev}"; right = run "${printf} \"$AUTORANDR_TXT\" | ${rg} Right | ${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 = "";
} }