You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[package outputs] generate buildInputs for package-outputs in flake (#1721)
## Summary
This PR reads the `outputs` field from the Config for a package.
For packages with non-default outputs in the config, we specify:
1. They are not to be taken from the binary cache
2. They are exempt from the `flakeInput.buildInputs()` that are
specified in the generated flake's devshell.buildInputs
Instead, we generate a [`symlinkJoin`
derivation](https://nixos.org/manual/nixpkgs/stable/#trivial-builder-symlinkJoin)
of the form:
```
(pkgs.symlinkJoin {
name = "prometheus-combined";
paths = [
# each output is printed here
nixpkgs-fd04be-pkgs.prometheus.cli
nixpkgs-fd04be-pkgs.prometheus.out
];
})
```
This `prometheus-combined` derivation is useful so that when we derive
the nix-profile from the flake's buildInputs as in #1692, it is treated
as a single package. Without this, we could inline each output as a
distinct buildInput in the flake's devshell, but then the nix profile
would treat each output as its own package.
## How was it tested?
Added testscript unit-test. Also, ran the same steps inside the
testscript manually.
setup:
```
# add package with multiple outputs
devbox add prometheus --outputs cli,out
# add package for a specific nixpkgs commit hash (as a control)
devbox add github:nixos/nixpkgs/fd04bea4cbf76f86f244b9e2549fca066db8ddff#hello
```
then the generated flake is:
```
❯ cat .devbox/gen/flake/flake.nix
{
description = "A devbox shell";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/fd04bea4cbf76f86f244b9e2549fca066db8ddff";
nixpkgs-fd04be.url = "github:NixOS/nixpkgs/fd04bea4cbf76f86f244b9e2549fca066db8ddff";
gh-nixos-nixpkgs-fd04bea4cbf76f86f244b9e2549fca066db8ddff.url = "github:NixOS/nixpkgs/fd04bea4cbf76f86f244b9e2549fca066db8ddff";
};
outputs = {
self,
nixpkgs,
nixpkgs-fd04be,
gh-nixos-nixpkgs-fd04bea4cbf76f86f244b9e2549fca066db8ddff,
}:
let
pkgs = nixpkgs.legacyPackages.x86_64-darwin;
nixpkgs-fd04be-pkgs = (import nixpkgs-fd04be {
system = "x86_64-darwin";
config.allowUnfree = true;
config.permittedInsecurePackages = [
];
});
gh-nixos-nixpkgs-fd04bea4cbf76f86f244b9e2549fca066db8ddff-pkgs = (import gh-nixos-nixpkgs-fd04bea4cbf76f86f244b9e2549fca066db8ddff {
system = "x86_64-darwin";
config.allowUnfree = true;
config.permittedInsecurePackages = [
];
});
in
{
devShells.x86_64-darwin.default = pkgs.mkShell {
buildInputs = [
(builtins.fetchClosure {
fromStore = "https://cache.nixos.org";
fromPath = "/nix/store/0djljz0g4s6f55xcnw7fpzcy7af7rxid-go-1.21.4";
inputAddressed = true;
})
(pkgs.symlinkJoin {
name = "prometheus-combined";
paths = [
nixpkgs-fd04be-pkgs.prometheus.cli
nixpkgs-fd04be-pkgs.prometheus.out
];
})
gh-nixos-nixpkgs-fd04bea4cbf76f86f244b9e2549fca066db8ddff-pkgs.hello
];
};
};
}
```
this leads to `$buildInputs` in a `devbox shell` to be:
```
❯ echo $buildInputs
/nix/store/0djljz0g4s6f55xcnw7fpzcy7af7rxid-go-1.21.4 /nix/store/9dn3rzv04x63n0kz2jwpgz82rdlsa56h-prometheus-combined /nix/store/4xy6iv0ph2v6w7n06cw5ra7cmyvignkm-hello-2.12.1
```
where the `prometheus-combined` derivation has the `cli` and `out`
outputs combined:
```
❯ ls -al /nix/store/9dn3rzv04x63n0kz2jwpgz82rdlsa56h-prometheus-combined/bin/
total 0
dr-xr-xr-x 4 root wheel 128 Dec 31 1969 .
dr-xr-xr-x 4 root wheel 128 Dec 31 1969 ..
lrwxr-xr-x 1 root wheel 76 Dec 31 1969 prometheus -> /nix/store/hizpsf2f5gc7l810328382xicjb9gc73-prometheus-2.48.1/bin/prometheus
lrwxr-xr-x 1 root wheel 78 Dec 31 1969 promtool -> /nix/store/8x6psdqn3945pbs0ww5wanmfhvvz2iyl-prometheus-2.48.1-cli/bin/promtool
```
0 commit comments