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
Update packaging existing software tutorial #695
Update packaging existing software tutorial #695
Conversation
@@ -46,12 +46,21 @@ As you progress through this tutorial, you will update this several times, addin | |||
### Hello, World! | |||
GNU Hello is an implementation of the "hello world" program, with source code accessible [from the GNU Project's FTP server](https://ftp.gnu.org/gnu/hello/). | |||
|
|||
To begin, you should add a `name` attribute to the set passed to `mkDerivation`; every derivation needs a name, and Nix will throw `error: derivation name missing` without one. | |||
Every derivation needs a package name and version, so to begin, you should add a `pname` attribute and a `version` string to the set passed to `mkDerivation`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick: both pname
and version
are attributes. Referring to one as an attribute and the other as a string is slightly misleading.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Every derivation needs a package name and version, so to begin, you should add a `pname` attribute and a `version` string to the set passed to `mkDerivation`. | |
Every derivation needs a package name and version, so to begin, you should add `pname` and `version` attributes to the set passed to `mkDerivation`, setting these to appropriate strings. |
Good point. How about this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me 👍
|
||
To avoid repeating yourself, and to make later updates to the package a little bit easier, you should set the `version` to `0.5` and then use [string interpolation](https://nix.dev/tutorials/first-steps/nix-language#string-interpolation) in the `rev` attribute passed to `fetchFromGitHub`. | ||
|
||
For `version` to be accessible to `rev`, the attribute set passed to `stdenv.mkDerivation` must be [*recursive*](https://nix.dev/tutorials/first-steps/nix-language#recursive-attribute-set-rec), so you should also add the `rec` keyword to avoid seeing `error: undefined variable 'version': |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It may be better practice to use a let
binding instead of rec
since rec
can make it hard to trace data flow.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Normally I would, but last time I submitted, I was told not to use let
🙃
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, so we're actually supposed to do this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sigh
Maybe you're "supposed" to do the last one, but that's so much more complicated than the other solutions that I'm inclined to say just throw your hands up and use rec
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
finalAttrs
is absolutely the right way to do it and severely underdocumented. In suppose has to be taught somewhat separately because it's tied into overrides, but for now we could do a compromise and use either let or rec with a note that there also exist finalAttrs, and then later reorder the tutorials to start with consuming existing packages. Since I took it upon me to extend the curriculum running into these issues is valuable input.
The most recent version of `hello` available on the FTP server is 2.12.1. | ||
|
||
:::{note} | ||
For historical reasons, Nix uses the `pname` and `version` attributes to construct a `name` attribute. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For historical reasons, Nix uses the `pname` and `version` attributes to construct a `name` attribute. | |
For historical reasons, Nix uses the `pname` and `version` attributes to construct a `name` attribute passed to the underlying call to [`builtins.derivation`](). |
Please add a link to the Nix manual
|
||
To avoid repeating yourself, and to make later updates to the package a little bit easier, you should set the `version` to `0.5` and then use [string interpolation](https://nix.dev/tutorials/first-steps/nix-language#string-interpolation) in the `rev` attribute passed to `fetchFromGitHub`. | ||
|
||
For `version` to be accessible to `rev`, the attribute set passed to `stdenv.mkDerivation` must be [*recursive*](https://nix.dev/tutorials/first-steps/nix-language#recursive-attribute-set-rec), so you should also add the `rec` keyword to avoid seeing `error: undefined variable 'version': |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
finalAttrs
is absolutely the right way to do it and severely underdocumented. In suppose has to be taught somewhat separately because it's tied into overrides, but for now we could do a compromise and use either let or rec with a note that there also exist finalAttrs, and then later reorder the tutorials to start with consuming existing packages. Since I took it upon me to extend the curriculum running into these issues is valuable input.
This is outdated. Most fixes were already applied in other PRs. |
We discussed feedback from Discourse and Reddit in today's docs team meetings, and decided it would be best to drop the
name
attribute and go straight forpname
andversion
in Packaging Existing Software with Nix.