1
0
Fork 0
mirror of https://github.com/nix-community/home-manager synced 2024-11-23 19:49:45 +01:00
home-manager/modules/targets/generic-linux.nix
Tad Fisher 23769994e8
xdg.systemDirs: init module (#1797)
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.
2021-05-10 20:14:42 -04:00

72 lines
2.1 KiB
Nix

{ config, lib, pkgs, ... }:
with lib;
let
cfg = config.targets.genericLinux;
profileDirectory = config.home.profileDirectory;
in {
imports = [
(mkRenamedOptionModule [ "targets" "genericLinux" "extraXdgDataDirs" ] [
"xdg"
"systemDirs"
"data"
])
];
options.targets.genericLinux = {
enable = mkEnableOption "" // {
description = ''
Whether to enable settings that make Home Manager work better on
GNU/Linux distributions other than NixOS.
'';
};
};
config = mkIf cfg.enable {
xdg.systemDirs.data = [
# Nix profiles
"\${NIX_STATE_DIR:-/nix/var/nix}/profiles/default/share"
"${profileDirectory}/share"
# Distribution-specific
"/usr/share/ubuntu"
"/usr/local/share"
"/usr/share"
"/var/lib/snapd/desktop"
];
home.sessionVariablesExtra = ''
. "${pkgs.nix}/etc/profile.d/nix.sh"
# reset TERM with new TERMINFO available (if any)
export TERM="$TERM"
'';
# We need to source both nix.sh and hm-session-vars.sh as noted in
# https://github.com/nix-community/home-manager/pull/797#issuecomment-544783247
programs.bash.initExtra = ''
. "${pkgs.nix}/etc/profile.d/nix.sh"
. "${profileDirectory}/etc/profile.d/hm-session-vars.sh"
'';
systemd.user.sessionVariables = let
# https://github.com/archlinux/svntogit-packages/blob/packages/ncurses/trunk/PKGBUILD
# https://salsa.debian.org/debian/ncurses/-/blob/master/debian/rules
# https://src.fedoraproject.org/rpms/ncurses/blob/main/f/ncurses.spec
# https://gitweb.gentoo.org/repo/gentoo.git/tree/sys-libs/ncurses/ncurses-6.2-r1.ebuild
distroTerminfoDirs = concatStringsSep ":" [
"/etc/terminfo" # debian, fedora, gentoo
"/lib/terminfo" # debian
"/usr/share/terminfo" # package default, all distros
];
in {
NIX_PATH = "$HOME/.nix-defexpr/channels\${NIX_PATH:+:}$NIX_PATH";
TERMINFO_DIRS =
"${profileDirectory}/share/terminfo:$TERMINFO_DIRS\${TERMINFO_DIRS:+:}${distroTerminfoDirs}";
};
};
}