1{
2 lib,
3 nix,
4 runCommand,
5}:
6let
7 nixpkgs =
8 with lib.fileset;
9 toSource {
10 root = ../.;
11 fileset = (fileFilter (file: file.hasExt "nix") ../.);
12 };
13in
14runCommand "nix-parse-${nix.name}"
15 {
16 nativeBuildInputs = [
17 nix
18 ];
19 }
20 ''
21 export NIX_STORE_DIR=$TMPDIR/store
22 export NIX_STATE_DIR=$TMPDIR/state
23
24 cd "${nixpkgs}"
25
26 # Passes all files to nix-instantiate at once.
27 # Much faster, but will only show first error.
28 parse-all() {
29 find . -type f -iname '*.nix' | xargs -P $(nproc) nix-instantiate --parse >/dev/null 2>/dev/null
30 }
31
32 # Passes each file separately to nix-instantiate with -n1.
33 # Much slower, but will show all errors.
34 parse-each() {
35 find . -type f -iname '*.nix' | xargs -n1 -P $(nproc) nix-instantiate --parse >/dev/null
36 }
37
38 if ! parse-all; then
39 parse-each
40 fi
41
42 touch $out
43 ''