1
0
Fork 0
mirror of https://github.com/nix-community/home-manager synced 2024-12-23 10:19:48 +01:00

xdg: add option 'xdg.stateHome' (#2439)

It corresponds to the newly introduced `XDG_STATE_HOME`.
This commit is contained in:
oxalica 2021-11-05 00:42:44 +08:00 committed by GitHub
parent 288faaa5a6
commit 70c5b268e1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 24 additions and 0 deletions

View file

@ -23,6 +23,9 @@ runCommand "home-manager-install" {
if [[ -v XDG_DATA_HOME && $XDG_DATA_HOME != "$HOME/.local/share" ]]; then
xdgVars="$xdgVars xdg.dataHome = \"$XDG_DATA_HOME\";$nl"
fi
if [[ -v XDG_STATE_HOME && $XDG_STATE_HOME != "$HOME/.local/state" ]]; then
xdgVars="$xdgVars xdg.stateHome = \"$XDG_STATE_HOME\";$nl"
fi
mkdir -p "$(dirname "$confFile")"
cat > $confFile <<EOF

View file

@ -14,6 +14,7 @@ let
defaultCacheHome = "${config.home.homeDirectory}/.cache";
defaultConfigHome = "${config.home.homeDirectory}/.config";
defaultDataHome = "${config.home.homeDirectory}/.local/share";
defaultStateHome = "${config.home.homeDirectory}/.local/state";
getEnvFallback = name: fallback:
let value = builtins.getEnv name;
@ -67,6 +68,15 @@ in {
Absolute path to directory holding application data.
'';
};
stateHome = mkOption {
type = types.path;
defaultText = "~/.local/state";
apply = toString;
description = ''
Absolute path to directory holding application states.
'';
};
};
config = mkMerge [
@ -74,11 +84,13 @@ in {
xdg.cacheHome = mkDefault defaultCacheHome;
xdg.configHome = mkDefault defaultConfigHome;
xdg.dataHome = mkDefault defaultDataHome;
xdg.stateHome = mkDefault defaultStateHome;
home.sessionVariables = {
XDG_CACHE_HOME = cfg.cacheHome;
XDG_CONFIG_HOME = cfg.configHome;
XDG_DATA_HOME = cfg.dataHome;
XDG_STATE_HOME = cfg.stateHome;
};
})
@ -96,6 +108,7 @@ in {
xdg.cacheHome = mkDefault defaultCacheHome;
xdg.configHome = mkDefault defaultConfigHome;
xdg.dataHome = mkDefault defaultDataHome;
xdg.stateHome = mkDefault stateHome;
})
{

View file

@ -15,6 +15,7 @@ let
export XDG_CACHE_HOME="/home/hm-user/.cache"
export XDG_CONFIG_HOME="/home/hm-user/.config"
export XDG_DATA_HOME="/home/hm-user/.local/share"
export XDG_STATE_HOME="/home/hm-user/.local/state"
'';
darwinExpected = ''
@ -27,6 +28,7 @@ let
export XDG_CACHE_HOME="/home/hm-user/.cache"
export XDG_CONFIG_HOME="/home/hm-user/.config"
export XDG_DATA_HOME="/home/hm-user/.local/share"
export XDG_STATE_HOME="/home/hm-user/.local/state"
'';
expected = pkgs.writeText "expected" (if isDarwin then darwinExpected else linuxExpected);

View file

@ -7,15 +7,18 @@ with lib;
xdg.configHome = /. + "${config.home.homeDirectory}/.dummy-config";
xdg.dataHome = /. + "${config.home.homeDirectory}/.dummy-data";
xdg.cacheHome = /. + "${config.home.homeDirectory}/.dummy-cache";
xdg.stateHome = /. + "${config.home.homeDirectory}/.dummy-state";
xdg.configFile.test.text = "config";
xdg.dataFile.test.text = "data";
home.file."${config.xdg.cacheHome}/test".text = "cache";
home.file."${config.xdg.stateHome}/test".text = "state";
nmt.script = ''
assertFileExists home-files/.dummy-config/test
assertFileExists home-files/.dummy-cache/test
assertFileExists home-files/.dummy-data/test
assertFileExists home-files/.dummy-state/test
assertFileContent \
home-files/.dummy-config/test \
${builtins.toFile "test" "config"}
@ -25,6 +28,9 @@ with lib;
assertFileContent \
home-files/.dummy-cache/test \
${builtins.toFile "test" "cache"}
assertFileContent \
home-files/.dummy-state/test \
${builtins.toFile "test" "state"}
'';
};
}