mirror of
https://github.com/nix-community/home-manager
synced 2024-11-09 04:39:44 +01:00
23769994e8
There is a need to manage XDG Base Directory system directory environment variables in Home Manager modules. There is an existing mechanism in `targets.genericLinux.extraXdgDataDirs', but this does not apply to NixOS systems. Furthermore, it is important that `XDG_CONFIG_DIRS' and `XDG_DATA_DIRS' are set in both login shells (to support getty and SSH sessions) as well as the systemd user manager (to propagate them to user services and desktop environments). The first need is addressed by adding the `xdg.systemDirs' module, which configures lists of directory names for both `config' and `data' directories. These are then set in `$XDG_CONFIG_DIR/environment.d/10-home-manager.conf' and picked up by the systemd user manager. To make these, and other variables set in `systemd.user.sessionVariables', available in login shells, an additional step is added to `etc/profile.d/hm-session-vars.sh' which exports the result of `user-environment-generators/30-systemd-environment-d-generator' which is shipped with systemd. The effect of this generator is to print variables set on the systemd user manager such that shells can import these into their environment.
40 lines
1.1 KiB
Nix
40 lines
1.1 KiB
Nix
{ config, lib, pkgs, ... }:
|
|
|
|
with lib;
|
|
|
|
let
|
|
expectedXdgDataDirs = concatStringsSep ":" [
|
|
"\${NIX_STATE_DIR:-/nix/var/nix}/profiles/default/share"
|
|
"/home/hm-user/.nix-profile/share"
|
|
"/usr/share/ubuntu"
|
|
"/usr/local/share"
|
|
"/usr/share"
|
|
"/var/lib/snapd/desktop"
|
|
"/foo"
|
|
];
|
|
|
|
in {
|
|
config = {
|
|
targets.genericLinux.enable = true;
|
|
|
|
xdg.systemDirs.data = [ "/foo" ];
|
|
|
|
nmt.script = ''
|
|
envFile=home-files/.config/environment.d/10-home-manager.conf
|
|
assertFileExists $envFile
|
|
assertFileContains $envFile \
|
|
'XDG_DATA_DIRS=${expectedXdgDataDirs}''${XDG_DATA_DIRS:+:$XDG_DATA_DIRS}'
|
|
assertFileContains $envFile \
|
|
'TERMINFO_DIRS=/home/hm-user/.nix-profile/share/terminfo:$TERMINFO_DIRS''${TERMINFO_DIRS:+:}/etc/terminfo:/lib/terminfo:/usr/share/terminfo'
|
|
|
|
sessionVarsFile=home-path/etc/profile.d/hm-session-vars.sh
|
|
assertFileExists $sessionVarsFile
|
|
assertFileContains $sessionVarsFile \
|
|
'. "${pkgs.nix}/etc/profile.d/nix.sh"'
|
|
|
|
assertFileContains \
|
|
home-path/etc/profile.d/hm-session-vars.sh \
|
|
'export TERM="$TERM"'
|
|
'';
|
|
};
|
|
}
|