nix-community / home-manager

Manage a user environment using Nix [maintainer=@rycee]
https://nix-community.github.io/home-manager/
MIT License
6.68k stars 1.75k forks source link

bug: `autorandr` fails to connect #3883

Closed kylechui closed 1 year ago

kylechui commented 1 year ago

Are you following the right branch?

Is there an existing issue for this?

Issue description

I'm using both programs.autorandr.enable and programs.xrandr.enable. When I plug in my monitor, nothing happens. I did a bit of investigating by checking the output of autorandr docked, and got:

Failed to apply profile 'docked' (line 1018; /nix/store/p7lrm3nwbwjax7ivaww3nqjk4p59yssk-autorandr-1.13.3/bin/.autorandr-wrapped):
  Command failed: /nix/store/8bpn74k49bp2jslpnisxg1xc7c4j95ap-xrandr-1.5.1/bin/xrandr --fb 2560x1440 --output DP-1 --gamma 1.0:1.0:1.0 --mode 2560x1440 --primary --rate 71.97 --reflect normal --rotate normal (line 1018; /nix/store/p7lrm3nwbwjax7ivaww3nqjk4p59yssk-autorandr-1.13.3/bin/.autorandr-wrapped)

Retrying the command yields the same result, and it seems that I have to "refresh" something by running xrandr --auto before I am able to use autorandr --change. I imagine that if the error didn't happen, then I wouldn't even need to run autorandr commands manually and that things would "just work". Additionally, the same error occurs if I unplug my monitor:

Please let me know if I'm missing any details!

Maintainer CC

@GaetanLepage @uvNikita

System information

- system: `"x86_64-linux"`
 - host os: `Linux 6.1.23, NixOS, 23.05 (Stoat), 23.05.20230411.3fb8eed`
 - multi-user?: `yes`
 - sandbox: `yes`
 - version: `nix-env (Nix) 2.13.3`
 - channels(root): `"home-manager-22.11.tar.gz, nixos-22.11"`
 - nixpkgs: `/nix/var/nix/profiles/per-user/root/channels/nixos`
GaetanLepage commented 1 year ago

I use autorandr regularly and have no problem with it. Although I have xrandr in my PATH, I have not enabled it through home-manager. What are you referring to by programs.xrandr.enable ? I don't see such option in neither home-manager nor NixOS...

Despite all that, if running the autorandr command by hand fails as well, then the problem does not come from the home-manager autorandr module I guess. Have you try to re-create an autorandr profile from scratch and apply it ?

kylechui commented 1 year ago

Sorry for the typo, I meant I have both services.autorandr.enable = true and programs.autorandr.enable = true. I also have xrandr on my PATH. Running the command autorandr mobile without unplugging my monitor works just fine, and then if I do autorandr docked right after that switches it back to my monitor. The issue is that when I unplug my monitor from my laptop (FWIW I am using a USB-C hub for this), the profile does change to mobile, but the display for my laptop stays off. Similarly, when I replug my monitor, both displays remain off (even though the profile changes back to docked). I then have to do something like autorandr --change to force it to "update" and match the profile. Hopefully I am making things more clear, sorry for the confusion.

Here is my current configuration if that helps: dotfiles link

GaetanLepage commented 1 year ago

Well, setting services.autorandr.enable = true will automate the launch of autorandr only when you log in to your session. The HM module is not setting other automation that run autorandr automatically when you plug/unplug a monitor. It is then normal to have to run autorandr --change explicitly when you need to.

Now, if autorandr --change fails, that is another story. Then, you have to check if the equivalent xrandr command fails as well. Sorry if I don't understand your question ^^

kylechui commented 1 year ago

Ah I see, I think I completely misunderstood the purpose of autorandr; it just allows you to detect the current state of what displays are connected, not actually change the active displays (which needs to be done manually). Sorry for the noise!

GaetanLepage commented 1 year ago

Ah I see, I think I completely misunderstood the purpose of autorandr; it just allows you to detect the current state of what displays are connected, not actually change the active displays (which needs to be done manually). Sorry for the noise!

Indeed. It detects which profile to apply and apply it (when invoked with --change) when you run it. Basically, autorandr is nothing more than a script, so you have to explicitly call it for it to do anything.

Having said that, you can add a layer of automation to make it run "automatically". That was the idea of the services.autorandr home-manager module. The limitation was the lack of a systemd hook that gets triggered when you (un)plug a screen. Hence, the only automation that we were able to achieve is that autorandr is run when you log in into your session. Relevant discussion: https://github.com/nix-community/home-manager/pull/3623#discussion_r1088394080