2017-10-17 13:50:55 +00:00
|
|
|
{ options, config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
cfg = config.xdg;
|
|
|
|
|
2017-11-06 09:28:55 +00:00
|
|
|
fileType = (import ../lib/file-type.nix {
|
|
|
|
inherit (config.home) homeDirectory;
|
|
|
|
inherit lib pkgs;
|
|
|
|
}).fileType;
|
2017-10-17 13:50:55 +00:00
|
|
|
|
|
|
|
defaultCacheHome = "${config.home.homeDirectory}/.cache";
|
|
|
|
defaultConfigHome = "${config.home.homeDirectory}/.config";
|
|
|
|
defaultDataHome = "${config.home.homeDirectory}/.local/share";
|
2021-11-04 16:42:44 +00:00
|
|
|
defaultStateHome = "${config.home.homeDirectory}/.local/state";
|
2017-10-17 13:50:55 +00:00
|
|
|
|
2021-09-13 02:44:58 +00:00
|
|
|
getEnvFallback = name: fallback:
|
2021-07-18 21:34:50 +00:00
|
|
|
let value = builtins.getEnv name;
|
|
|
|
in if value != "" then value else fallback;
|
2017-10-17 13:50:55 +00:00
|
|
|
|
2021-07-18 21:34:50 +00:00
|
|
|
in {
|
2017-10-17 13:50:55 +00:00
|
|
|
options.xdg = {
|
2023-07-01 23:45:18 +00:00
|
|
|
enable = mkEnableOption "management of XDG base directories";
|
2017-10-17 13:50:55 +00:00
|
|
|
|
|
|
|
cacheHome = mkOption {
|
|
|
|
type = types.path;
|
|
|
|
defaultText = "~/.cache";
|
2021-09-13 02:44:58 +00:00
|
|
|
apply = toString;
|
2023-07-01 23:45:18 +00:00
|
|
|
description = ''
|
2017-10-17 13:50:55 +00:00
|
|
|
Absolute path to directory holding application caches.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
configFile = mkOption {
|
2023-06-30 05:22:38 +00:00
|
|
|
type = fileType "xdg.configFile" "{var}`xdg.configHome`" cfg.configHome;
|
2021-07-18 21:34:50 +00:00
|
|
|
default = { };
|
2023-07-01 23:45:18 +00:00
|
|
|
description = ''
|
2017-10-17 13:50:55 +00:00
|
|
|
Attribute set of files to link into the user's XDG
|
|
|
|
configuration home.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
configHome = mkOption {
|
|
|
|
type = types.path;
|
|
|
|
defaultText = "~/.config";
|
2021-09-13 02:44:58 +00:00
|
|
|
apply = toString;
|
2023-07-01 23:45:18 +00:00
|
|
|
description = ''
|
2017-10-17 13:50:55 +00:00
|
|
|
Absolute path to directory holding application configurations.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2017-11-10 23:30:53 +00:00
|
|
|
dataFile = mkOption {
|
2023-05-22 20:48:23 +00:00
|
|
|
type =
|
|
|
|
fileType "xdg.dataFile" "<varname>xdg.dataHome</varname>" cfg.dataHome;
|
2021-07-18 21:34:50 +00:00
|
|
|
default = { };
|
2023-07-01 23:45:18 +00:00
|
|
|
description = ''
|
2017-11-10 23:30:53 +00:00
|
|
|
Attribute set of files to link into the user's XDG
|
|
|
|
data home.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2017-10-17 13:50:55 +00:00
|
|
|
dataHome = mkOption {
|
|
|
|
type = types.path;
|
|
|
|
defaultText = "~/.local/share";
|
2021-09-13 02:44:58 +00:00
|
|
|
apply = toString;
|
2023-07-01 23:45:18 +00:00
|
|
|
description = ''
|
2017-10-17 13:50:55 +00:00
|
|
|
Absolute path to directory holding application data.
|
|
|
|
'';
|
|
|
|
};
|
2021-11-04 16:42:44 +00:00
|
|
|
|
2024-09-06 12:55:36 +00:00
|
|
|
stateFile = mkOption {
|
|
|
|
type = fileType "xdg.stateFile" "<varname>xdg.stateHome</varname>"
|
|
|
|
cfg.stateHome;
|
|
|
|
default = { };
|
|
|
|
description = ''
|
|
|
|
Attribute set of files to link into the user's XDG
|
|
|
|
state home.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2021-11-04 16:42:44 +00:00
|
|
|
stateHome = mkOption {
|
|
|
|
type = types.path;
|
|
|
|
defaultText = "~/.local/state";
|
|
|
|
apply = toString;
|
2023-07-01 23:45:18 +00:00
|
|
|
description = ''
|
2021-11-04 16:42:44 +00:00
|
|
|
Absolute path to directory holding application states.
|
|
|
|
'';
|
|
|
|
};
|
2017-10-17 13:50:55 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
config = mkMerge [
|
2022-03-18 02:22:53 +00:00
|
|
|
(let
|
|
|
|
variables = {
|
2017-10-17 13:50:55 +00:00
|
|
|
XDG_CACHE_HOME = cfg.cacheHome;
|
|
|
|
XDG_CONFIG_HOME = cfg.configHome;
|
|
|
|
XDG_DATA_HOME = cfg.dataHome;
|
2021-11-04 16:42:44 +00:00
|
|
|
XDG_STATE_HOME = cfg.stateHome;
|
2017-10-17 13:50:55 +00:00
|
|
|
};
|
2022-03-18 02:22:53 +00:00
|
|
|
in mkIf cfg.enable {
|
|
|
|
xdg.cacheHome = mkDefault defaultCacheHome;
|
|
|
|
xdg.configHome = mkDefault defaultConfigHome;
|
|
|
|
xdg.dataHome = mkDefault defaultDataHome;
|
|
|
|
xdg.stateHome = mkDefault defaultStateHome;
|
|
|
|
|
|
|
|
home.sessionVariables = variables;
|
|
|
|
systemd.user.sessionVariables =
|
|
|
|
mkIf pkgs.stdenv.hostPlatform.isLinux variables;
|
2017-10-17 13:50:55 +00:00
|
|
|
})
|
|
|
|
|
2020-05-24 16:08:49 +00:00
|
|
|
# Legacy non-deterministic setup.
|
|
|
|
(mkIf (!cfg.enable && versionOlder config.home.stateVersion "20.09") {
|
2021-09-13 02:44:58 +00:00
|
|
|
xdg.cacheHome =
|
|
|
|
mkDefault (getEnvFallback "XDG_CACHE_HOME" defaultCacheHome);
|
|
|
|
xdg.configHome =
|
|
|
|
mkDefault (getEnvFallback "XDG_CONFIG_HOME" defaultConfigHome);
|
|
|
|
xdg.dataHome = mkDefault (getEnvFallback "XDG_DATA_HOME" defaultDataHome);
|
2017-10-17 13:50:55 +00:00
|
|
|
})
|
|
|
|
|
2020-05-24 16:08:49 +00:00
|
|
|
# "Modern" deterministic setup.
|
|
|
|
(mkIf (!cfg.enable && versionAtLeast config.home.stateVersion "20.09") {
|
|
|
|
xdg.cacheHome = mkDefault defaultCacheHome;
|
|
|
|
xdg.configHome = mkDefault defaultConfigHome;
|
|
|
|
xdg.dataHome = mkDefault defaultDataHome;
|
2021-11-19 01:14:11 +00:00
|
|
|
xdg.stateHome = mkDefault defaultStateHome;
|
2020-05-24 16:08:49 +00:00
|
|
|
})
|
|
|
|
|
2017-10-17 13:50:55 +00:00
|
|
|
{
|
2019-07-26 21:23:51 +00:00
|
|
|
home.file = mkMerge [
|
2021-09-13 02:44:58 +00:00
|
|
|
(mapAttrs' (name: file: nameValuePair "${cfg.configHome}/${name}" file)
|
2020-10-12 00:22:58 +00:00
|
|
|
cfg.configFile)
|
2021-09-13 02:44:58 +00:00
|
|
|
(mapAttrs' (name: file: nameValuePair "${cfg.dataHome}/${name}" file)
|
2020-10-12 00:22:58 +00:00
|
|
|
cfg.dataFile)
|
2024-09-06 12:55:36 +00:00
|
|
|
(mapAttrs' (name: file: nameValuePair "${cfg.stateHome}/${name}" file)
|
|
|
|
cfg.stateFile)
|
2021-09-13 02:44:58 +00:00
|
|
|
{ "${cfg.cacheHome}/.keep".text = ""; }
|
2019-07-26 21:23:51 +00:00
|
|
|
];
|
2017-10-17 13:50:55 +00:00
|
|
|
}
|
|
|
|
];
|
|
|
|
}
|