I can't install a package I defined in flake in a nixosConfigurations

Hello! I wrote a flake that outputs two NixOS configuration and one package. The package contains a faw symlinks from one of the NixOS configuration (blackhole):

$ nix flake show ./machines/lab-generic-netbooting/
warning: Git tree '/home/gianarb/.dotfiles' is dirty
git+file:///home/gianarb/.dotfiles?dir=nixos%2fmachines%2flab-generic-netbooting
├───nixosConfigurations
│   ├───blackhole: NixOS configuration
│   └───pixiecore-dispatcher: NixOS configuration
└───packages
    └───x86_64-linux
        └───blackhole: package 'blackhole'
{
  description = "A very basic flake";
  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-22.05";
  };
  outputs = { self, nixpkgs }: {
    nixosConfigurations = {
      # This is an utility to test with:
      # $ nix build-vm
      # In reality what I want to build here is a package. In this way I can
      # deploy such OS via pixecore
      blackhole = nixpkgs.lib.nixosSystem {
        system = "x86_64-linux";
        modules = [
          ./netbooting-os.nix
        ];
      };
      # This is the machine that distribute netbooting images via Pixiecore.
      # It distributes the one we have just built for now but as a follow up
      # I will write some software that integrates with pixiecore api
      # https://github.com/danderson/netboot/blob/master/pixiecore/README.api.md
      pixiecore-dispatcher = nixpkgs.lib.nixosSystem {
        system = "x86_64-linux";
        modules = [
          ./pixiecore-dispatcher.nix
        ];
      };
    };
    packages.x86_64-linux.blackhole = nixpkgs.legacyPackages.x86_64-linux.symlinkJoin {
      name = "blackhole";
      paths = with self.nixosConfigurations.blackhole.config.system.build; [
        netbootRamdisk
        kernel
        netbootIpxeScript
      ];
    };
  };
}

In practice I want to distribute blackhole via netbooting using pixiecore but I can’t figure out how to install the package blackhole in pixiecore-dispatcher

This is the pixiecore dispatcher configuration.nix but pkgs.blackhole is not available

{ config, pkgs, lib, modulesPath, ... }: with lib; {
  imports = [
    (modulesPath + "/installer/netboot/netboot-base.nix")
    ./tailscale.nix
  ];
  users.users.root.openssh.authorizedKeys.keys = [
    "ssh-"
  ];

  environment.systemPackages = [ pkgs.pixiecore pkgs.blackhole ];

  services.pixiecore.enable = true;
  services.pixiecore.openFirewall = true;


  ## Some useful options for setting up a new system
  services.getty.autologinUser = mkForce "root";

  networking.dhcpcd.enable = true;
  networking.hostName = "pixiecore-dispatcher";

  services.openssh.enable = true;
  services.tailscale.enable = true;

  hardware.cpu.intel.updateMicrocode =
    lib.mkDefault config.hardware.enableRedistributableFirmware;

  system.stateVersion = "22.05";
}

I am not sure if this is the right way I solved via overlay:

      pixiecore-dispatcher =
        let
          system = "x86_64-linux";
          overlay-lab = final: prev: {
            lab = self.packages.${prev.system};
          };
        in
        nixpkgs.lib.nixosSystem {
          inherit system;
          modules = [
            ({ config, pkgs, ... }: { nixpkgs.overlays = [ overlay-lab ]; })
            ./pixiecore-dispatcher.nix
          ];
        };

And the pixiecore-dispatcher.nix configuration uses pkgs.lab.blackhole to install the derivation.

Here’s how I’d implement it. This evaluates pkgs only once (instead of 3 times).

This looks way better!! Thank you for sharing your solution! I tried to get to something that clean on my own but I didn’t manage to do it!