fork/home-manager
git clone https://git.julia.blue/fork/home-manager
75790441
master
1{ options , config , lib , pkgs , ...} : 2 3with lib ; 4 5let 6 7cfg = config . xdg ; 8 9fileType = ( import ../lib/file-type.nix { 10inherit ( config . home ) homeDirectory ; 11inherit lib pkgs ; 12}). fileType ; 13 14defaultCacheHome = " ${ config . home . homeDirectory } /.cache" ; 15defaultConfigHome = " ${ config . home . homeDirectory } /.config" ; 16defaultDataHome = " ${ config . home . homeDirectory } /.local/share" ; 17defaultStateHome = " ${ config . home . homeDirectory } /.local/state" ; 18 19getEnvFallback = name :fallback : 20let value = builtins . getEnv name ; 21in if value != "" then value else fallback ; 22 23in { 24options . xdg = { 25enable = mkEnableOption "management of XDG base directories" ; 26 27cacheHome = mkOption { 28type = types . path ; 29defaultText = "~/.cache" ; 30apply = toString ; 31description = '' 32Absolute path to directory holding application caches. 33'' ; 34}; 35 36configFile = mkOption { 37type = fileType "xdg.configFile" "{var}`xdg.configHome`" cfg . configHome ; 38default = { }; 39description = '' 40Attribute set of files to link into the user's XDG 41configuration home. 42'' ; 43}; 44 45configHome = mkOption { 46type = types . path ; 47defaultText = "~/.config" ; 48apply = toString ; 49description = '' 50Absolute path to directory holding application configurations. 51'' ; 52}; 53 54dataFile = mkOption { 55type = 56fileType "xdg.dataFile" "<varname>xdg.dataHome</varname>" cfg . dataHome ; 57default = { }; 58description = '' 59Attribute set of files to link into the user's XDG 60data home. 61'' ; 62}; 63 64dataHome = mkOption { 65type = types . path ; 66defaultText = "~/.local/share" ; 67apply = toString ; 68description = '' 69Absolute path to directory holding application data. 70'' ; 71}; 72 73stateHome = mkOption { 74type = types . path ; 75defaultText = "~/.local/state" ; 76apply = toString ; 77description = '' 78Absolute path to directory holding application states. 79'' ; 80}; 81}; 82 83config = mkMerge [ 84( let 85variables = { 86XDG_CACHE_HOME = cfg . cacheHome ; 87XDG_CONFIG_HOME = cfg . configHome ; 88XDG_DATA_HOME = cfg . dataHome ; 89XDG_STATE_HOME = cfg . stateHome ; 90}; 91in mkIf cfg . enable { 92xdg . cacheHome = mkDefault defaultCacheHome ; 93xdg . configHome = mkDefault defaultConfigHome ; 94xdg . dataHome = mkDefault defaultDataHome ; 95xdg . stateHome = mkDefault defaultStateHome ; 96 97home . sessionVariables = variables ; 98systemd . user . sessionVariables = 99mkIf pkgs . stdenv . hostPlatform . isLinux variables ; 100}) 101 102# Legacy non-deterministic setup. 103( mkIf ( ! cfg . enable && versionOlder config . home . stateVersion "20.09" ) { 104xdg . cacheHome = 105mkDefault ( getEnvFallback "XDG_CACHE_HOME" defaultCacheHome ); 106xdg . configHome = 107mkDefault ( getEnvFallback "XDG_CONFIG_HOME" defaultConfigHome ); 108xdg . dataHome = mkDefault ( getEnvFallback "XDG_DATA_HOME" defaultDataHome ); 109}) 110 111# "Modern" deterministic setup. 112( mkIf ( ! cfg . enable && versionAtLeast config . home . stateVersion "20.09" ) { 113xdg . cacheHome = mkDefault defaultCacheHome ; 114xdg . configHome = mkDefault defaultConfigHome ; 115xdg . dataHome = mkDefault defaultDataHome ; 116xdg . stateHome = mkDefault defaultStateHome ; 117}) 118 119{ 120home . file = mkMerge [ 121( mapAttrs' ( name :file :nameValuePair " ${ cfg . configHome } / ${ name } " file ) 122cfg . configFile ) 123( mapAttrs' ( name :file :nameValuePair " ${ cfg . dataHome } / ${ name } " file ) 124cfg . dataFile ) 125{ " ${ cfg . cacheHome } /.keep" . text = "" ; } 126]; 127} 128]; 129}