nix-pkgset is a lightweight library that helps package nix derivations into cross-compilation aware package sets by splicing packages in the same fashion as nixpkgs.
<pkgset-name><host><target> (e.g. pkgset.myPkgsBuildHost).callPackage through <pkgset-name> (e.g. pkgset.myPkgs).nix-pkgset.lib.makePackageSet <name> <newScope> <scopeFn>
<name>BuildHost, <name>BuildTarget.pkgs.newScope). These packages will be available in pkgset.callPackage scope alongside your custom packages defined in scopeFn.pkgset.foo). See nixpkgs makeScope for more details.let
# Create a new package set that inherits the scope from `pkgs`.
myPkgs = nix-pkgset.lib.makePackageSet "myPkgs" pkgs.newScope (self: {
foo = self.callPackage ./foo.nix { };
bar = self.callPackage ./bar.nix { };
});
in
{
# We can reference packages from the package set.
foo = myPkgs.foo;
bar = myPkgs.bar;
# We can't reference packages that are not in the package set.
# Package `hello` is only available in `callPackage` scope.
hello = myPkgs.hello; # Error
# We can reference package splices from `<pkgset><host><target>`.
buildbuild-foo = myPkgs.myPkgsBuildBuild.foo;
buildbuild-bar = myPkgs.myPkgsBuildBuild.bar;
# We can't reference packages that are not in the package set.
# Package `hello` is only available in `callPackage` scope.
buildbuild-hello = myPkgs.myPkgsBuildBuild.hello; # Error
# We can access pre-spliced packages.
foo-spliced = myPkgs.myPkgs.foo; # `foo-spliced.__spliced` is set
bar-spliced = myPkgs.myPkgs.bar;
# We can create a derivation based on the package set's scope.
baz = myPkgs.callPackage ({ stdenv, hello, bar, foo }:
stdenv.mkDerivation {
name = "baz";
# `nativeBuildInputs` are spliced to run on the build platform.
nativeBuildInputs = [ hello bar ];
# `buildInputs` are spliced to run on the host platform.
buildInputs = [ foo ];
# ...
}
) { };
}
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
nix-pkgset.url = "github:github.com/szlend/nix-pkgset";
nix-pkgset.inputs.nixpkgs.follows = "nixpkgs";
};
outputs =
{
self,
nixpkgs,
nix-pkgset,
...
}:
let
lib = nixpkgs.lib;
forAllSystems = lib.genAttrs lib.systems.flakeExposed;
in
{
legacyPackages = forAllSystems (
system:
nix-pkgset.lib.makePackageSet "foo" nixpkgs.legacyPackages.${system}.newScope (self: {
# ...
})
);
packages = forAllSystems (
system:
lib.filterAttrs (_: lib.isDerivation) self.legacyPackages.${system}
);
};
}
16 commits
Nix
100.0%
nix-pkgset is a lightweight library that helps package nix derivations into cross-compilation aware package sets by splicing packages in the same fashion as nixpkgs.
<pkgset-name><host><target> (e.g. pkgset.myPkgsBuildHost).callPackage through <pkgset-name> (e.g. pkgset.myPkgs).nix-pkgset.lib.makePackageSet <name> <newScope> <scopeFn>
<name>BuildHost, <name>BuildTarget.pkgs.newScope). These packages will be available in pkgset.callPackage scope alongside your custom packages defined in scopeFn.pkgset.foo). See nixpkgs makeScope for more details.let
# Create a new package set that inherits the scope from `pkgs`.
myPkgs = nix-pkgset.lib.makePackageSet "myPkgs" pkgs.newScope (self: {
foo = self.callPackage ./foo.nix { };
bar = self.callPackage ./bar.nix { };
});
in
{
# We can reference packages from the package set.
foo = myPkgs.foo;
bar = myPkgs.bar;
# We can't reference packages that are not in the package set.
# Package `hello` is only available in `callPackage` scope.
hello = myPkgs.hello; # Error
# We can reference package splices from `<pkgset><host><target>`.
buildbuild-foo = myPkgs.myPkgsBuildBuild.foo;
buildbuild-bar = myPkgs.myPkgsBuildBuild.bar;
# We can't reference packages that are not in the package set.
# Package `hello` is only available in `callPackage` scope.
buildbuild-hello = myPkgs.myPkgsBuildBuild.hello; # Error
# We can access pre-spliced packages.
foo-spliced = myPkgs.myPkgs.foo; # `foo-spliced.__spliced` is set
bar-spliced = myPkgs.myPkgs.bar;
# We can create a derivation based on the package set's scope.
baz = myPkgs.callPackage ({ stdenv, hello, bar, foo }:
stdenv.mkDerivation {
name = "baz";
# `nativeBuildInputs` are spliced to run on the build platform.
nativeBuildInputs = [ hello bar ];
# `buildInputs` are spliced to run on the host platform.
buildInputs = [ foo ];
# ...
}
) { };
}
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
nix-pkgset.url = "github:github.com/szlend/nix-pkgset";
nix-pkgset.inputs.nixpkgs.follows = "nixpkgs";
};
outputs =
{
self,
nixpkgs,
nix-pkgset,
...
}:
let
lib = nixpkgs.lib;
forAllSystems = lib.genAttrs lib.systems.flakeExposed;
in
{
legacyPackages = forAllSystems (
system:
nix-pkgset.lib.makePackageSet "foo" nixpkgs.legacyPackages.${system}.newScope (self: {
# ...
})
);
packages = forAllSystems (
system:
lib.filterAttrs (_: lib.isDerivation) self.legacyPackages.${system}
);
};
}
16 commits
Nix
100.0%