1. My Current Understanding:
There seem to be 4 parts for identifying a package:
-
Attr Name: the nix-shell name, such as:
nixpkgs.ocamlPackages.pycaml
- I believe this is the most “official” name
- I don’t know much about how this name is generated. It seems to be related, but not quite, the path to the package inside nixPkgs. Ex:
ocaml-modules/pycaml/default.nix
.
This is probably my greatest need of clarification. - I believe this name can change what it refers to with new releases of nixpkgs. For example I think it is possible that
nixpkgs.ruby
can be ruby 2.1 on an old channel, but ruby 2.7 on a new channel. However, it seems that packages like python and llvm are frozen to keep pointing to their old versions (ex: python2 instead of python3). So I’m not sure. - Often times part (and only part) of the name will include the version. Ex:
nixpkgs.python38
- This refers to 1 and only one source (
nixpkgs.python
does not represent all sources offering python, or all sources offering python 2.7.18)
-
Version:
version =
- I believe this field is not required
- No strict format. It seems that the version is more permissive than the package name, since it can start with letters or numbers. It generally seems any string matching:
[.-+a-zA-Z0-9_]
in any order or quantity is allowed. For example:
version = "unstable-2020-08-31"
- The version can be set dynamically. Ex:
version = "${builtins.substring 0 6 rev}"
- There is an official comparison method by nix
builtins.parseDrvName
to decide if one package is a more-up-to-date version of another package. This is detailed in thenix-env --help
. However, many many packages seem to ignore this format entirely when setting their version.
-
PName:
pname =
, the “nix-env name”, the “pkg name”, the name of what is being installed, such as firefox, python, or zsh. This is what users use to install the latest version of a package without knowing the version.- Not all packages have a pname, according to How to find the real name (once installed) of a package
- The pname is also dynamic, and seemingly more so than the “specific name” (talked about next). For example:
pname = "dokuwiki-${hostName}"
- Multiple packages can have the same pname, but different Attr Name. Ex: python 3.8 can be found under many different Attr Names (which makes since due to different sources being able to offer the same tool & version).
- Some pnames include a variant name, such as
pname = "python3-minimal"
I’m not sure if this is an anti-pattern or not as I don’t know much about overrides and args. - There seem to be naming constraints, which look like they need to match the following regex
[a-zA-Z0-9_][.-+a-zA-Z0-9_]
However, I do not know of official requirements. - Some pnames have the anti-pattern of including the version, such as
pname = "cryptodev-linux-1.11"
-
Name:
name =
, Very confusingly the package has a name that is different from the pname/pkgName. I will refer to this one as the “package + version name” or the “specific package name” or “specific version name”. This name is also used innix-env
.- Unlike the first two, I believe all packages must have the package + version name.
- This name can still be programatic, sometimes very programatic, for example:
name = "heapster-${lib.strings.substring 0 7 rev}"
- I believe this is often, but not necessarily, the pname + version joined by a
-
However, this is a problem. Both the version and the pname are allowed to contain-
, letters, and numbers, meaning there is no way to know where the pname ends and the version begins. For example, this package2048-in-terminal-2017-11-29
, the2017-11-29
is the version.
Does this sound about right so far @vcunat ?
Questions: (@ anyone)
- Can
nix-env -qa -f $commit
on one machine can have different output thannix-env -qa -f $commit
on another machine/OS? - Can the pname/specific name/version be the result of a curl request (aka impure)
- Is it true that the Attr Name + nixpkg-commit-hash should uniquely be a specific-version of a specific-package? (even if that specific-version and specific-package can be a different depending on the OS)
- How is the Attr Name determined?
(including “sub” Attr Names like the “CGICompile” inperl530Packages.CGICompile
) - If the nixpkg-commit-hash changes (forward or backwards in time) can an Attr Name change what is refers to? e.g.
nixpkgs.python
=python-2.7.18
then at a later commit
nixpkgs.python
=python-3.8.1
I’ll try to keep this post up to date as new information comes in, and try to add links to relevant documentation and discourse posts as well.