nix-community / impermanence

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

How do I enable Home Manager support with a Flake configuration? #57

Closed a12l closed 2 years ago

a12l commented 2 years ago

I've a NixOS configuration based on Nix Flakes. I've imported Home Manager as a module.

Minimal viable example of my NixOS configuration flake.nix:

{
  description = "NixOS configuration";

  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-21.11";

    home-manager.url = "github:nix-community/home-manager/master";

    impermanence.url = "github:nix-community/impermanence/master";
  };

  outputs = { self, nixpkgs, home-manager, impermanence }: {
    nixosConfigurations = let
      system = "x86_64-linux";

      lib = nixpkgs.lib;
    in {
      computerName = nixpkgs.lib.nixosSystem {
        inherit system;

        modules = [
          ({ pkgs, ... }: {
            # Safely erasing the root dataset on each boot
            boot.initrd.postDeviceCommands = lib.mkAfter ''
              zfs rollback -r zroot/ROOT/root@blank
            '';

            networking.hostName = "computerName";

            users.users.a12l = {
              home = "/home/a12l";
              isNormalUser = true;
            };

            nix.extraOptions = ''
              experimental-features = nix-command flakes
            '';

            system.stateVersion = "21.11";
          })

          home-manager.nixosModules.home-manager
          {
            home-manager.useGlobalPkgs = true;
            home-manager.useUserPackages = true;
            home-manager.users.a12l = {
              home.username = "a12l";
              home.homeDirectory = "/home/a12l";
            };
          }

          impermanence.nixosModules.impermanence
          {
            environment.persistence."/persistent" = {
              directories = [
                "/var/log"
                "/var/lib/bluetooth"
                "/var/lib/systemd/coredump"
                "/etc/NetworkManager/system-connections"
              ];

              files = [ "/etc/machine-id" ];
            };
          }
        ];
      };
    };
  };
}

To where should I send this attribute set?

{
  home.persistence."/persistent/home/a12l" = {
    directories = [
      "Example"
    ];

    files = [
      ".examplerc"
    ];

    allowOther = true;
  };
}

When I look at impermanence's flake.nix, it seems that only the module for system configurations is available via the flake interface?

{
  outputs = { self }: {
    nixosModules.impermanence = import ./nixos.nix;
  };
}

I can use environment.persistence."/persistent/home/a12l", but then I don't for example have the allowOther attribute.

{
  environment.persistence."/persistent/home/a12l" = {
    directories = [
      "Example"
    ];

    files = [
      ".examplerc"
    ];

    allowOther = true;
  };
}
a12l commented 2 years ago

Well, found the PR directly after posting the issue.