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

Issues creating persistence directory #102

Closed chz101 closed 1 year ago

chz101 commented 1 year ago

Hi, I recently tried to run impermanence as a home manager module under flakes, for a tempfs / and /home setup following etu's blog post, but am having issues when calling nix-rebuild:

building the system configuration...
activating the configuration...
setting up /etc...
reloading user units for chuck...
setting up tmpfiles
warning: the following units failed: home-manager-chuck.service

× home-manager-chuck.service - Home Manager environment for chuck
     Loaded: loaded (/etc/systemd/system/home-manager-chuck.service; enabled; preset: enabled)
     Active: failed (Result: exit-code) since Mon 2022-08-22 09:58:12 MDT; 45ms ago
   Duration: 5h 20min 21.974s
    Process: 41292 ExecStart=/nix/store/gzzla4ws2brdjnxshsb29hnnm2hxwfrn-hm-setup-env /nix/store/cszx0lfnkkkhcyrch458kh15mvyqdxrk-home-manager-generation (code=exited, status=1/FAILURE)
   Main PID: 41292 (code=exited, status=1/FAILURE)
         IP: 0B in, 0B out
        CPU: 55ms

Aug 22 09:58:12 nixos systemd[1]: Starting Home Manager environment for chuck...
Aug 22 09:58:12 nixos hm-activate-chuck[41292]: Starting Home Manager activation
Aug 22 09:58:12 nixos hm-activate-chuck[41292]: Activating checkFilesChanged
Aug 22 09:58:12 nixos hm-activate-chuck[41292]: Activating checkLinkTargets
Aug 22 09:58:12 nixos hm-activate-chuck[41292]: Activating unmountPersistentStoragePaths
Aug 22 09:58:12 nixos hm-activate-chuck[41292]: Activating createAndMountPersistentStoragePaths
Aug 22 09:58:12 nixos hm-activate-chuck[41328]: mkdir: cannot create directory ‘/nix/persist/home/.dotfiles’: Permission denied
Aug 22 09:58:12 nixos systemd[1]: home-manager-chuck.service: Main process exited, code=exited, status=1/FAILURE
Aug 22 09:58:12 nixos systemd[1]: home-manager-chuck.service: Failed with result 'exit-code'.
Aug 22 09:58:12 nixos systemd[1]: Failed to start Home Manager environment for chuck.
warning: error(s) occurred while switching to the new configuration

Manually updating permissions using chmod 777 /nix/persist/home gives a different error:

Aug 22 10:00:49 nixos hm-activate-chuck[41677]: fuse: mountpoint is not empty
Aug 22 10:00:49 nixos hm-activate-chuck[41677]: fuse: if you are sure this is safe, use the 'nonempty' mount option

The directory is created correctly, but it still throws this error. Rebuilding multiple times and manually deleting the directory both don't solve the problem.

My flake.nix file looks as follows

{
  description = "A very basic flake";

  inputs = {
    nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
    home-manager = {
      url = "github:nix-community/home-manager";
      inputs.nixpkgs.follows = "nixpkgs";
    };

    impermanence = {
      url = "github:nix-community/impermanence";
      inputs.nixpkgs.follows = "nixpkgs";
    };

    hyprland = {
      url = "github:hyprwm/Hyprland";
      inputs.nixpkgs.follows = "nixpkgs";
    };

  };

  outputs = inputs@{ self, nixpkgs, home-manager, impermanence, hyprland, ... }:
    let
      system = "x86_64-linux";
      pkgs = import nixpkgs {
        inherit system;
        config.allowUnfree = true;
      };
      lib = nixpkgs.lib;
    in {
      nixosConfigurations = {
        nixos = nixpkgs.lib.nixosSystem {
          inherit system;
          modules = [
            ./configuration.nix
            home-manager.nixosModules.home-manager
            {
              home-manager.useGlobalPkgs = true;
              home-manager.useUserPackages = true;
              home-manager.users.chuck = { pkgs, ... }: {
                home.homeDirectory = "/home/chuck";
                imports = [ impermanence.nixosModules.home-manager.impermanence
                            ./home.nix
                ];

                #programs.home-manager.enable = true;
                #home.persistence."....
                #environment.persistence ...
              };
            }
            hyprland.nixosModules.default
            { programs.hyprland.enable = true; }
          ];
        };
      };
    };
}

and my home.nix just in case it's necessary

{ config, pkgs, ... }:

{
  home.username = "chuck";
  home.homeDirectory = "/home/chuck";

  home.stateVersion = "22.05";

  home.persistence."/nix/persist/home" = {

    directories = [
      ".dotfiles"
    ];

    allowOther = true;

  };

  # Let Home Manager manage itself
  programs.home-manager.enable = true;
}

If there are things that I'm missing or that I should try, please let me know. Thank you.

emmanuelrosa commented 1 year ago

/nix is meant to be read-only, so perhaps you should use a different location for your persist path.

talyz commented 1 year ago

Hi! You need to create your home directory manually in persistent storage with the correct permissions, since the module runs as your user and won't have the permissions to so. The non-empty error occurs because directories you've listed in your config have already been created in ephemeral storage - to get rid of this error, move the directories out of the way or simply reboot your system.

chz101 commented 1 year ago

Got it working by moving things away. Thanks!