Open ony opened 2 years ago
It is not possible to override lib
from within a module, as this would create an infinite recursion:
To evaluate config.system.build.toplevel
(ie the "whole" config), we must evaluate all module config
s, many of which are defined through lib.mkIf
and therefore lib
, which would have to come from, again, the config
s.
To override the lib
module argument, you'll have to pass the modified lib
to the nixosSystem
function.
cc @ncfavier If we do make nixosSystem
use the final lib, we can recommend let lib = nixpkgs.lib.extend foo; in lib.nixosSystem
. Working with only one lib
like that is perhaps easier.
rec {
This is redundant. It's generally a good idea not to use it, especially in places where you can access the same values through a "fixed point" like the flake self
argument or an overlay's final
argument.
cc @ncfavier If we do make
nixosSystem
use the final lib, we can recommendlet lib = nixpkgs.lib.extend foo; in lib.nixosSystem
. Working with only onelib
like that is perhaps easier.
Yes, that's exactly the use case I had in mind (see my config for example)
@ony so in your case, something like this should work:
{
outputs = { nixpkgs, ... }@inputs: with inputs; let
lib = nixpkgs.lib.extend (final: prev: {
licenses = prev.licenses // {
sspl = prev.licenses.sspl // { shortName = "sspl"; };
};
});
in {
nixosConfigurations.ony = lib.nixosSystem {
inherit lib; # might become unnecessary in the future
system = "x86_64-linux";
modules = [ ({ lib, ... }: ... lib.licenses.sspl ...) ];
};
defaultPackage.x86_64-linux = self.nixosConfigurations.ony.config.system.build.toplevel;
};
}
@ncfavier , thank you for lib.extend
that saves some boilerplate.
Though using that modified lib.nixosSystem
and passing into it modified lib
do have effect on module lib
, it do not effect pkgs.lib
(opposite to nixpkgs.overlays
). And it still fails on finding sspl
in lib.licenses
in check-meta.nix
.
Could it be because of this?
https://github.com/NixOS/nixpkgs/blob/c4bb9084aa159f029ae9e35edb580d22f0ed5fdb/pkgs/stdenv/generic/default.nix#L1 https://github.com/NixOS/nixpkgs/blob/c4bb9084aa159f029ae9e35edb580d22f0ed5fdb/pkgs/stdenv/generic/default.nix#L54 https://github.com/NixOS/nixpkgs/blob/c4bb9084aa159f029ae9e35edb580d22f0ed5fdb/pkgs/stdenv/generic/make-derivation.nix#L1-L7
I was thinking about that earlier. It seems like a complete solution would look like introducing a concept of an "ambient" lib
that's passed around the files in pkgs
instead of importing ../lib
. Or maybe just adding a simple { inherit lib; }
overlay in specific places (although this wouldn't solve the checkMeta
situation).
I wonder if simple solution would be to not depend on lib.licenses
and lib.platforms
in check-meta.nix
:slightly_smiling_face: .
@roberth , I would expect recursion only in case if overlay overrides something used to lookup and combine overlays. Otherwise it should be able to traverse to original "bootstrap" attrset through all //
.
Describe the bug
Attempt to add overlay
lib
have effect only onpkgs
module argument attrset and not onlib
.Steps To Reproduce
Steps to reproduce the behavior:
nix flake check
Expected behavior
lib
orpkgs
(viapkgs.lib
) arguments of module.lib
in overlay should have effect oncheck-meta.nix
evaluations too. That message indicates that licenses referenced inblocklistedLicenses
and in attrsetlib.licenses
were different even ifsspl
attribute was found. See comment for issue with SSPL.Screenshots
When using
lib.licenses
(no effect from overlay)When using
pkgs.lib.licenses
(license do not match one referenced incheck-meta.nix
)(notice lower case version of
shortName
)Additional context
When there is requirement for
blocklistedLicenses
to reference only licenses fromlib.licenses
, we need a way extend that attrset to allow having packages and licenses outside of mainnixpkgs
repo.Notify maintainers
Metadata
"x86_64-linux"
Linux 5.10.81, NixOS, 21.11 (Porcupine)
yes
yes
nix-env (Nix) 2.4
"nixos-21.11.334684.1158f346391"
"nixpkgs-unstable-21.11pre310022.14b0f20fa1f"
/nix/var/nix/profiles/per-user/root/channels/nixos