Home-manager xdg.cacheHome option not working as expected

{
  home.preferXdgDirectories = true;
  xdg = {
    enable = true;
    dataHome = "~/.local/share";
    stateHome = "~/.local/state";
    cacheHome = "~/.cache";
    configHome = "~/.config";

    mime = {
      enable = true;
    };
    mimeApps = {
      enable = true;

      defaultApplications = {
        "application/pdf" = "org.pwmt.zathura-pdf.desktop";
      };
    };

    systemDirs = {
      data = [
        "/usr/share"
        "/usr/local/share"
      ];

      config = [ "/etc/xdg" ];
    };

    userDirs = {
      enable = true;
      createDirectories = true;
    };
  };
}

The above is my xdgsettings.nix. The result of nixos-re build switch is

error: A definition for option `home-manager.users.krish.xdg.cacheHome' is not of type `path'. Definition values:
       - In `/nix/store/qqag6l1n0cfdw8lx4y5qhcs8jbiacj8v-source/modules/user/xdgsettings.nix': "~/.cache"

But I am just giving the default value as is.

No, you are not. The “default” is only for easier reading. The actual default is ”${config.home.homeDirectory}/.cache".

And you should build the location the same way.

1 Like

Why do you want to provide the default value again?

Thanks. But why isn’t it mentioned in the description.

Well, even if the default value is being passed, it should work right?

1 Like

I’m just trying to understand the purpose of your code to re-pass the default value. It’s unusual code in my opinion. (And of course as discussed, it wasn’t the default.)

Oh. I was just trying to see if it could be changed, how it might be changed. Or whether it creates symlinks or updates the environment variables to achieve the purpose. Of course looking at the nix code would tell that. But, I am a total noob. And so, this change in code.

Nix doesn’t do shell expansion so instead of ~ becoming /home/user you would end with a directory named ~ in your home directory.

But that won’t work either because the option takes an absolute path, not a relative one.

~/.cache shows up as the “default” because of how the option is constructed, the module system has a way to make documentation display a specific string (defaultText) instead of the actual value (default):

1 Like