srid / nixos-flake

A flake-parts module to manage NixOS and macOS machines, along with home-manager support, in a unified fashion.
https://community.flake.parts/nixos-flake
MIT License
175 stars 19 forks source link

Per-host home-manager configurations #19

Closed srid closed 2 months ago

srid commented 1 year ago

cc @bketelsen

Basically add hostname, along with username, to the legacyPackages.homeConfigurations keys.

{
  legacyPackages.homeConfigurations = rec {
    default = ...;
    "srid@macbook1" = default;
    "srid@linux-desktop1" = default;
  };
}

Then nix run .#activate -- --home (see #18) knows which configuration to activate.

ParetoOptimalDev commented 9 months ago

I tried to temporarily make this work in a somewhat hacky way since:

But it doesn't work for some reason.

If you have any ideas on a quick work-around it would save me the time of having to go back to flake-utils-plus where I know how to do this. Long term I think I want a flake-parts based config... I think :)

Here's my code:

{
  # ...
  outputs = inputs@{ self, ... }:
    inputs.flake-parts.lib.mkFlake { inherit inputs; } {
      # ...
      flake = {
        nixosConfigurations = {
          laptop = self.nixos-flake.lib.mkLinuxSystem {
            imports = [
              self.nixosModules.default
              ./nixos/gui/wayland.nix
              {
                # not ideal, see https://github.com/srid/nixos-flake/issues/19
                home-manager.users.paretoOptimalDev = [
                    ./home/window-manager/sway.nix
                ];
              }
            ];
          };
        };
      };
    };
}
srid commented 9 months ago

Well, this should be straightforward to implement, right?

Look for hostname (fallback to $USER), and then use that to set the attribute here ... all done in the bash script:

https://github.com/srid/nixos-flake/blob/40010feda1ac1afdcc2571ef550ef3de44926b0e/flake-module.nix#L94-L95

srid commented 9 months ago

Ideally we want to have that in this repo, but for quick workaround, you can simply add a writeShellApplication based flake app that does this.

srid commented 2 months ago

Alright, checkout #60

With it, you can do nix run . $USER@$HOSTNAME