mirror of
https://github.com/nix-community/home-manager.git
synced 2026-06-05 21:02:51 +00:00
xdg-user-dirs: assert extraConfig key warning
This commit is contained in:
@@ -113,25 +113,6 @@ in
|
||||
MISC = "''${config.home.homeDirectory}/Misc";
|
||||
}
|
||||
'';
|
||||
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.
|
||||
|
||||
@@ -175,6 +156,23 @@ in
|
||||
|
||||
config =
|
||||
let
|
||||
legacyExtraConfigKeys = lib.filter (key: lib.match "XDG_(.*)_DIR" key != null) (
|
||||
lib.attrNames cfg.extraConfig
|
||||
);
|
||||
|
||||
normalizeExtraConfigKey =
|
||||
key:
|
||||
let
|
||||
matches = lib.match "XDG_(.*)_DIR" key;
|
||||
in
|
||||
if matches == null then key else lib.elemAt matches 0;
|
||||
|
||||
extraConfig =
|
||||
if lib.versionOlder config.home.stateVersion "26.05" then
|
||||
lib.mapAttrs' (key: lib.nameValuePair (normalizeExtraConfigKey key)) cfg.extraConfig
|
||||
else
|
||||
cfg.extraConfig;
|
||||
|
||||
directories =
|
||||
(lib.filterAttrs (_n: v: !isNull v) {
|
||||
DESKTOP = cfg.desktop;
|
||||
@@ -187,11 +185,26 @@ in
|
||||
TEMPLATES = cfg.templates;
|
||||
VIDEOS = cfg.videos;
|
||||
})
|
||||
// cfg.extraConfig;
|
||||
// extraConfig;
|
||||
|
||||
bindings = lib.mapAttrs' (k: lib.nameValuePair "XDG_${k}_DIR") directories;
|
||||
in
|
||||
lib.mkIf cfg.enable {
|
||||
warnings = lib.optionals (lib.versionOlder config.home.stateVersion "26.05") (
|
||||
map (
|
||||
key:
|
||||
lib.hm.deprecations.mkDeprecatedOptionValueWarning {
|
||||
option = [
|
||||
"xdg"
|
||||
"userDirs"
|
||||
"extraConfig"
|
||||
];
|
||||
old = "keys like `${key}`";
|
||||
replacement = "keys like `${normalizeExtraConfigKey key}`";
|
||||
}
|
||||
) legacyExtraConfigKeys
|
||||
);
|
||||
|
||||
xdg.configFile."user-dirs.dirs".text =
|
||||
let
|
||||
# For some reason, these need to be wrapped with quotes to be valid.
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
xdg-local-bin-in-path = ./local-bin-in-path.nix;
|
||||
xdg-local-bin-not-in-path = ./local-bin-not-in-path.nix;
|
||||
xdg-user-dirs-mixed = ./user-dirs-mixed.nix;
|
||||
xdg-user-dirs-mixed-current = ./user-dirs-mixed-current.nix;
|
||||
xdg-user-dirs-null = ./user-dirs-null.nix;
|
||||
xdg-user-dirs-short = ./user-dirs-short.nix;
|
||||
xdg-user-dirs-session-vars-legacy = ./user-dirs-session-vars-legacy.nix;
|
||||
|
||||
14
tests/modules/misc/xdg/user-dirs-mixed-current.nix
Normal file
14
tests/modules/misc/xdg/user-dirs-mixed-current.nix
Normal file
@@ -0,0 +1,14 @@
|
||||
{ config, ... }:
|
||||
|
||||
{
|
||||
config = {
|
||||
home.stateVersion = "26.05";
|
||||
|
||||
xdg.userDirs = {
|
||||
enable = true;
|
||||
extraConfig.XDG_MISC_DIR = "${config.home.homeDirectory}/Misc";
|
||||
};
|
||||
|
||||
test.asserts.warnings.expected = [ ];
|
||||
};
|
||||
}
|
||||
@@ -15,6 +15,13 @@
|
||||
extraConfig.XDG_MISC_DIR = "${config.home.homeDirectory}/Misc";
|
||||
};
|
||||
|
||||
test.asserts.warnings.expected = [
|
||||
''
|
||||
Using `xdg.userDirs.extraConfig` as keys like `XDG_MISC_DIR` is deprecated and will be
|
||||
removed in a future release. Please use keys like `MISC` instead.
|
||||
''
|
||||
];
|
||||
|
||||
nmt.script = ''
|
||||
configFile=home-files/.config/user-dirs.dirs
|
||||
assertFileExists $configFile
|
||||
|
||||
Reference in New Issue
Block a user