fork/home-manager
git clone https://git.julia.blue/fork/home-manager
75790441
master
1{ config , lib , pkgs , ...} : 2 3with lib ; 4 5let 6 7cfg = config . xdg . userDirs ; 8 9in { 10meta . maintainers = with maintainers ; [ pacien ]; 11 12imports = [ 13( mkRenamedOptionModule [ "xdg" "userDirs" "publishShare" ] [ 14"xdg" 15"userDirs" 16"publicShare" 17]) 18]; 19 20options . xdg . userDirs = { 21enable = mkOption { 22type = types . bool ; 23default = false ; 24description = '' 25Whether to manage {file}`$XDG_CONFIG_HOME/user-dirs.dirs`. 26 27The generated file is read-only. 28'' ; 29}; 30 31# Well-known directory list from 32# https://gitlab.freedesktop.org/xdg/xdg-user-dirs/blob/master/man/user-dirs.dirs.xml 33 34desktop = mkOption { 35type = with types ; nullOr ( coercedTo path toString str ); 36default = " ${ config . home . homeDirectory } /Desktop" ; 37defaultText = 38literalExpression ''"''${config.home.homeDirectory}/Desktop"'' ; 39description = "The Desktop directory." ; 40}; 41 42documents = mkOption { 43type = with types ; nullOr ( coercedTo path toString str ); 44default = " ${ config . home . homeDirectory } /Documents" ; 45defaultText = 46literalExpression ''"''${config.home.homeDirectory}/Documents"'' ; 47description = "The Documents directory." ; 48}; 49 50download = mkOption { 51type = with types ; nullOr ( coercedTo path toString str ); 52default = " ${ config . home . homeDirectory } /Downloads" ; 53defaultText = 54literalExpression ''"''${config.home.homeDirectory}/Downloads"'' ; 55description = "The Downloads directory." ; 56}; 57 58music = mkOption { 59type = with types ; nullOr ( coercedTo path toString str ); 60default = " ${ config . home . homeDirectory } /Music" ; 61defaultText = 62literalExpression ''"''${config.home.homeDirectory}/Music"'' ; 63description = "The Music directory." ; 64}; 65 66pictures = mkOption { 67type = with types ; nullOr ( coercedTo path toString str ); 68default = " ${ config . home . homeDirectory } /Pictures" ; 69defaultText = 70literalExpression ''"''${config.home.homeDirectory}/Pictures"'' ; 71description = "The Pictures directory." ; 72}; 73 74publicShare = mkOption { 75type = with types ; nullOr ( coercedTo path toString str ); 76default = " ${ config . home . homeDirectory } /Public" ; 77defaultText = 78literalExpression ''"''${config.home.homeDirectory}/Public"'' ; 79description = "The Public share directory." ; 80}; 81 82templates = mkOption { 83type = with types ; nullOr ( coercedTo path toString str ); 84default = " ${ config . home . homeDirectory } /Templates" ; 85defaultText = 86literalExpression ''"''${config.home.homeDirectory}/Templates"'' ; 87description = "The Templates directory." ; 88}; 89 90videos = mkOption { 91type = with types ; nullOr ( coercedTo path toString str ); 92default = " ${ config . home . homeDirectory } /Videos" ; 93defaultText = 94literalExpression ''"''${config.home.homeDirectory}/Videos"'' ; 95description = "The Videos directory." ; 96}; 97 98extraConfig = mkOption { 99type = with types ; attrsOf ( coercedTo path toString str ); 100default = { }; 101defaultText = literalExpression "{ }" ; 102example = literalExpression '' 103{ 104XDG_MISC_DIR = "''${config.home.homeDirectory}/Misc"; 105} 106'' ; 107description = "Other user directories." ; 108}; 109 110createDirectories = 111mkEnableOption "automatic creation of the XDG user directories" ; 112}; 113 114config = let 115directories = ( filterAttrs ( n :v :! isNull v ) { 116XDG_DESKTOP_DIR = cfg . desktop ; 117XDG_DOCUMENTS_DIR = cfg . documents ; 118XDG_DOWNLOAD_DIR = cfg . download ; 119XDG_MUSIC_DIR = cfg . music ; 120XDG_PICTURES_DIR = cfg . pictures ; 121XDG_PUBLICSHARE_DIR = cfg . publicShare ; 122XDG_TEMPLATES_DIR = cfg . templates ; 123XDG_VIDEOS_DIR = cfg . videos ; 124}) // cfg . extraConfig ; 125in mkIf cfg . enable { 126assertions = 127[ ( hm . assertions . assertPlatform "xdg.userDirs" pkgs platforms . linux ) ]; 128 129xdg . configFile . "user-dirs.dirs" . text = let 130# For some reason, these need to be wrapped with quotes to be valid. 131wrapped = mapAttrs ( _ :value :''" ${ value } "'' ) directories ; 132in generators . toKeyValue { } wrapped ; 133 134xdg . configFile . "user-dirs.conf" . text = "enabled=False" ; 135 136home . sessionVariables = directories ; 137 138home . activation . createXdgUserDirectories = mkIf cfg . createDirectories ( let 139directoriesList = attrValues directories ; 140mkdir = ( dir :''$DRY_RUN_CMD mkdir -p $VERBOSE_ARG " ${ dir } "'' ); 141in lib . hm . dag . entryAfter [ "linkGeneration" ] 142( strings . concatMapStringsSep "\n" mkdir directoriesList )); 143}; 144}