nix-community / impermanence

Modules to help you handle persistent state on systems with ephemeral root storage [maintainer=@talyz]
MIT License
1.03k stars 77 forks source link

Certain persisted directories are owned by root instead of my user using the NixOS module #140

Closed robbins closed 10 months ago

robbins commented 10 months ago

I used to have my files in ~ persisted using the Home Manager module, but I wanted to switch to the NixOS module. However, when I persist any directories in .config, .local, or .cache, the parent directories of the persisted directory is owned by root/root.

Example (some conditionally included files in the non-user section were excluded):

  environment.persistence."/persist" = {
      hideMounts = true;
      files = [
        { file = "/etc/machine-id"; parentDirectory = { user = "root"; group = "root"; }; }
      users."${specialArgs.username}" = {
        files = [
          ".config/gh/hosts.yml"
    ];
        directories = [
          ".local/share/backgrounds"
          "downloads"
          "pictures"
          "music"
          "videos"
          ".icons"
          ".minecraft"
          ".ssh"
          ".android"
     ".gradle"
     ".themes"
    ];
      };
    };

drwxr-xr-x 3 root root 60 Sep 9 14:27 .local drwxr-xr-x 3 root root 60 Sep 9 14:27 share drwxr-xr-x 2 nate users 118 Aug 5 13:24 backgrounds

This doesn't happen when persisting other directories. eg ~/.themes is owned by my_username users. These same persistent directories worked fine when using the HM module.

My persistent directory /persist is a ZFS dataset, and the ownership on /persist all the way down to /persist/home/my_username/.local/share/backgrounds is my_username users.

It seems to be the same issue as https://github.com/nix-community/impermanence/issues/74.

Impeprmanence version: e3a7acd113903269a1b5c8b527e84ce7ee859851 (Latest commit) NixOS version: 0bffda19b8af722f8069d09d8b6a24594c80b352 (Latest NixOS unstable commit) journalctl -b output with debugging enabled: https://katb.in/fexoyefeqif

talyz commented 10 months ago

Do you mount /home or any of its children separately? This was the issue in #74.

robbins commented 10 months ago

All I have is

  fileSystems."/home/my_username" =
    {
      device = "none";
      fsType = "tmpfs"; 
      options = [ "defaults" "size=500M" "mode=755" ];
    };
talyz commented 10 months ago

Okay, then that's the issue. If you need to mount the home directory separately, it must be marked as neededForBoot.

robbins commented 10 months ago

Thanks, re-reading #74, it makes sense.

neededForBoot = true solved the problem.