Skip to content

Commit cd36881

Browse files
authored
Merge pull request #12585 from NixOS/mergify/bp/2.26-maintenance/pr-12582
packaging/everything.nix: Use a multi-output derivation (backport #12582)
2 parents 1dda07e + d8606f9 commit cd36881

File tree

1 file changed

+130
-86
lines changed

1 file changed

+130
-86
lines changed

packaging/everything.nix

Lines changed: 130 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
lib,
33
stdenv,
4+
lndir,
45
buildEnv,
56

67
nix-util,
@@ -38,7 +39,6 @@
3839
nix-perl-bindings,
3940

4041
testers,
41-
runCommand,
4242
}:
4343

4444
let
@@ -119,92 +119,136 @@ let
119119
};
120120

121121
in
122-
(buildEnv {
123-
name = "nix-${nix-cli.version}";
124-
paths = [
125-
nix-cli
126-
nix-manual.man
122+
stdenv.mkDerivation (finalAttrs: {
123+
pname = "nix";
124+
version = nix-cli.version;
125+
126+
/**
127+
This package uses a multi-output derivation, even though some outputs could
128+
have been provided directly by the constituent component that provides it.
129+
130+
This is because not all tooling handles packages composed of arbitrary
131+
outputs yet. This includes nix itself, https://github.com/NixOS/nix/issues/6507.
132+
133+
`devdoc` is also available, but not listed here, because this attribute is
134+
not an output of the same derivation that provides `out`, `dev`, etc.
135+
*/
136+
outputs = [
137+
"out"
138+
"dev"
139+
"doc"
140+
"man"
127141
];
128142

129-
meta.mainProgram = "nix";
130-
}).overrideAttrs
131-
(
132-
finalAttrs: prevAttrs: {
133-
doCheck = true;
134-
doInstallCheck = true;
135-
136-
checkInputs =
137-
[
138-
# Make sure the unit tests have passed
139-
nix-util-tests.tests.run
140-
nix-store-tests.tests.run
141-
nix-expr-tests.tests.run
142-
nix-fetchers-tests.tests.run
143-
nix-flake-tests.tests.run
144-
145-
# Make sure the functional tests have passed
146-
nix-functional-tests
147-
148-
# dev bundle is ok
149-
# (checkInputs must be empty paths??)
150-
(runCommand "check-pkg-config" { checked = dev.tests.pkg-config; } "mkdir $out")
151-
]
152-
++ lib.optionals
153-
(!stdenv.hostPlatform.isStatic && stdenv.buildPlatform.canExecute stdenv.hostPlatform)
154-
[
155-
# Perl currently fails in static build
156-
# TODO: Split out tests into a separate derivation?
157-
nix-perl-bindings
158-
];
159-
passthru = prevAttrs.passthru // {
160-
inherit (nix-cli) version;
161-
162-
/**
163-
These are the libraries that are part of the Nix project. They are used
164-
by the Nix CLI and other tools.
165-
166-
If you need to use these libraries in your project, we recommend to use
167-
the `-c` C API libraries exclusively, if possible.
168-
169-
We also recommend that you build the complete package to ensure that the unit tests pass.
170-
You could do this in CI, or by passing it in an unused environment variable. e.g in a `mkDerivation` call:
171-
172-
```nix
173-
buildInputs = [ nix.libs.nix-util-c nix.libs.nix-store-c ];
174-
# Make sure the nix libs we use are ok
175-
unusedInputsForTests = [ nix ];
176-
disallowedReferences = nix.all;
177-
```
178-
*/
179-
inherit libs;
180-
181-
tests = prevAttrs.passthru.tests or { } // {
182-
# TODO: create a proper fixpoint and:
183-
# pkg-config =
184-
# testers.hasPkgConfigModules {
185-
# package = finalPackage;
186-
# };
187-
};
143+
/**
144+
Unpacking is handled in this package's constituent components
145+
*/
146+
dontUnpack = true;
147+
/**
148+
Building is handled in this package's constituent components
149+
*/
150+
dontBuild = true;
151+
152+
/**
153+
`doCheck` controles whether tests are added as build gate for the combined package.
154+
This includes both the unit tests and the functional tests, but not the
155+
integration tests that run in CI (the flake's `hydraJobs` and some of the `checks`).
156+
*/
157+
doCheck = true;
158+
159+
/**
160+
`fixupPhase` currently doesn't understand that a symlink output isn't writable.
161+
162+
We don't compile or link anything in this derivation, so fixups aren't needed.
163+
*/
164+
dontFixup = true;
165+
166+
checkInputs =
167+
[
168+
# Make sure the unit tests have passed
169+
nix-util-tests.tests.run
170+
nix-store-tests.tests.run
171+
nix-expr-tests.tests.run
172+
nix-fetchers-tests.tests.run
173+
nix-flake-tests.tests.run
174+
175+
# Make sure the functional tests have passed
176+
nix-functional-tests
177+
]
178+
++ lib.optionals
179+
(!stdenv.hostPlatform.isStatic && stdenv.buildPlatform.canExecute stdenv.hostPlatform)
180+
[
181+
# Perl currently fails in static build
182+
# TODO: Split out tests into a separate derivation?
183+
nix-perl-bindings
184+
];
188185

189-
/**
190-
A derivation referencing the `dev` outputs of the Nix libraries.
191-
*/
192-
inherit dev;
193-
inherit devdoc;
194-
doc = nix-manual;
195-
outputs = [
196-
"out"
197-
"dev"
198-
"devdoc"
199-
"doc"
200-
];
201-
all = lib.attrValues (
202-
lib.genAttrs finalAttrs.passthru.outputs (outName: finalAttrs.finalPackage.${outName})
203-
);
204-
};
205-
meta = prevAttrs.meta // {
206-
description = "The Nix package manager";
207-
pkgConfigModules = dev.meta.pkgConfigModules;
186+
nativeBuildInputs = [
187+
lndir
188+
];
189+
190+
installPhase =
191+
let
192+
devPaths = lib.mapAttrsToList (_k: lib.getDev) finalAttrs.finalPackage.libs;
193+
in
194+
''
195+
mkdir -p $out $dev $doc $man
196+
197+
# Merged outputs
198+
lndir ${nix-cli} $out
199+
for lib in ${lib.escapeShellArgs devPaths}; do
200+
lndir $lib $dev
201+
done
202+
203+
# Forwarded outputs
204+
ln -s ${nix-manual} $doc
205+
ln -s ${nix-manual.man} $man
206+
'';
207+
208+
passthru = {
209+
inherit (nix-cli) version;
210+
211+
/**
212+
These are the libraries that are part of the Nix project. They are used
213+
by the Nix CLI and other tools.
214+
215+
If you need to use these libraries in your project, we recommend to use
216+
the `-c` C API libraries exclusively, if possible.
217+
218+
We also recommend that you build the complete package to ensure that the unit tests pass.
219+
You could do this in CI, or by passing it in an unused environment variable. e.g in a `mkDerivation` call:
220+
221+
```nix
222+
buildInputs = [ nix.libs.nix-util-c nix.libs.nix-store-c ];
223+
# Make sure the nix libs we use are ok
224+
unusedInputsForTests = [ nix ];
225+
disallowedReferences = nix.all;
226+
```
227+
*/
228+
inherit libs;
229+
230+
/**
231+
Developer documentation for `nix`, in `share/doc/nix/{internal,external}-api/`.
232+
233+
This is not a proper output; see `outputs` for context.
234+
*/
235+
inherit devdoc;
236+
237+
/**
238+
Extra tests that test this package, but do not run as part of the build.
239+
See <https://nixos.org/manual/nixpkgs/stable/index.html#var-passthru-tests>
240+
*/
241+
tests = {
242+
pkg-config = testers.hasPkgConfigModules {
243+
package = finalAttrs.finalPackage;
208244
};
209-
}
210-
)
245+
};
246+
};
247+
248+
meta = {
249+
mainProgram = "nix";
250+
description = "The Nix package manager";
251+
pkgConfigModules = dev.meta.pkgConfigModules;
252+
};
253+
254+
})

0 commit comments

Comments
 (0)