{ config, lib, this, ... }: with lib; let cfg = config.nixfiles.modules.common.xdg; in { imports = let withBase = a: [ "nixfiles" "modules" "common" "xdg" a ]; in [ (mkAliasOptionModule [ "dirs" "cache" ] (withBase "cacheHome")) (mkAliasOptionModule [ "dirs" "config" ] (withBase "configHome")) (mkAliasOptionModule [ "dirs" "data" ] (withBase "dataHome")) (mkAliasOptionModule [ "dirs" "state" ] (withBase "stateHome")) (mkAliasOptionModule [ "userDirs" ] (withBase "userDirs")) ]; options.nixfiles.modules.common.xdg = { cacheHome = mkOption { type = types.str; default = "${config.hm.home.homeDirectory}/.cache"; }; configHome = mkOption { type = types.str; default = "${config.hm.home.homeDirectory}/.config"; }; dataHome = mkOption { type = types.str; default = "${config.hm.home.homeDirectory}/.local/share"; }; stateHome = mkOption { type = types.str; default = "${config.hm.home.homeDirectory}/.local/state"; }; userDirs = mkOption { type = types.attrs; default = let inherit (config.my) home; tmp = home + "/tmp"; in { enable = true; desktop = tmp; documents = "${home}/doc"; download = tmp; music = tmp; pictures = tmp; publicShare = "${home}/share"; templates = tmp; videos = tmp; }; }; defaultApplications = mkOption { description = "Default applications."; type = with types; attrsOf (listOf str); default = { }; }; }; config = { xdg.portal = mkIf this.isHeadful { enable = true; }; hm.xdg = mkMerge [ (with cfg; { enable = true; inherit cacheHome; inherit configHome; inherit dataHome; inherit stateHome; inherit userDirs; }) (mkIf this.isHeadful { mimeApps = { enable = true; defaultApplications = mkMerge ( mapAttrsToList (n: v: genAttrs v (_: [ "${n}.desktop" ])) cfg.defaultApplications ); }; }) ]; }; }