Compare commits

...

2 commits

Author SHA1 Message Date
krizej
abbea019f7 auto monitor name thingy!!!! 2024-07-10 22:10:55 +02:00
krizej
def13f7226 agony 2024-07-10 21:28:29 +02:00
6 changed files with 43 additions and 20 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"
];
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;
}

View file

@ -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" ];

View file

@ -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}]";
};
};
}

View file

@ -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

View file

@ -1,20 +1,23 @@
# 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";
# 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";
# 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}";
left = run "${printf} \"$AUTORANDR_TXT\" | ${rg} Left | ${rev} | ${cut} -d\" \" -f1 | ${rev}";
right = run "${printf} \"$AUTORANDR_TXT\" | ${rg} Right | ${rev} | ${cut} -d\" \" -f1 | ${rev}";
}