From e6ed60548397627bf10f561f9438201dbba0a36e Mon Sep 17 00:00:00 2001 From: Azat Bahawi Date: Sun, 21 Apr 2024 02:15:42 +0300 Subject: 2024-04-21 --- modules/common/xdg.nix | 109 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 109 insertions(+) create mode 100644 modules/common/xdg.nix (limited to 'modules/common/xdg.nix') diff --git a/modules/common/xdg.nix b/modules/common/xdg.nix new file mode 100644 index 0000000..c581369 --- /dev/null +++ b/modules/common/xdg.nix @@ -0,0 +1,109 @@ +{ + 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 + ); + }; + }) + ]; + }; +} -- cgit 1.4.1