Skip to content

lib and pkgs.lib loose sync when trying to overlay lib #156312

@ony

Description

@ony

Describe the bug

Attempt to add overlay lib have effect only on pkgs module argument attrset and not on lib.

Steps To Reproduce

Steps to reproduce the behavior:

  1. Prepare dummy NixOS configuration
# flake.nix
{
  outputs = { nixpkgs, ... }@inputs: with inputs; {
    nixosConfigurations.ony = nixpkgs.lib.nixosSystem rec {
      system = "x86_64-linux";
      modules = [ ./configuration.nix ];
    };
    defaultPackage.x86_64-linux = self.nixosConfigurations.ony.config.system.build.toplevel;
  };
}
{ lib, pkgs, ... }:
{
  nixpkgs.overlays = [
    (final: prev: {
      lib = prev.lib // {
        licenses = prev.lib.licenses // {
          sspl = prev.lib.licenses.sspl // {
            shortName = "sspl";  # try to fix upper case SSPL not matching attribute
          };
        };
      };
    })
  ];
  nixpkgs.config = {
    # blocklistedLicenses = with lib.licenses; [ sspl ]; # => ‘SSPL’ is not an attribute of lib.licenses
    blocklistedLicenses = with pkgs.lib.licenses; [ sspl ]; # => ‘sspl’ is not an attribute of lib.licenses
  };
}
  1. Run nix flake check

Expected behavior

  • There should be no difference between using lib or pkgs (via pkgs.lib) arguments of module.
  • Overriding lib in overlay should have effect on check-meta.nix evaluations too. That message indicates that licenses referenced in blocklistedLicenses and in attrset lib.licenses were different even if sspl attribute was found. See comment for issue with SSPL.

Screenshots

When using lib.licenses (no effect from overlay)

zsh%  nix flake check
error: ‘SSPL’ is not an attribute of lib.licenses
(use '--show-trace' to show detailed location information)

When using pkgs.lib.licenses (license do not match one referenced in check-meta.nix)

zsh%  nix flake check
error: ‘sspl’ is not an attribute of lib.licenses
(use '--show-trace' to show detailed location information)

(notice lower case version of shortName)

Additional context

When there is requirement for blocklistedLicenses to reference only licenses from lib.licenses, we need a way extend that attrset to allow having packages and licenses outside of main nixpkgs repo.

Notify maintainers

Metadata

nix run nixpkgs\#nix-info -- -m
  • system: "x86_64-linux"
  • host os: Linux 5.10.81, NixOS, 21.11 (Porcupine)
  • multi-user?: yes
  • sandbox: yes
  • version: nix-env (Nix) 2.4
  • channels(root): "nixos-21.11.334684.1158f346391"
  • channels(nikolay): "nixpkgs-unstable-21.11pre310022.14b0f20fa1f"
  • nixpkgs: /nix/var/nix/profiles/per-user/root/channels/nixos

Metadata

Metadata

Assignees

No one assigned

    Labels

    0.kind: bugSomething is broken2.status: stalehttps://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions