Scheduled Maintenance: We are aware of an issue with Google, AOL, and Yahoo services as email providers which are blocking new registrations. We are trying to fix the issue and we have several internal and external support tickets in process to resolve the issue. Please see: viewtopic.php?t=158230

 

 

 

[Software] /usr/lib/environment.d/ apparently not working

If none of the specific sub-forums seem right for your thread, ask here.
Post Reply
Message
Author
bityard
Posts: 1
Joined: 2024-03-10 13:47

[Software] /usr/lib/environment.d/ apparently not working

#1 Post by bityard »

Howdy,

I was going to play around with Nix as a package manager on Debian (long story). I installed the `nix-bin` and `nix-setup-systemd` packages and noted the contents of `/usr/share/doc/nix-bin/README.Debian`, which states:

Setting up of the user environment is done by the systemd
configuration files /usr/share/user-tmpfiles.d/nix-daemon.conf[1] and
/usr/lib/environment.d/nix-daemon.conf[2]. For this to work there
must be a user session instance of systemd running, as provided by
the recommended package libpam-systemd.

Well, there is indeed a `/usr/lib/environment.d/nix-daemon.conf`, and it contains the following:

NIX_REMOTE=daemon
PATH="$HOME/.nix-profile/bin:/nix/var/nix/profiles/default/bin:$PATH"
NIX_PATH="nixpkgs=/nix/var/nix/profiles/per-user/$USER/channels/nixpkgs:/nix/var/nix/profiles/per-user/$USER/channels"

However, this is not getting read or "sourced" by my SSH login shell, as all the man pages suggest it should. I definitely have a user service running:

$ systemctl --user status
● debvm1
    State: running
    Units: 78 loaded (incl. loaded aliases)
     Jobs: 0 queued
   Failed: 0 units
    Since: Sun 2024-03-10 09:34:34 EDT; 24min ago
  systemd: 252.22-1~deb12u1
   CGroup: /user.slice/user-1000.slice/user@1000.service
           └─init.scope
             ├─547 /lib/systemd/systemd --user
             └─549 "(sd-pam)"

The output of `env | grep -i nix` returns nothing at all.

Anything else I should try, or look at?

User avatar
sunrat
Administrator
Administrator
Posts: 6515
Joined: 2006-08-29 09:12
Location: Melbourne, Australia
Has thanked: 119 times
Been thanked: 489 times

Re: [Software] /usr/lib/environment.d/ apparently not working

#2 Post by sunrat »

Please use code tags for terminal text and config files, not preformatted text tags.
“ computer users can be divided into 2 categories:
Those who have lost data
...and those who have not lost data YET ”
Remember to BACKUP!

Aki
Global Moderator
Global Moderator
Posts: 2981
Joined: 2014-07-20 18:12
Location: Europe
Has thanked: 75 times
Been thanked: 407 times

Re: [Software] /usr/lib/environment.d/ apparently not working

#3 Post by Aki »

Hello,
bityard wrote: 2024-03-10 14:00 I was going to play around with Nix as a package manager on Debian (long story). I installed the `nix-bin` and `nix-setup-systemd` packages and noted the contents of `/usr/share/doc/nix-bin/README.Debian`, which states:
[..]
Well, there is indeed a `/usr/lib/environment.d/nix-daemon.conf`, and it contains the following:

Code: Select all

[pre]NIX_REMOTE=daemon
PATH="$HOME/.nix-profile/bin:/nix/var/nix/profiles/default/bin:$PATH"
NIX_PATH="nixpkgs=/nix/var/nix/profiles/per-user/$USER/channels/nixpkgs:/nix/var/nix/profiles/per-user/$USER/channels"[/pre]
However, this is not getting read or "sourced" by my SSH login shell, as all the man pages suggest it should. I definitely have a user service running
What is your installed Debian version ?

What is your installed nix version ?

In my Debian Bookworm (after installing nix and rebooting), the systemd-user environment is set, but the user's shell environment does not contain the "NIX_*" variables (both in local and remote ssh logins):

Code: Select all

$ systemctl --user show-environment | grep NIX   
NIX_REMOTE=daemon
NIX_PATH=nixpkgs=/nix/var/nix/profiles/per-user/aki/channels/nixpkgs:/nix/var/nix/profiles/per-user/aki/channels

$ env | grep NIX
# empty output
According to "environment.d" man page [3]:
Applicability
Environment variables exported by the user service manager (systemd --user instance started in the user@uid.service system service) are passed to any services started by that service manager. In particular, this may include services which run user shells. For example in the GNOME environment, the graphical terminal emulator runs as the gnome-terminal-server.service user unit, which in turn runs the user shell, so that shell will inherit environment variables exported by the user manager. For other instances of the shell, not launched by the user service manager, the environment they inherit is defined by the program that starts them.
and:
Specifically, for ssh logins, the sshd(8) service builds an environment that is a combination of variables forwarded from the remote system and defined by sshd, see the discussion in ssh(1). A graphical display session will have an analogous mechanism to define the environment. Note that some managers query the systemd user instance for the exported environment and inject this configuration into programs they start, using systemctl show-environment or the underlying D-Bus call.
According to the systemd's author Lennart Poettering [4]:
systemd-environment-d-generator gets run by systemd --user, and thus set environment variables for the systemd per-user service manager and their child processes only. Login shells (such as those started via getty on the console or ssh) are not children of systemd and hence the generators have no effect on them whatsoever. For login sessions use pam_env or some .profile script or similar to set env vars... Sorry.
Hope this helps.

note: This issue has been already reported in Debian [1] and in systemd [2], and it was closed as fixed.
---
[1] https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=869144
[2] https://github.com/systemd/systemd/issues/6414
[3] https://www.freedesktop.org/software/systemd/man/latest/environment.d.html
[4] https://github.com/systemd/systemd/issues/12938#issuecomment-508381592
⢀⣴⠾⠻⢶⣦⠀
⣾⠁⢠⠒⠀⣿⡁ Debian - The universal operating system
⢿⡄⠘⠷⠚⠋⠀ https://www.debian.org
⠈⠳⣄⠀

Post Reply