nix-community / impermanence

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

home-manager module cannot mount files to /persist. permission denied. #184

Open mairs8 opened 6 months ago

mairs8 commented 6 months ago

i am having a nightmare trying to get the home-manager impermanence module to work. keep getting permission denied error and it does not appear to be mounting the home files to my /persist/home location. i am trying below but it is not a good approach and still i get error on the files now 'failed to create symbolic link '/home/billy/.config/gh/config.yml': Permission denied'. what am i doing wrong? is there a better way to do this? do i get same error if i was to use zfs over btrfs?


  systemd.tmpfiles.rules = [
    "d /persist/system/var/lib/nixos 0755 root root -"
    "d /persist/system/etc/nixos 0755 root root -"
    "d /persist/system/var/log 0755 root root -"

"d /persist/home/.local/share/docker 0755 root root -"
"d /persist/home/.config/VSCodium 0755 root root -"
"d /persist/home/.vscode 0755 root root -"
"d /persist/home/.vscode-oss 0755 root root -"
"d /persist/home/.config/libvirt 0755 root root -"
"d /persist/home/.zsh_history 0755 root root -"
"d /persist/home/.config/rclone 0755 root root -"
"d /persist/home/.config/rclone-browser 0755 root root -"
"d /persist/home/.config/qutebrowser/bookmarks 0755 root root -"
"d /persist/home/.config/qutebrowser/greasemonkey 0755 root root -"
"d /persist/home/.local/share/qutebrowser 0755 root root -"
"d /persist/home/.password-store 0755 root root -"
"d /persist/home/.config/nvim 0755 root root -"
"d /persist/home/.local/share/nvim 0755 root root -"
"d /persist/home/.local/state/nvim 0755 root root -"
"d /persist/home/tutorials 0755 root root -"
"d /persist/home/.config/go 0755 root root -"
"d /persist/home/.config/dlv 0755 root root -"
"d /persist/home/.virtualenvs 0755 root root -"
"d /persist/home/.gradle 0755 root root -"
"d /persist/home/notes 0755 root root -"
"d /persist/home/.pki 0755 root root -"
"d /persist/home/.cache/google-chrome 0755 root root -"
"d /persist/home/.cache/fontconfig 0755 root root -"
"d /persist/home/.config/google-chrome 0755 root root -"
"d /persist/home/.config/git 0755 root root -"
"d /persist/home/.config/gh 0755 root root -"
"d /persist/home/.gnupg 0755 root root -"

  ];

example of what i am doing for home persistence. is this not following best practices?

  home.persistence."/persist/home" = {
    directories = [
      ".config/qutebrowser/bookmarks"
      ".config/qutebrowser/greasemonkey"
      ".local/share/qutebrowser"
    ];
  };
karaolidis commented 5 months ago

I am having a similar issue where persisting files works fine, but directories are not linked/mounted. Did you figure this out?

testplayername commented 4 months ago

I had a permissions issue in which the Home Manager Impermanence module does not have permission to create each users' home folders in /home (e.g. /home/billy).

I use this systemd service to ensure each users' home folders exist:

systemd.services."persist-home-create-root-paths" =
let
    persistentHomesRoot = "/persist";

    listOfCommands = l.mapAttrsToList
        (_: user:
        let
            userHome = l.escapeShellArg (persistentHomesRoot + user.home);

        in ''
            if [[ ! -d ${userHome} ]]; then
                echo "Persistent home root folder '${userHome}' not found, creating..."
                mkdir -p --mode=${user.homeMode} ${userHome}
                chown ${user.name}:${user.group} ${userHome}
            fi
            ''
        )
        (l.filterAttrs (_: user: user.createHome == true) config.users.users);

    stringOfCommands = l.concatLines listOfCommands;
in {
    script = stringOfCommands;
    unitConfig = {
        Description = "Ensure users' home folders exist in the persistent filesystem";
        PartOf = [ "local-fs.target" ];
        # The folder creation should happen after the persistent home path is mounted.
        After = [ "persist-home.mount" ];
    };

    serviceConfig = {
        Type = "oneshot";
        StandardOutput = "journal";
        StandardError = "journal";
    };

    # [Install]
    wantedBy = [ "local-fs.target" ];

};
SolidRhino commented 2 months ago

Had the same problem fixed with the systemd services! Is there a complete fix on the way? @talyz

talyz commented 1 month ago

For now, I would recommend using the NixOS module with the users option instead of the home-manager module to solve this issue. The problem is that home-manager runs as the user and only has its permissions, so it can't create the initial user home directory.