1{
2 lib,
3 stdenv,
4 lndir,
5 buildEnv,
6
7 maintainers,
8 teams,
9
10 version,
11
12 nix-util,
13 nix-util-c,
14 nix-util-tests,
15
16 nix-store,
17 nix-store-c,
18 nix-store-tests,
19
20 nix-fetchers,
21 nix-fetchers-c,
22 nix-fetchers-tests,
23
24 nix-expr,
25 nix-expr-c,
26 nix-expr-tests,
27
28 nix-flake,
29 nix-flake-c,
30 nix-flake-tests,
31
32 nix-main,
33 nix-main-c,
34
35 nix-cmd,
36
37 nix-cli,
38
39 nix-functional-tests,
40
41 nix-manual,
42 nix-internal-api-docs,
43 nix-external-api-docs,
44
45 nix-perl-bindings,
46
47 testers,
48
49 patchedSrc ? null,
50}:
51
52let
53 libs = {
54 inherit
55 nix-util
56 nix-util-c
57 nix-store
58 nix-store-c
59 nix-fetchers
60 nix-expr
61 nix-expr-c
62 nix-flake
63 nix-flake-c
64 nix-main
65 nix-main-c
66 nix-cmd
67 ;
68 }
69 // lib.optionalAttrs (lib.versionAtLeast version "2.29pre") {
70 inherit
71 nix-fetchers-c
72 ;
73 }
74 //
75 lib.optionalAttrs
76 (!stdenv.hostPlatform.isStatic && stdenv.buildPlatform.canExecute stdenv.hostPlatform)
77 {
78 # Currently fails in static build
79 inherit
80 nix-perl-bindings
81 ;
82 };
83
84 devdoc = buildEnv {
85 name = "nix-${nix-cli.version}-devdoc";
86 paths = [
87 nix-internal-api-docs
88 nix-external-api-docs
89 ];
90 };
91
92in
93stdenv.mkDerivation (finalAttrs: {
94 pname = "nix";
95 version = nix-cli.version;
96
97 /**
98 This package uses a multi-output derivation, even though some outputs could
99 have been provided directly by the constituent component that provides it.
100
101 This is because not all tooling handles packages composed of arbitrary
102 outputs yet. This includes nix itself, https://github.com/NixOS/nix/issues/6507.
103
104 `devdoc` is also available, but not listed here, because this attribute is
105 not an output of the same derivation that provides `out`, `dev`, etc.
106 */
107 outputs = [
108 "out"
109 "dev"
110 "doc"
111 "man"
112 ];
113
114 /**
115 Unpacking is handled in this package's constituent components
116 */
117 dontUnpack = true;
118 /**
119 Building is handled in this package's constituent components
120 */
121 dontBuild = true;
122
123 /**
124 `doCheck` controles whether tests are added as build gate for the combined package.
125 This includes both the unit tests and the functional tests, but not the
126 integration tests that run in CI (the flake's `hydraJobs` and some of the `checks`).
127 */
128 doCheck = true;
129
130 /**
131 `fixupPhase` currently doesn't understand that a symlink output isn't writable.
132
133 We don't compile or link anything in this derivation, so fixups aren't needed.
134 */
135 dontFixup = true;
136
137 checkInputs = [
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 ++
149 lib.optionals (!stdenv.hostPlatform.isStatic && stdenv.buildPlatform.canExecute stdenv.hostPlatform)
150 [
151 # Perl currently fails in static build
152 # TODO: Split out tests into a separate derivation?
153 nix-perl-bindings
154 ];
155
156 nativeBuildInputs = [
157 lndir
158 ];
159
160 installPhase =
161 let
162 devPaths = lib.mapAttrsToList (_k: lib.getDev) finalAttrs.finalPackage.libs;
163 in
164 ''
165 mkdir -p $out $dev/nix-support
166
167 # Custom files
168 echo $libs >> $dev/nix-support/propagated-build-inputs
169 echo ${nix-cli} ${lib.escapeShellArgs devPaths} >> $dev/nix-support/propagated-build-inputs
170
171 # Merged outputs
172 lndir ${nix-cli} $out
173
174 for lib in ${lib.escapeShellArgs devPaths}; do
175 lndir $lib $dev
176 done
177
178 # Forwarded outputs
179 ln -sT ${nix-manual} $doc
180 ln -sT ${nix-manual.man} $man
181 '';
182
183 passthru = {
184 inherit (nix-cli) version;
185 src = patchedSrc;
186
187 /**
188 These are the libraries that are part of the Nix project. They are used
189 by the Nix CLI and other tools.
190
191 If you need to use these libraries in your project, we recommend to use
192 the `-c` C API libraries exclusively, if possible.
193
194 We also recommend that you build the complete package to ensure that the unit tests pass.
195 You could do this in CI, or by passing it in an unused environment variable. e.g in a `mkDerivation` call:
196
197 ```nix
198 buildInputs = [ nix.libs.nix-util-c nix.libs.nix-store-c ];
199 # Make sure the nix libs we use are ok
200 unusedInputsForTests = [ nix ];
201 disallowedReferences = nix.all;
202 ```
203 */
204 inherit libs;
205
206 /**
207 Developer documentation for `nix`, in `share/doc/nix/{internal,external}-api/`.
208
209 This is not a proper output; see `outputs` for context.
210 */
211 inherit devdoc;
212
213 /**
214 Extra tests that test this package, but do not run as part of the build.
215 See <https://nixos.org/manual/nixpkgs/stable/index.html#var-passthru-tests>
216 */
217 tests = {
218 pkg-config = testers.hasPkgConfigModules {
219 package = finalAttrs.finalPackage;
220 };
221 };
222 };
223
224 meta = {
225 mainProgram = "nix";
226 description = "Nix package manager";
227 longDescription = nix-cli.meta.longDescription;
228 homepage = nix-cli.meta.homepage;
229 license = nix-cli.meta.license;
230 maintainers = maintainers;
231 teams = teams;
232 platforms = nix-cli.meta.platforms;
233 outputsToInstall = [
234 "out"
235 "man"
236 ];
237 pkgConfigModules = [
238 "nix-cmd"
239 "nix-expr"
240 "nix-expr-c"
241 "nix-fetchers"
242 ]
243 ++ lib.optionals (lib.versionAtLeast version "2.29pre") [
244 "nix-fetchers-c"
245 ]
246 ++ [
247 "nix-flake"
248 "nix-flake-c"
249 "nix-main"
250 "nix-main-c"
251 "nix-store"
252 "nix-store-c"
253 "nix-util"
254 "nix-util-c"
255 ];
256 };
257
258})