Navigation Menu

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

Manual Ch. 6 Package management ambiguous examples #55556

Closed
AMDphreak opened this issue Feb 11, 2019 · 5 comments
Closed

Manual Ch. 6 Package management ambiguous examples #55556

AMDphreak opened this issue Feb 11, 2019 · 5 comments

Comments

@AMDphreak
Copy link

AMDphreak commented Feb 11, 2019

Issue description

Nixos declarative package management has zero explanation for why trying to install a package using nixos.packagename causes an error:

This example code in the manual:

$ nix-env -qaP '*' --description
nixos.firefox   firefox-23.0   Mozilla Firefox - the browser, reloaded
...

has this note under it, which is misleading:

(The nixos prefix allows distinguishing between different channels that you might have.)

I took this advice and applied it directly to my declarations in a separate .nix file, since I am subscribed to the nixos stable channel:

{ config, pkgs, ... }:

{
  environment.systemPackages = [
    nixos.firefox
  ];
}

however, nixos.firefox causes an error (whereas pkgs.firefox does not):

# nixos-rebuild build
building Nix...
building the system configuration...
error: attribute 'nixos' missing, at /nix/var/nix/profiles/per-user/root/channels/nixos/lib/modules.nix:163:28
  1. What does nixos.packagename require in order to be valid syntax? When would I use this?

To add to the confusion, https://nixos.wiki/wiki/Cheatsheet contains examples (shown below) that are inconsistent with Ch. 6.

Cheatsheet:

systemPackages = with pkgs;
                    [ <other packages...> emacs ];

It is not apparent to the reader that the writer excluded the required environment = { line before the systemPackages line. To make this even more confusing, the systemPackages statement uses a with pkgs statement, which has zero explanation.

  1. Make the required environment = block apparent and make the examples consistent for the sake of the reader.
  2. What is the purpose of the with statement in this context?

Proposal: add answers for these questions to the manual.

@FRidh
Copy link
Member

FRidh commented Feb 15, 2019

Knowledge of the Nix language is a prerequisite for being able to understand and write Nix expressions found in the NixOS manual.

@jtojnar
Copy link
Contributor

jtojnar commented Feb 16, 2019

As Frederik says, you really need to understand Nix syntax before trying to tackle anything using it.

Most importantly is the fact that there are no free variables – you can only access the variables that are defined using let expression inside the body after in, or function arguments inside the function body, or attributes of a record inside the body of with expression.

{ config, pkgs, ... }:

{
  environment.systemPackages = [
    nixos.firefox
  ];
}

As you can see, there is no with expression, nor is there a let binding, nor is there a nixos among the function arguments, therefore the name/attribute/variable is missing:

error: attribute 'nixos' missing, at /nix/var/nix/profiles/per-user/root/channels/nixos/lib/modules.nix:163:28

The nixos. prefix in the nix-env output is only relevant to nix-env (imperative package management). Personally, I would just remove the nix-env mention from declarative section and direct users to list of packages.

  1. What does nixos.packagename require in order to be valid syntax? When would I use this?

It refers to the fact that packagename attribute is part of pkgs in a channel named nixos. Conveniently, the pkgs argument passed to the NixOS configuration also commonly points to the pkgs attribute in nixos channel so you can access the package through pkgs.packagename in the configuration expression. Note that the channels hide a lot of magic and this might not be true in a general case (e.g. if you change the NIX_PATH or pass -I arguments to nixos-rebuild).

It is not apparent to the reader that the writer excluded the required environment = { line before the systemPackages line. To make this even more confusing, the systemPackages statement uses a with pkgs statement, which has zero explanation.

This can be assumed from context (there is only single systemPackages attribute) but for clarity it should probably contain the environment parent. with is again part of Nix syntax and user should be familiar with it. pkgs is expected to be passed to nixos-configuration as an argument, yet another idiom.

@danbst
Copy link
Contributor

danbst commented Mar 15, 2019

@AMDphreak thanks, fixed wiki! Also made environment.systemPackages usages consistent.

@matthewbauer matthewbauer added this to the 19.09 milestone May 27, 2019
@stale
Copy link

stale bot commented Jun 2, 2020

Thank you for your contributions.

This has been automatically marked as stale because it has had no activity for 180 days.

If this is still important to you, we ask that you leave a comment below. Your comment can be as simple as "still important to me". This lets people see that at least one person still cares about this. Someone will have to do this at most twice a year if there is no other activity.

Here are suggestions that might help resolve this more quickly:

  1. Search for maintainers and people that previously touched the related code and @ mention them in a comment.
  2. Ask on the NixOS Discourse.
  3. Ask on the #nixos channel on irc.freenode.net.

@stale stale bot added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Jun 2, 2020
@veprbl veprbl removed this from the 19.09 milestone May 31, 2021
@stale stale bot removed the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label May 31, 2021
@jtojnar
Copy link
Contributor

jtojnar commented Jun 3, 2021

Fixed in #57617

@jtojnar jtojnar closed this as completed Jun 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants