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

Update packaging existing software tutorial #695

Conversation

proofconstruction
Copy link
Contributor

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 for pname and version in Packaging Existing Software with Nix.

@proofconstruction proofconstruction requested a review from a team as a code owner August 24, 2023 20:51
@@ -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`.
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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?

Copy link
Contributor

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':
Copy link
Contributor

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.

Copy link
Contributor Author

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 🙃

Copy link
Contributor Author

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

Copy link
Contributor

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.

Copy link
Collaborator

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.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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':
Copy link
Collaborator

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.

@fricklerhandwerk
Copy link
Collaborator

This is outdated. Most fixes were already applied in other PRs.

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

Successfully merging this pull request may close these issues.

None yet

3 participants