Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sway: deterministic .desktop file #89179

Closed
wants to merge 1 commit into from
Closed

Conversation

jlesquembre
Copy link
Member

Motivation for this change

If I use the sway.desktop from this derivation, I'd expect to use the sway binary generated by the derivation, not the one in my path.

I was bitten by this because I'm installing sway with the NixOS option programs.sway.enable and programs.sway.extraSessionCommands, but to manage the sway config file (on ~/.config/sway/config), I use home-manager. Since home-manager is also installing sway in your nix profile, this version has preference, and the commands I specified on the programs.sway.extraSessionCommands were ignored

Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS linux)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Determined the impact on package closure size (by running nix path-info -S before and after)
  • Ensured that relevant documentation is up to date
  • Fits CONTRIBUTING.md.

Copy link
Member

@primeos primeos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The diff LGTM.

This is a bit of an interesting case as this should only work with a login/display manager since they use only the desktop entries from the NixOS configuration. Luckily this is, apart from very special edge-cases, the only situation we care about.
(For normal desktop entries this shouldn't make a difference in this use-case since the user is already logged in the desktop file from ~/.nix-profile/share/applications/ should take precedence over the one in /run/current-system/sw/share/applications/.)

However, the big issue I see here is that, in theory, this should fix your use case but "break" the home-manager module. This is because the home-manager module also implements the options from the NixOS module link (including e.g. extraSessionCommands). And then we should use Sway from the user's path (home-manager) instead of the NixOS module. But please note that I didn't actually test my theory, so I might have missed something.


I think we should resolve this issue together with the home-manager maintainers. I believe the correct solution would be to enable Sway system-wide (programs.sway.enable - see #89019 (comment)) and configure the rest though the home-manager module. If the home-manager maintainers agree with this we should document it in the enable option of the home-manager module.

cc @alexarice, @cole-h, @nurelin (module) @rycee (home-manager): What do you think?

Copy link
Member

@primeos primeos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(forgot to switch to request changes - at least until we resolve the discussion)

@alexarice
Copy link
Contributor

Tbh I'm not sure I've fully grasped what the problem is here, but I'm am using sway from nixos with the config from home-manager and I guess as I wrote the module this is supported usage.

@alexarice
Copy link
Contributor

Any systemd parts of the home manager config are the bits I was least sure of. If you have any suggestions that would improve it (especially with respect to login managers), then I would be happy with it, if home manager maintainers are happy with it

@primeos
Copy link
Member

primeos commented May 30, 2020

@alexarice the relevant part for home-manager is #89019 (comment) to resolve issue nix-community/home-manager#1288 (amongst others). My suggestion would be to document the following in the enable option of the home-manager module for Sway:

@jlesquembre
Copy link
Member Author

To me, there are 2 ways to install sway with home-manager:

  • Use home-manager to manage only the sway config files. In this case, the changes in this PR are needed. (or alternatively add an option to home-manager's module to install sway optionally)

  • Manage sway only with home-manager. I don't like this options too much, because to me it looks like a duplication of effort between NixOS and home-manager, and also because I think it is easier to manage the integration between sway and a display manager in NixOS config. If you want to go this way, you don't need to do anything, since the default value for programs.sway.enable is false. But if anyways you want to install 2 sway versions, one with NixOS and one with home-manager, it should be possible if you have something like this in your NixOS config:

services.xserver.desktopManager.session = [
  {
    name = "home-manager";
    start = ''
      ${pkgs.runtimeShell} $HOME/.hm-session &
      waitPID=$!
    '';
  }
];

and this in your home-manager config:

xsession.enable = true;
xsession.scriptPath = ".hm-session";
xsession.windowManager.command = mySwayPackage;

2 notes: services.xserver.desktopManager.session doesn't generate wayland sessions, but it should be an easy fix, and mySwayPackage refers to the same sway package you define in wayland.windowmanager.sway.package option.

@alexarice To my understanding, systemd is not involve in this, I don't have any suggestions to improve the systemd part, it looks good to me :)
I'll try to clarify the issue with an example, let's say you have this config in you NixOS configuration.nix:

programs.sway = {
     enable = true;
     extraSessionCommands =
       ''
       export MYVAR=nixos
       '';
};

and this on your home-manager config:

wayland.windowmanager.sway = {
     enable = true;
     extraSessionCommands =
       ''
       export MYVAR=home-manager
       '';
};

after login, MYVAR value will be home-manager. As long as you mix NixOS and home-manger sway options, it is not possible to start the NixOS sway version from a display manager

@alexarice
Copy link
Contributor

I think the difficulty is that home-manager has to work on non nixos machines, and this makes it hard to integrate with nixos options.

@jlesquembre
Copy link
Member Author

I think the difficulty is that home-manager has to work on non nixos machines, and this makes it hard to integrate with nixos options.

Right, I didn't considered that case

@alexarice
Copy link
Contributor

This might be similar to what has already been suggested, but I think the necessary changes for home-manager are:

  • Make sway.package be nullable
  • Update the documentation on sway.package to say that if you are using the nixos sway module you should set this to null to avoid overwriting this

Would this fix all the issues?

@jlesquembre
Copy link
Member Author

@alexarice I think so, that 2 changes should solve it. But I think it still makes sense to merge this PR

@alexarice
Copy link
Contributor

I'll make a PR on home-manager then, I think this pr is probably a good idea too

@primeos
Copy link
Member

primeos commented Jun 1, 2020

Even with nix-community/home-manager#1298 one (theoretical) issue remains: When Sway is launched via a login/display manager the following options from the home-manager module won't do anything: package, wrapperFeatures, extraSessionCommands, extraOptions (more details in #89179 (review)).

If that's ok for the maintainers of the home-manager module for Sway we could merge this PR.

@alexarice
Copy link
Contributor

Ah I see the issue now, though I don't see a way round it other than putting a big warning somewhere that this overwrite exists. The home-manager module will say that setting package to null is recommended if using the nixos option

@alexarice
Copy link
Contributor

The home-manager change went through, was there any decision on what to do with this?

@primeos
Copy link
Member

primeos commented Jun 10, 2020

@alexarice no, not really. AFAIK @jlesquembre is still in favor of this PR while I'm more against it due to the problem explained in #89179 (comment) and also the resulting inconsistent behaviour between a login via a display manager or tty. I also looked at the desktop entries on my system and most files don't use absolute paths. I don't have a strong opinion on this though and I don't use a display manager anyway.

@jlesquembre if you still want this PR to get merged it would be good if you could ping a few other maintainers familiar with desktop entries and display manager (you can e.g. check the Git history). I think @jtojnar might e.g. be a good fit or actually even better @NixOS/freedesktop. If not feel free to close this PR.

@jlesquembre
Copy link
Member Author

I think I'm going to close this PR since now it is possible to set the sway package in home-manager to null.
The only reason against closing, it's that I prefer to be more deterministic, instead of picking the first sway version in PATH
I'm going to think a bit more about it, but if I cannot find a better reason for this PR, I'll close it

@rycee
Copy link
Member

rycee commented Jun 10, 2020

I don't know much about Sway but it seems to me that if a user chooses to set up Sway in Home Manager then they don't really want a sway.desktop but a home-manager.desktop. The HM desktop file could do something like starting a hm-graphical-session.target systemd unit, which in turn would pull in a sway.service and other graphical services the user would like.

This is sort of how the HM xsession module works but kicking off hm-graphical-session.target from ~/.xsession instead of a desktop file.

Edit: It might be worth mentioning that to do this property one would need to use the system --wait option, which does not work by default in NixOS due to its troublesome user session dbus setup. But I imagine that it would be possible to work-around by having a occasionally-check-if-sway-is-still-running-and-break-if-not loop.

@primeos
Copy link
Member

primeos commented Jun 11, 2020

The only reason against closing, it's that I prefer to be more deterministic, instead of picking the first sway version in PATH

I guess this is a matter of definition. I'd e.g. still consider this perfectly deterministic. A reference without the absolute path is just more like a global and mutable variable in a programming language while a reference with an absolute path is of course immutable as the referenced content in the Nix store is immutable (and depending on what we'd like to achieve both behaviours can make sense).

I don't know much about Sway but it seems to me that if a user chooses to set up Sway in Home Manager then they don't really want a sway.desktop but a home-manager.desktop.

HM can generate a home-manager.desktop file but unless you reference that from the NixOS configuration or patch display managers they won't find it.

@jlesquembre
Copy link
Member Author

HM can generate a home-manager.desktop file but unless you reference that from the NixOS configuration or patch display managers they won't find it.

That should be possible with the services.xserver.displayManager.session option, I think.

I'm closing this PR. IMO the new option added to home-manager by @alexarice is good enough and solves the problem I had. Feel free to reopen if you think otherwise.

Thanks @primeos , @alexarice and @rycee for all your comments, it was a really interesting conversation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants