nix-community / impermanence

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

Add capability to let impemanence create the `persistentStoragePath` #163

Open portiatrivisonno opened 8 months ago

portiatrivisonno commented 8 months ago

Add option createPersistentStoragePath (bool) which, if set, creates the directory persistentStoragePath during activation phase. The default is set to true as I think this is what most people expect and also avoids some permissions mismatches (see below). If you do not agree for whatever reason, feel free to drop the commit enabling it by default.

The permission mismatch might also be related to #139.

More Background

Beginning of the story is, that I bootstrapped a new system with this config:

  environment.persistence."home" = {
    persistentStoragePath = "/persist/user/this/dir/does/not/yet/exist";
    users."me" = {
      directories = [
        "cooldir"
      ];
    };
  };

After rebooting, cooldir was created by owned by root. It took me a while but the problem is/was that impermanence failed to create /home/me/cooldir inside the persistentStoragePath location (because that directory does not exist). However, a bind entry was created in /etc/fstab which triggered systemd-fstab-generator to generated that mount and in the process also create the missing directories but with root permissions.

With this PR the config could look like

  environment.persistence."home" = {
    persistentStoragePath = "/persist/user/this/dir/does/not/yet/exist";
    createPersistentStoragePath = true;
    users."me" = {
      directories = [
        "cooldir"
      ];
    };
  };