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