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

nixos/xsession: check for env vars #42677

Closed
wants to merge 2 commits into from
Closed

nixos/xsession: check for env vars #42677

wants to merge 2 commits into from

Conversation

Kmeakin
Copy link
Contributor

@Kmeakin Kmeakin commented Jun 27, 2018

Read $XCOMPOSECACHE and $XDG_DATA_HOME environment variables when writing ~/.compose-cache and ~/.local/share, otherwise use default values.

Motivation for this change

Old script did not check for $XCOMPOSECACHE and $XDG_DATA_HOME
environment variables.

Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS)
  • 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 nox --run "nox-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)
  • Fits CONTRIBUTING.md.

Old script did not check for $XCOMPOSECACHE and $XDG_DATA_HOME
environment variables.
@peterhoeg
Copy link
Member

Thank you for contributing to Nix.

Since you are using the XDG variables for the data path, how about XDG_CACHE_HOME for the default location of the compose cache (if xcomposecache isn't set)?

@infinisil
Copy link
Member

Aren't these env vars usually set up after this point and potentially in the sessions themselves? I for example have a ~/.xsession file that ends up setting the correct XDG_DATA_HOME, which happens here:

# Allow the user to setup a custom session type.
if test -x ~/.xsession; then
exec ~/.xsession
else

So this script doesn't even get the chance to see the correct env vars.

@Kmeakin
Copy link
Contributor Author

Kmeakin commented Jul 2, 2018

@peterhoeg ~/.compose-cache is the default location, so if it has not been set by the user, other applications (e.g compose (5)) will read from ~/.compose-cache. This patch would have no effect unless the user specifically exports XCOMPOSECACHE.
I also think we should in general try not to change things from the upstream default, as it can cause confusion and inconsistent behavior between distros.

@Kmeakin
Copy link
Contributor Author

Kmeakin commented Jul 2, 2018

@infinisil The exact time that the environment variables are set depends on where they are defined. You are correct that, if they are set in ~/.xsession, then they will not be available at the time the script is run. This can be solved by either:

  • move the sourcing ~/.xsession at the beginning
  • defining your environment variables elsewhere, such as /etc/profile (this is can be used in NixOS by setting environment.sessionVariables. However this doesn't allow you to have different per-user values (e.g. user A wants XDG_DATA_HOME to be ~/.local/share, and user B wants XDG_DATA_HOME to be ~/.hidden/local/share)

@infinisil
Copy link
Member

The problem is that ~/.xsession isn't a file you source, but rather execute. It represents the full user session, and it only exits once the user logs out.

@Kmeakin
Copy link
Contributor Author

Kmeakin commented Jul 2, 2018

It also occurred to me that we could expose services.xserver.displayManager.session.script as an option. This would allow people with niche setups to override the default script. Currently services.xserver.displayManager.sessionCommands only appends to the default script.

@Kmeakin
Copy link
Contributor Author

Kmeakin commented Jul 2, 2018

@infinisil Apologies, I am not familiar with "manual" Xorg setups (I use KDE plasma). From looking at the xsession script, it seems like these env vars could be set in ~/.xprofile if we move the sourcing of ~/.xprofile to the beginning.

@infinisil
Copy link
Member

That might work

@Kmeakin
Copy link
Contributor Author

Kmeakin commented Jul 8, 2018

@infinisil Bump? Is there some proper way to request attention? I'm new to git/github, so sorry if this is the wrong way to go about it

@Kmeakin
Copy link
Contributor Author

Kmeakin commented Jul 18, 2018

@infinisil
ping?

@infinisil
Copy link
Member

Not sure, maybe try pinging some people that were involved with this part of the code in the past

@peterhoeg
Copy link
Member

As a KDE user, how would you go about overriding the location of the compose cache? Otherwise this looks fine to me but please run the various tests (sddm, plasma5, xfce, gnome3) to ensure this isn't breaking anything.

@Kmeakin
Copy link
Contributor Author

Kmeakin commented Jul 19, 2018

@peterhoeg Personally, I set XCOMPOSECACHE in /etc/profile, though I imagine you could do it on a per-user basis with ~/.xprofile or ~/.pam_environment

@mmahut
Copy link
Member

mmahut commented Aug 3, 2019

What is the status of this pull request?

@SFrijters
Copy link
Member

While trying to declutter my $HOME I ran into this issue. It would be nice to have this rebased and merged at some point.

@@ -110,22 +115,19 @@ let

# Speed up application start by 50-150ms according to
# http://kdemonkey.blogspot.nl/2008/04/magic-trick.html
rm -rf "$HOME/.compose-cache"
mkdir "$HOME/.compose-cache"
compose_cache="''${$XCOMPOSECACHE:-$HOME/.compose-cache}"
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't the $ before XCOMPOSECACHE be dropped?

mkdir "$HOME/.compose-cache"
compose_cache="''${$XCOMPOSECACHE:-$HOME/.compose-cache}"
rm -rf "$compose_cache"
mkdir -p "$compose_cache"
Copy link
Member

Choose a reason for hiding this comment

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

Maybe explicitly unset compose_cache when we're done with it?

SFrijters added a commit to SFrijters/nixpkgs that referenced this pull request May 29, 2020
SFrijters added a commit to SFrijters/nixpkgs that referenced this pull request Jun 1, 2020
SFrijters added a commit to SFrijters/nixpkgs that referenced this pull request Jun 7, 2020
SFrijters added a commit to SFrijters/nixpkgs that referenced this pull request Jun 21, 2020
SFrijters added a commit to SFrijters/nixpkgs that referenced this pull request Jun 22, 2020
SFrijters added a commit to SFrijters/nixpkgs that referenced this pull request Jun 24, 2020
SFrijters added a commit to SFrijters/nixpkgs that referenced this pull request Jun 26, 2020
SFrijters added a commit to SFrijters/nixpkgs that referenced this pull request Jun 28, 2020
SFrijters added a commit to SFrijters/nixpkgs that referenced this pull request Jul 12, 2020
SFrijters added a commit to SFrijters/nixpkgs that referenced this pull request Jul 22, 2020
SFrijters added a commit to SFrijters/nixpkgs that referenced this pull request Jul 27, 2020
SFrijters added a commit to SFrijters/nixpkgs that referenced this pull request Aug 1, 2020
SFrijters added a commit to SFrijters/nixpkgs that referenced this pull request Aug 9, 2020
SFrijters added a commit to SFrijters/nixpkgs that referenced this pull request Aug 9, 2020
SFrijters added a commit to SFrijters/nixpkgs that referenced this pull request Aug 12, 2020
SFrijters added a commit to SFrijters/nixpkgs that referenced this pull request Aug 13, 2020
SFrijters added a commit to SFrijters/nixpkgs that referenced this pull request Aug 28, 2020
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

8 participants