# Why does one validity check pass, and the other fail?

# nix-instantiate --eval --strict weird-meta.nix -A isValid
# { handled = true; valid = true; }

# nix-instantiate --eval --strict weird-meta.nix -A out
# error: Package ‘nvidia-settings-440.59’ in /nix/store/lcr3p8f33ksljpzmdk2x06m0ak95bah4-source/pkgs/os-specific/linux/nvidia-x11/settings.nix:102 has an unfree license (‘unfreeRedistributable’), refusing to evaluate.
#
# a) For `nixos-rebuild` you can set
#   { nixpkgs.config.allowUnfree = true; }
# in configuration.nix to override this.
# 
# b) For `nix-env`, `nix-build`, `nix-shell` or any other Nix command you can add
#   { allowUnfree = true; }
# to ~/.config/nixpkgs/config.nix.
# 
# (use '--show-trace' to show detailed location information)


let
  nixpkgs = builtins.fetchTarball "channel:nixos-unstable";
  pkgs = import nixpkgs {
    overlays = [];
    config.allowUnfreePredicate = p:
      let hasName = builtins.hasAttr "name" p;
          inherit (builtins.parseDrvName p.name) name;
          allowed = builtins.elem name [
            "nvidia-settings"
          ];
      in  hasName && allowed;
  };

  checkMeta = import (pkgs.path + /pkgs/stdenv/generic/check-meta.nix) {
    inherit (pkgs) lib config;
    inherit (pkgs.stdenv) hostPlatform;
  };

  p = pkgs.linuxPackages.nvidia_x11.settings;
in {
  passesPredicate = pkgs.config.allowUnfreePredicate p;
  isValid = checkMeta {
    attrs = p;
    meta = p.meta;
  };
  out = p.outPath;
}