Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong documentation for non-free packages #67830

Closed
b-m-f opened this issue Aug 31, 2019 · 11 comments
Closed

Wrong documentation for non-free packages #67830

b-m-f opened this issue Aug 31, 2019 · 11 comments

Comments

@b-m-f
Copy link
Contributor

b-m-f commented Aug 31, 2019

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?

@davidak
Copy link
Member

davidak commented Sep 2, 2019

Related to #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.

@das-g
Copy link
Member

das-g commented Oct 16, 2019

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"
    ]);
}

@das-g
Copy link
Member

das-g commented Oct 16, 2019

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"
    ]
  );

  # ...
}

@das-g
Copy link
Member

das-g commented Oct 17, 2019

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?

@nixos-discourse
Copy link

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

@nixos-discourse
Copy link

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

@stale
Copy link

stale bot commented Nov 3, 2020

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

@stale stale bot added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Nov 3, 2020
@davidak
Copy link
Member

davidak commented Nov 3, 2020

...

@stale stale bot removed the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Nov 3, 2020
@das-g
Copy link
Member

das-g commented Nov 3, 2020

Is this issue still a problem?

Currently (and probably since 20.03, which included 9b090cc), 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:

nixpkgs/lib/strings.nix

Lines 475 to 490 in 747d5a3

/* This function takes an argument that's either a derivation or a
derivation's "name" attribute and extracts the name part from that
argument.
Example:
getName "youtube-dl-2016.01.01"
=> "youtube-dl"
getName pkgs.youtube-dl
=> "youtube-dl"
*/
getName = x:
let
parse = drv: (builtins.parseDrvName drv).name;
in if isString x
then parse x
else x.pname or (parse x.name);

@b-m-f
Copy link
Contributor Author

b-m-f commented Nov 3, 2020

@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

@das-g
Copy link
Member

das-g commented Nov 3, 2020

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

@das-g das-g closed this as completed Nov 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants