Skip to content

Multiple allowUnfreePredicates should compose with or #197325

@l0b0

Description

@l0b0

Describe the bug

Specifying nixpkgs.config.allowUnfreePredicate in two files, and then importing one from the other, results in only one of the allowUnfreePredicates taking effect. Instead, any package matching any allowUnfreePredicate should be allowed.

Steps To Reproduce

Steps to reproduce the behavior:

  1. Specify imports = [./host.nix];, fonts.fonts = [pkgs.corefonts];, and
    nixpkgs.config.allowUnfreePredicate = pkg:
      builtins.elem (
        lib.getName pkg
      ) (
        map lib.getName [
          pkgs.corefonts
        ]
      );
    in /etc/nixos/configuration.nix
  2. Specify
    nixpkgs.config.allowUnfreePredicate = pkg:
      (
        builtins.elem (
          lib.getName pkg
        ) (
          map lib.getName [
            pkgs.steam
            pkgs.steamPackages.steam
          ]
        )
      );
    and programs.steam.enable = true; in /etc/nixos/host.nix.
  3. Run nixos-rebuild

This command will fail because only the /etc/nixos/configuration.nix allowUnfreePredicate is taken into account, so Steam can't be installed.

Expected behavior

Both pkgs.corefonts and pkgs.steam should be installed, analogous to how environment.systemPackages from imported packages are joined with local environment.systemPackages to install all of them.

Additional context

Workaround:

{
  config,
  lib,
  modulesPath,
  pkgs,
  specialArgs,
  options,
}: let
  imports = [
    /etc/nixos/cachix.nix
    /etc/nixos/root.nix
  ];
in {
  inherit imports;

  nixpkgs.config.allowUnfreePredicate = pkg:
    (builtins.elem (lib.getName pkg) [
      "bar"
    ])
    || builtins.any (
      path: let
        package = import path {
          inherit config lib modulesPath pkgs specialArgs options;
        };
      in
        if builtins.hasAttr "nixpkgs" package
        then package.nixpkgs.config.allowUnfreePredicate pkg
        else false
    )
    imports;
}

Notify maintainers

Metadata

  • system: "x86_64-linux"
  • host os: Linux 5.15.74, NixOS, 22.05 (Quokka), 22.05.3737.3933d8bb912
  • multi-user?: yes
  • sandbox: yes
  • version: nix-env (Nix) 2.11.0
  • channels(root): "home-manager-22.05.tar.gz, nixos-22.05"
  • channels(victor): ""
  • nixpkgs: /nix/var/nix/profiles/per-user/root/channels/nixos

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions