{ nixpkgs
, nixpkgs-unstable
, home-manager
, nix-flatpak
, ...
}:

let
  mkPkgsUnstable =
    system:
    import nixpkgs-unstable {
      inherit system;
      config.allowUnfree = true;
    };
in

{
  nixosConfigurations = {
    "gandalf" = nixpkgs.lib.nixosSystem {
      system = "x86_64-linux";
      specialArgs = {
        pkgsUnstable = mkPkgsUnstable "x86_64-linux";
        nixFlatpak = nix-flatpak;
      };
      modules = [
        nix-flatpak.nixosModules.nix-flatpak
        home-manager.nixosModules.home-manager
        ./systems/gandalf
      ];
    };
    "frodo" = nixpkgs.lib.nixosSystem {
      system = "x86_64-linux";
      specialArgs = {
        pkgsUnstable = mkPkgsUnstable "x86_64-linux";
        nixFlatpak = nix-flatpak;
      };
      modules = [
        nix-flatpak.nixosModules.nix-flatpak
        home-manager.nixosModules.home-manager
        ./systems/frodo
      ];
    };
    "legolas" = nixpkgs.lib.nixosSystem {
      system = "x86_64-linux";
      specialArgs = {
        pkgsUnstable = mkPkgsUnstable "x86_64-linux";
        nixFlatpak = nix-flatpak;
      };
      modules = [
        nix-flatpak.nixosModules.nix-flatpak
        home-manager.nixosModules.home-manager
        ./systems/legolas
      ];
    };
    "balrog" = nixpkgs.lib.nixosSystem {
      system = "x86_64-linux";
      specialArgs = {
        pkgsUnstable = mkPkgsUnstable "x86_64-linux";
        nixFlatpak = nix-flatpak;
      };
      modules = [
        nix-flatpak.nixosModules.nix-flatpak
        home-manager.nixosModules.home-manager
        ./systems/balrog
      ];
    };
    "work" = nixpkgs.lib.nixosSystem {
      system = "x86_64-linux";
      specialArgs = {
        pkgsUnstable = mkPkgsUnstable "x86_64-linux";
        nixFlatpak = nix-flatpak;
      };
      modules = [
        nix-flatpak.nixosModules.nix-flatpak
        home-manager.nixosModules.home-manager
        ./systems/work
      ];
    };
  };
}
