Skip to content

Commit 43833fc

Browse files
committed
Add descriptive error in case of pkgs error
1 parent 0d3917b commit 43833fc

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

default.nix

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
{ nurpkgs ? import <nixpkgs> {} # For nixpkgs dependencies used by NUR itself
22
# Dependencies to call NUR repos with
3-
, pkgs ? throw "NUR call didn't receive a pkgs argument, but the evaluation requires it."
4-
}:
3+
, pkgs ? null }:
54

65
let
76
inherit (nurpkgs) fetchgit fetchzip lib;
@@ -44,7 +43,7 @@ let
4443
};
4544

4645
createRepo = name: attr: import ./lib/evalRepo.nix {
47-
inherit name pkgs lib;
46+
inherit name pkgs lib attr;
4847
src = repoSource name attr + "/" + (attr.file or "");
4948
};
5049

lib/evalRepo.nix

+17-2
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,35 @@
11
{ name
2+
, attr
23
, src
34
, pkgs # Do not use this for anything other than passing it along as an argument to the repository
45
, lib
56
}:
67
let
78

9+
prettyName = "${name}";
10+
811
# Arguments passed to each repositories default.nix
9-
passedArgs = { inherit pkgs lib; };
12+
passedArgs = {
13+
inherit lib;
14+
pkgs = if pkgs != null then pkgs else throw ''
15+
NUR import call didn't receive a pkgs argument, but the evaluation of NUR's ${prettyName} repository requires it.
16+
17+
This is either because
18+
- You're trying to use a package from that repository, but didn't pass a `pkgs` argument to the NUR import.
19+
In that case, refer to the installation instructions at https://github.com/nix-community/nur#installation on how to properly import NUR
20+
21+
- You're trying to use a module/overlay from that repository, but it didn't properly declare their module.
22+
In that case, inform the maintainer of the repository: ${attr.url}
23+
'';
24+
};
1025

1126
expr = import src;
1227
args = builtins.functionArgs expr;
1328
# True if not all arguments are either passed by default (e.g. pkgs) or defaulted (e.g. foo ? 10)
1429
usesCallPackage = ! lib.all (arg: lib.elem arg (lib.attrNames passedArgs) || args.${arg}) (lib.attrNames args);
1530

1631
in if usesCallPackage then lib.warn ''
17-
NUR repository ${name} is using the deprecated callPackage syntax which
32+
NUR repository ${prettyName} is using the deprecated callPackage syntax which
1833
might result in infinite recursion when used with NixOS modules.
1934
'' (pkgs.callPackages src {})
2035
else expr (builtins.intersectAttrs args passedArgs)

0 commit comments

Comments
 (0)