I have a recursive package set (by-name style, using lib.packagesFromDirectoryRecursive
) and I want that set to contain both packages and nixos configuration (using pkgs.nixos
). I want the nixos configs in the set to be able to use packages from that same set. Also there are packages that depend on nixos configs, which is why I can’t define the package set first, then put that in a top-level overlay and define my nixos configs based on that.
To do that, I tried to set nixpkgs.pkgs = pkgs';
in the nixos config, where pkgs'
is the final package set, containing both the original pkgs of the nixpkgs evaluation and the packages from my set.
{
inputs.nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";
outputs =
{ nixpkgs, ... }:
let
pkgs = import nixpkgs { system = "x86_64-linux"; };
foo = pkgs.runCommand "foo" { } ''echo "this is foo and fails!"'';
pkgs' = pkgs // { inherit foo; };
in
{
nixosConfigurations.bar = nixpkgs.lib.nixosSystem {
system = "x86_64-linux";
modules = [
({ pkgs /* this pkgs should contain foo */, ... }: {
nixpkgs.pkgs = pkgs';
# This works
# nixpkgs.overlays = [ (self: super: { inherit foo; }) ];
environment.systemPackages = [ pkgs.foo ];
# Satisfy assertions.
boot.loader.systemd-boot.enable = true;
fileSystems."/" = {
device = "/dev/sda1";
fsType = "ext4";
};
}
)
];
};
};
}
Building that gives me error: attribute 'foo' missing
, however nixpkgs.overlays
works as expected.
Any idea how to get this working?