summaryrefslogtreecommitdiff
path: root/modules/common/xdg.nix
diff options
context:
space:
mode:
authorAzat Bahawi <azat@bahawi.net>2024-04-21 02:15:42 +0300
committerAzat Bahawi <azat@bahawi.net>2024-04-21 02:15:42 +0300
commite6ed60548397627bf10f561f9438201dbba0a36e (patch)
treef9a84c5957d2cc4fcd148065ee9365a0c851ae1c /modules/common/xdg.nix
parent9ac64328603d44bd272175942d3ea3eaadcabd04 (diff)
2024-04-21
Diffstat (limited to 'modules/common/xdg.nix')
-rw-r--r--modules/common/xdg.nix109
1 files changed, 109 insertions, 0 deletions
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
+ );
+ };
+ })
+ ];
+ };
+}