Files
home-manager/modules/misc/xdg-system-dirs.nix
Austin Horstman 355734d876 treewide: remove literalExpression where unneeded
`literalExpression` is intended just to signify code that needs to stay
a string that gets represented exactly as-is for docs. It has been
misused heavily and people get confused repeatedly on when or not to use
it because of the rampant misuse.
2026-05-17 21:43:25 -05:00

66 lines
1.5 KiB
Nix

{
config,
lib,
pkgs,
...
}:
let
inherit (lib) types;
cfg = config.xdg.systemDirs;
configDirs = lib.concatStringsSep ":" cfg.config;
dataDirs = lib.concatStringsSep ":" cfg.data;
in
{
meta.maintainers = with lib.maintainers; [ tadfisher ];
options.xdg.systemDirs = {
config = lib.mkOption {
type = types.listOf types.str;
default = [ ];
example = [ "/etc/xdg" ];
description = ''
Directory names to add to {env}`XDG_CONFIG_DIRS`
in the user session.
'';
};
data = lib.mkOption {
type = types.listOf types.str;
default = [ ];
example = [
"/usr/share"
"/usr/local/share"
];
description = ''
Directory names to add to {env}`XDG_DATA_DIRS`
in the user session.
'';
};
};
config = lib.mkMerge [
(lib.mkIf (cfg.config != [ ] || cfg.data != [ ]) {
assertions = [
(lib.hm.assertions.assertPlatform "xdg.systemDirs" pkgs lib.platforms.linux)
];
})
(lib.mkIf (cfg.config != [ ]) {
home.sessionVariables.XDG_CONFIG_DIRS = "${configDirs}\${XDG_CONFIG_DIRS:+:$XDG_CONFIG_DIRS}";
systemd.user.sessionVariables.XDG_CONFIG_DIRS = "${configDirs}\${XDG_CONFIG_DIRS:+:$XDG_CONFIG_DIRS}";
})
(lib.mkIf (cfg.data != [ ]) {
home.sessionVariables.XDG_DATA_DIRS = "${dataDirs}\${XDG_DATA_DIRS:+:$XDG_DATA_DIRS}";
systemd.user.sessionVariables.XDG_DATA_DIRS = "${dataDirs}\${XDG_DATA_DIRS:+:$XDG_DATA_DIRS}";
})
];
}