Separate NUR nixpkgs from repos nixpkgs, avoid callPackages
This is essential to get modules in NUR to work. By taking a separate
argument for NUR's nixpkgs (for fetchgit, fetchzip and lib), we don't
need to evaluate the nixpkgs used for repos.
This also implies that you won't be able to `callPackage` NUR anymore,
and instead you'll have to use `import (builtins.fetchGit ".../NUR") {
inherit pkgs; }` instead. Doing this also prevents the evaluation of
pkgs. In case of NixOS, this pkgs depends on your whole config, which is
the source of the recursion. Evaluating this at the last possible moment
is key.
This also means that you won't be able to take package arguments in a
repo definition, you instead get just `pkgs`, also to avoid evaluation
of it.
An error will be thrown when pkgs was required for evaluation but wasn't
passed to the NUR import
The old callPackage syntax will still be supported albeit with a warning
Also repos receive a lib argument,
Using this lib instead of pkgs.lib makes it possible to define library
functions that use other library functions without depending on pkgs ->
should prevent some infinite recursion cases for NixOS module usage.
This commit is contained in:
parent
3a6a6f4da7
commit
ee65c7afd6
2 changed files with 43 additions and 4 deletions
13
default.nix
13
default.nix
|
|
@ -1,7 +1,9 @@
|
|||
{ nurpkgs ? import <nixpkgs> {} # For nixpkgs dependencies used by NUR itself
|
||||
# Dependencies to call NUR repos with
|
||||
, pkgs ? null }:
|
||||
|
||||
{ pkgs ? import <nixpkgs> {} }:
|
||||
let
|
||||
inherit (pkgs) fetchgit fetchzip callPackages lib;
|
||||
inherit (nurpkgs) fetchgit fetchzip lib;
|
||||
|
||||
manifest = (builtins.fromJSON (builtins.readFile ./repos.json)).repos;
|
||||
lockedRevisions = (builtins.fromJSON (builtins.readFile ./repos.json.lock)).repos;
|
||||
|
|
@ -40,9 +42,12 @@ let
|
|||
fetchSubmodules = submodules;
|
||||
};
|
||||
|
||||
expressionPath = name: attr: (repoSource name attr) + "/" + (attr.file or "");
|
||||
createRepo = name: attr: import ./lib/evalRepo.nix {
|
||||
inherit name pkgs lib;
|
||||
inherit (attr) url;
|
||||
src = repoSource name attr + "/" + (attr.file or "");
|
||||
};
|
||||
|
||||
createRepo = (name: attr: callPackages (expressionPath name attr) {});
|
||||
in {
|
||||
repos = lib.mapAttrs createRepo manifest;
|
||||
repo-sources = lib.mapAttrs repoSource manifest;
|
||||
|
|
|
|||
34
lib/evalRepo.nix
Normal file
34
lib/evalRepo.nix
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
{ name
|
||||
, url
|
||||
, src
|
||||
, pkgs # Do not use this for anything other than passing it along as an argument to the repository
|
||||
, lib
|
||||
}:
|
||||
let
|
||||
|
||||
prettyName = "[32;1m${name}[0m";
|
||||
|
||||
# Arguments passed to each repositories default.nix
|
||||
passedArgs = {
|
||||
pkgs = if pkgs != null then pkgs else throw ''
|
||||
NUR import call didn't receive a pkgs argument, but the evaluation of NUR's ${prettyName} repository requires it.
|
||||
|
||||
This is either because
|
||||
- You're trying to use a [1mpackage[0m from that repository, but didn't pass a `pkgs` argument to the NUR import.
|
||||
In that case, refer to the installation instructions at https://github.com/nix-community/nur#installation on how to properly import NUR
|
||||
|
||||
- You're trying to use a [1mmodule[0m/[1moverlay[0m from that repository, but it didn't properly declare their module.
|
||||
In that case, inform the maintainer of the repository: ${url}
|
||||
'';
|
||||
};
|
||||
|
||||
expr = import src;
|
||||
args = builtins.functionArgs expr;
|
||||
# True if not all arguments are either passed by default (e.g. pkgs) or defaulted (e.g. foo ? 10)
|
||||
usesCallPackage = ! lib.all (arg: lib.elem arg (lib.attrNames passedArgs) || args.${arg}) (lib.attrNames args);
|
||||
|
||||
in if usesCallPackage then lib.warn ''
|
||||
NUR repository ${prettyName} is using the deprecated callPackage syntax which
|
||||
might result in infinite recursion when used with NixOS modules.
|
||||
'' (passedArgs.pkgs.callPackages src {})
|
||||
else expr (builtins.intersectAttrs args passedArgs)
|
||||
Loading…
Add table
Add a link
Reference in a new issue