xdg.userDirs: change the syntax for extraConfig
E.g., use `MISC` instead of `XDG_MISC_DIR`, the same way `xdg-user-dirs-update` works. This is conditionalized on 26.05, so in future `XDG_MISC_DIR` will be disallowed.
This commit is contained in:
parent
db9044b119
commit
9b62076484
4 changed files with 104 additions and 12 deletions
|
|
@ -103,10 +103,33 @@ in
|
|||
defaultText = literalExpression "{ }";
|
||||
example = literalExpression ''
|
||||
{
|
||||
XDG_MISC_DIR = "''${config.home.homeDirectory}/Misc";
|
||||
MISC = "''${config.home.homeDirectory}/Misc";
|
||||
}
|
||||
'';
|
||||
description = "Other user directories.";
|
||||
apply =
|
||||
if lib.versionOlder config.home.stateVersion "26.05" then
|
||||
lib.mapAttrs' (
|
||||
k:
|
||||
let
|
||||
matches = lib.match "XDG_(.*)_DIR" k;
|
||||
in
|
||||
lib.nameValuePair (
|
||||
if matches == null then
|
||||
k
|
||||
else
|
||||
let
|
||||
name = lib.elemAt matches 0;
|
||||
in
|
||||
lib.warn "using keys like ‘${k}’ for xdg.userDirs.extraConfig is deprecated in favor of keys like ‘${name}’" name
|
||||
)
|
||||
)
|
||||
else
|
||||
lib.id;
|
||||
description = ''
|
||||
Other user directories.
|
||||
|
||||
The key ‘MISC’ corresponds to the user-dirs entry ‘XDG_MISC_DIR’.
|
||||
'';
|
||||
};
|
||||
|
||||
createDirectories = lib.mkEnableOption "automatic creation of the XDG user directories";
|
||||
|
|
@ -136,22 +159,24 @@ in
|
|||
let
|
||||
directories =
|
||||
(lib.filterAttrs (n: v: !isNull v) {
|
||||
XDG_DESKTOP_DIR = cfg.desktop;
|
||||
XDG_DOCUMENTS_DIR = cfg.documents;
|
||||
XDG_DOWNLOAD_DIR = cfg.download;
|
||||
XDG_MUSIC_DIR = cfg.music;
|
||||
XDG_PICTURES_DIR = cfg.pictures;
|
||||
XDG_PUBLICSHARE_DIR = cfg.publicShare;
|
||||
XDG_TEMPLATES_DIR = cfg.templates;
|
||||
XDG_VIDEOS_DIR = cfg.videos;
|
||||
DESKTOP = cfg.desktop;
|
||||
DOCUMENTS = cfg.documents;
|
||||
DOWNLOAD = cfg.download;
|
||||
MUSIC = cfg.music;
|
||||
PICTURES = cfg.pictures;
|
||||
PUBLICSHARE = cfg.publicShare;
|
||||
TEMPLATES = cfg.templates;
|
||||
VIDEOS = cfg.videos;
|
||||
})
|
||||
// cfg.extraConfig;
|
||||
|
||||
bindings = lib.mapAttrs' (k: lib.nameValuePair "XDG_${k}_DIR") directories;
|
||||
in
|
||||
lib.mkIf cfg.enable {
|
||||
xdg.configFile."user-dirs.dirs".text =
|
||||
let
|
||||
# For some reason, these need to be wrapped with quotes to be valid.
|
||||
wrapped = lib.mapAttrs (_: value: ''"${value}"'') directories;
|
||||
wrapped = lib.mapAttrs (_: value: ''"${value}"'') bindings;
|
||||
in
|
||||
lib.generators.toKeyValue { } wrapped;
|
||||
|
||||
|
|
@ -159,7 +184,7 @@ in
|
|||
|
||||
home.packages = lib.mkIf (cfg.package != null) [ cfg.package ];
|
||||
|
||||
home.sessionVariables = lib.mkIf cfg.setSessionVariables directories;
|
||||
home.sessionVariables = lib.mkIf cfg.setSessionVariables bindings;
|
||||
|
||||
home.activation.createXdgUserDirectories = lib.mkIf cfg.createDirectories (
|
||||
let
|
||||
|
|
|
|||
|
|
@ -4,5 +4,7 @@
|
|||
xdg-mime-disabled = ./mime-disabled.nix;
|
||||
xdg-autostart = ./autostart.nix;
|
||||
xdg-autostart-readonly = ./autostart-readonly.nix;
|
||||
xdg-user-dirs-mixed = ./user-dirs-mixed.nix;
|
||||
xdg-user-dirs-null = ./user-dirs-null.nix;
|
||||
xdg-user-dirs-short = ./user-dirs-short.nix;
|
||||
}
|
||||
|
|
|
|||
35
tests/modules/misc/xdg/user-dirs-mixed.nix
Normal file
35
tests/modules/misc/xdg/user-dirs-mixed.nix
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
{
|
||||
config,
|
||||
pkgs,
|
||||
...
|
||||
}:
|
||||
|
||||
{
|
||||
config = {
|
||||
home.stateVersion = "25.11";
|
||||
|
||||
xdg.userDirs = {
|
||||
enable = true;
|
||||
extraConfig.PROJECTS = "${config.home.homeDirectory}/Projects";
|
||||
## This will trigger a warning.
|
||||
extraConfig.XDG_MISC_DIR = "${config.home.homeDirectory}/Misc";
|
||||
};
|
||||
|
||||
nmt.script = ''
|
||||
configFile=home-files/.config/user-dirs.dirs
|
||||
assertFileExists $configFile
|
||||
assertFileContent $configFile ${pkgs.writeText "expected" ''
|
||||
XDG_DESKTOP_DIR="/home/hm-user/Desktop"
|
||||
XDG_DOCUMENTS_DIR="/home/hm-user/Documents"
|
||||
XDG_DOWNLOAD_DIR="/home/hm-user/Downloads"
|
||||
XDG_MISC_DIR="/home/hm-user/Misc"
|
||||
XDG_MUSIC_DIR="/home/hm-user/Music"
|
||||
XDG_PICTURES_DIR="/home/hm-user/Pictures"
|
||||
XDG_PROJECTS_DIR="/home/hm-user/Projects"
|
||||
XDG_PUBLICSHARE_DIR="/home/hm-user/Public"
|
||||
XDG_TEMPLATES_DIR="/home/hm-user/Templates"
|
||||
XDG_VIDEOS_DIR="/home/hm-user/Videos"
|
||||
''}
|
||||
'';
|
||||
};
|
||||
}
|
||||
30
tests/modules/misc/xdg/user-dirs-short.nix
Normal file
30
tests/modules/misc/xdg/user-dirs-short.nix
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
{
|
||||
config,
|
||||
pkgs,
|
||||
...
|
||||
}:
|
||||
|
||||
{
|
||||
config = {
|
||||
xdg.userDirs = {
|
||||
enable = true;
|
||||
extraConfig.PROJECTS = "${config.home.homeDirectory}/Projects";
|
||||
};
|
||||
|
||||
nmt.script = ''
|
||||
configFile=home-files/.config/user-dirs.dirs
|
||||
assertFileExists $configFile
|
||||
assertFileContent $configFile ${pkgs.writeText "expected" ''
|
||||
XDG_DESKTOP_DIR="/home/hm-user/Desktop"
|
||||
XDG_DOCUMENTS_DIR="/home/hm-user/Documents"
|
||||
XDG_DOWNLOAD_DIR="/home/hm-user/Downloads"
|
||||
XDG_MUSIC_DIR="/home/hm-user/Music"
|
||||
XDG_PICTURES_DIR="/home/hm-user/Pictures"
|
||||
XDG_PROJECTS_DIR="/home/hm-user/Projects"
|
||||
XDG_PUBLICSHARE_DIR="/home/hm-user/Public"
|
||||
XDG_TEMPLATES_DIR="/home/hm-user/Templates"
|
||||
XDG_VIDEOS_DIR="/home/hm-user/Videos"
|
||||
''}
|
||||
'';
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue