about summary refs log blame commit diff
path: root/modules/common/xdg.nix
blob: 805afe1203e7efe4c8c97ccec8ea7b9c2557c8d0 (plain) (tree)
1
2
3
4
5
6
7
8
9




         

                                           
 









                     
                                

                               
                                

                                
                                

                              
                                

                               
                                                                    
      
                                         
                              
                                                         
                               
                                                          
                             
                                                               
                              
                                                               
                             





                                   
 







                                        
      
                                        
                                            
                                                  



                    
           



                                          
                                     
 
                          
       
                      






                     
                                
                        


                                                                                

          
    
{
  config,
  lib,
  this,
  ...
}:
let
  cfg = config.nixfiles.modules.common.xdg;
in
{
  imports =
    let
      withBase = a: [
        "nixfiles"
        "modules"
        "common"
        "xdg"
        a
      ];
    in
    [
      (lib.mkAliasOptionModule [
        "dirs"
        "cache"
      ] (withBase "cacheHome"))
      (lib.mkAliasOptionModule [
        "dirs"
        "config"
      ] (withBase "configHome"))
      (lib.mkAliasOptionModule [
        "dirs"
        "data"
      ] (withBase "dataHome"))
      (lib.mkAliasOptionModule [
        "dirs"
        "state"
      ] (withBase "stateHome"))
      (lib.mkAliasOptionModule [ "userDirs" ] (withBase "userDirs"))
    ];

  options.nixfiles.modules.common.xdg = {
    cacheHome = lib.mkOption {
      type = lib.types.str;
      default = "${config.hm.home.homeDirectory}/.cache";
    };
    configHome = lib.mkOption {
      type = lib.types.str;
      default = "${config.hm.home.homeDirectory}/.config";
    };
    dataHome = lib.mkOption {
      type = lib.types.str;
      default = "${config.hm.home.homeDirectory}/.local/share";
    };
    stateHome = lib.mkOption {
      type = lib.types.str;
      default = "${config.hm.home.homeDirectory}/.local/state";
    };
    userDirs = lib.mkOption {
      type = lib.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 = lib.mkOption {
      description = "Default applications.";
      type = with lib.types; attrsOf (listOf str);
      default = { };
    };
  };

  config = {
    xdg = {
      portal = {
        enable = this.isHeadful;
        xdgOpenUsePortal = this.isHeadful;
      };

      sounds.enable = this.isHeadful;
    };

    hm.xdg = lib.mkMerge [
      {
        enable = true;

        inherit (cfg)
          cacheHome
          configHome
          dataHome
          stateHome
          userDirs
          ;
      }
      (lib.mkIf this.isHeadful {
        mimeApps = {
          enable = true;
          defaultApplications =
            cfg.defaultApplications
            |> lib.mapAttrsToList (n: v: lib.genAttrs v (_: [ "${n}.desktop" ]))
            |> lib.mkMerge;
        };
      })
    ];
  };
}

Consider giving Nix/NixOS a try! <3