Skip to content

Comments

mkShell: make it buildable#153194

Merged
zimbatm merged 6 commits intoNixOS:masterfrom
zimbatm:buildable-mkshell
Jan 8, 2022
Merged

mkShell: make it buildable#153194
zimbatm merged 6 commits intoNixOS:masterfrom
zimbatm:buildable-mkshell

Conversation

@zimbatm
Copy link
Member

@zimbatm zimbatm commented Jan 2, 2022

When I designed mkShell, I didn't have a good idea of what the output
should look like and so decided to make the build fail. In practice,
this causes quite a bit of confusion and complications because now the
shell cannot be part of a normal package set without failing the CI as
well.

This commit changes that build phase to record all the build inputs in a
file. That way it becomes possible to build it, makes sure that all the
build inputs get built as well, and also can be used as a GC root.
(by applying the same trick as #95536).

The documentation has also been improved to better describe what mkShell
does and how to use it.

Motivation for this change
Things done
  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandbox = true set in nix.conf? (See Nix manual)
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • 22.05 Release Notes (or backporting 21.11 Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
    • (Release notes changes) Ran nixos/doc/manual/md-to-db.sh to update generated release notes
  • Fits CONTRIBUTING.md.

@github-actions github-actions bot added the 8.has: documentation This PR adds or changes documentation label Jan 2, 2022
@zimbatm zimbatm requested a review from infinisil January 2, 2022 11:09
@ofborg ofborg bot added 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. 10.rebuild-linux: 0 This PR does not cause any packages to rebuild on Linux. labels Jan 2, 2022
@roberth
Copy link
Member

roberth commented Jan 2, 2022

You could also write out a shell script that behaves like a better nix-shell.

Right now, the output is a single file with no room for extension, because it is not a directory. A good first step is to write to $out/env.sh instead, so other files can be added.

@zimbatm
Copy link
Member Author

zimbatm commented Jan 2, 2022

There is an infinite number of things I could do. The question is; is this PR better than before? I will make it so that the file is unusable, as it's not meant to be part of the interface.

When I designed `mkShell`, I didn't have a good idea of what the output
should look like and so decided to make the build fail. In practice,
this causes quite a bit of confusion and complications because now the
shell cannot be part of a normal package set without failing the CI as
well.

This commit changes that build phase to record all the build inputs in a
file. That way it becomes possible to build it, makes sure that all the
build inputs get built as well, and also can be used as a GC root.
(by applying the same trick as NixOS#95536).

The documentation has also been improved to better describe what mkShell
does and how to use it.
@zimbatm zimbatm force-pushed the buildable-mkshell branch from 9fe7be3 to 28e0397 Compare January 2, 2022 14:43
@roberth
Copy link
Member

roberth commented Jan 2, 2022

I'm not asking you to do an infinite number of things, just to prevent a future breaking change.

I will make it so that the file is unusable

That makes it a non-breaking change. 👍


buildPhase = ''
echo "-------------------------------------------" >> $out
echo " Do not use this file. See the mkShell doc." >>$out
Copy link
Member

@roberth roberth Jan 2, 2022

Choose a reason for hiding this comment

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

I don't quite understand why. Could you explain it here in the message?

Copy link
Member Author

Choose a reason for hiding this comment

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

Ok, this is ready for another round of review.

@zimbatm zimbatm requested review from cole-h and roberth January 4, 2022 16:53
@zimbatm
Copy link
Member Author

zimbatm commented Jan 4, 2022

Waiting for a last round of reviews.

@zimbatm zimbatm merged commit 1e91020 into NixOS:master Jan 8, 2022
@zimbatm zimbatm deleted the buildable-mkshell branch January 8, 2022 00:54
@rvl
Copy link
Contributor

rvl commented Feb 9, 2022

Very helpful, thanks @zimbatm and @roberth - I can remove my nobuildPhase overrides now.

@Atry
Copy link
Contributor

Atry commented May 25, 2022

buildEnv is not used anywhere. Shall we delete it?

@roberth
Copy link
Member

roberth commented May 25, 2022

@Atry well spotted. Feel free to go ahead.

@charles-dyfis-net
Copy link
Contributor

There's still equivalent logic to the restriction this pulls elsewhere in nixpkgs:

pkgs/build-support/build-fhsenv-bubblewrap/default.nix:      echo >&2 "*** User chroot 'env' attributes are intended for interactive nix-shell sessions, not for building! ***"
pkgs/build-support/build-fhsenv-chroot/default.nix:      echo >&2 "*** User chroot 'env' attributes are intended for interactive nix-shell sessions, not for building! ***"
pkgs/development/interpreters/lua-5/wrapper.nix:          echo >&2 "*** lua 'env' attributes are intended for interactive nix-shell sessions, not for building! ***"
pkgs/development/interpreters/octave/build-env.nix:        echo >&2 "*** octave 'env' attributes are intended for interactive nix-shell sessions, not for building! ***"
pkgs/development/interpreters/python/wrapper.nix:          echo >&2 "*** Python 'env' attributes are intended for interactive nix-shell sessions, not for building! ***"
pkgs/development/ruby-modules/bundled-common/default.nix:            echo >&2 "*** Ruby 'env' attributes are intended for interactive nix-shell sessions, not for building! ***"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

8.has: documentation This PR adds or changes documentation 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. 10.rebuild-linux: 0 This PR does not cause any packages to rebuild on Linux.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants