Nixpkgs: Wrong documentation for non-free packages

Created on 31 Aug 2019  路  11Comments  路  Source: NixOS/nixpkgs

Issue description

The documentation at https://nixos.org/nixpkgs/manual/ states:

{
  allowUnfreePredicate = (pkg: builtins.elem
    (builtins.parseDrvName pkg.name).name [
      "flashplayer"
      "vscode"
    ]);
}

Which will produce

$ nix-env -i vscode
installing 'vscode-1.35.1'
error: attribute 'name' missing, at nixpkgs/config.nix:3:28

Technical details

Is fixed when changing the docs to

{
  allowUnfreePredicate = (pkg: builtins.elem
    (builtins.parseDrvName pkg.pname).name [
      "flashplayer"
      "vscode"
    ]);
}

I am not sure if it is always pname or just for VsCode. In addition to that I am not sure how to find the right place to change this. Is the docs/configuration.xml used for this or somehow autogenerated?

Most helpful comment

I wonder though: Is checking the names the right approach at all for whitelisting a known set of packages? Wouldn't it better refer to them by their attribute path, e.g. pkgs.steam? If so, what is the attribute path of packages that are nested into other packages, such as steam-runtime and steam-original?

All 11 comments

Related to https://github.com/NixOS/nixpkgs/issues/55678. Maybe the docs are fixed in unstable.

I am not sure if it is always pname or just for VsCode.

It's not used always but probably in most packages now.

https://github.com/NixOS/nixpkgs/blob/965cddb7ecad94db2c498ad68bd5a19f32b8e392/pkgs/applications/editors/vscode/vscode.nix#L21

Notice that you shouldn't have to apply builtins.parseDrvName to pkg.pname, as the latter already is the package name without the version suffix.

So, for the example from the documentation, this should suffice:

{
  allowUnfreePredicate = (pkg: builtins.elem
    pkg.pname [
      "flashplayer"
      "vscode"
    ]);
}

When you want to whitelist a mix of unfree packages by name, some of which use pname while the others still use name (e.g. currently steam and its dependencies), the following will work:

{
  # ...

  nixpkgs.config.allowUnfreePredicate = (pkg:
    builtins.elem (pkg.pname or (builtins.parseDrvName pkg.name).name) [
      "steam"
      "steam-original"
      "steam-runtime"
    ]
  );

  # ...
}

Due to operator precedence, the parentheses can be dropped, but I find the resulting code harder to understand:

{
  # ...

  nixpkgs.config.allowUnfreePredicate = (pkg:
    builtins.elem pkg.pname or (builtins.parseDrvName pkg.name).name [
      "steam"
      "steam-original"
      "steam-runtime"
    ]
  );

  # ...
}

I wonder though: Is checking the names the right approach at all for whitelisting a known set of packages? Wouldn't it better refer to them by their attribute path, e.g. pkgs.steam? If so, what is the attribute path of packages that are nested into other packages, such as steam-runtime and steam-original?

This issue has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/question-regarding-configuration-nix/1619/22

This issue has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/question-regarding-configuration-nix/1619/23

I marked this as stale due to inactivity. → More info

...

Is this issue still a problem?

Currently (and probably since 20.03, which included 9b090ccbca3f7dd26d91db06e96e8bf8282c37ca), https://nixos.org/manual/nixpkgs/stable/#sec-allow-unfree states:

  • It is possible to permanently allow individual unfree packages, while still blocking unfree packages by default using the allowUnfreePredicate configuration option in the user configuration file.

    This option is a function which accepts a package as a parameter, and returns a boolean. The following example configuration accepts a package and always returns false:

    {
    allowUnfreePredicate = (pkg: false);
    }
    

    For a more useful example, try the following. This configuration only allows unfree packages named flash player and visual studio code:

    {
    allowUnfreePredicate = pkg: builtins.elem (lib.getName pkg) [
      "flashplayer"
      "vscode"
    ];
    }
    

This should work with packages that define name as well as with packages that define pname, as it's lib.getName's very purpose to abstract over those variations:
https://github.com/NixOS/nixpkgs/blob/747d5a3dbf1758ae4ef8037429337c029a9e76d0/lib/strings.nix#L475-L490

@das-g

I cant comment on this as I dont have Nix running anymore.
If anyone else still has this problem this can be kept open, otherwise closed

Unintentionally(?) fixed with 9b090ccbca3f7dd26d91db06e96e8bf8282c37ca / #74057, closing.

Was this page helpful?
0 / 5 - 0 ratings