-
-
Notifications
You must be signed in to change notification settings - Fork 14.9k
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
lib.getExe: Do not make assumptions about the main program #246386
Merged
roberth
merged 5 commits into
NixOS:master
from
hercules-ci:lib-getExe-dont-make-name-assumption
Aug 2, 2023
Merged
lib.getExe: Do not make assumptions about the main program #246386
roberth
merged 5 commits into
NixOS:master
from
hercules-ci:lib-getExe-dont-make-name-assumption
Aug 2, 2023
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Before this commit, getExe assumes that if `meta.mainProgram` is unset, it has a main program that's named after the package name. While this is probable, it leads to a bad error when the assumption does not hold. If the user called `getExe` themselves, they might narrow down the location of the assumption quite easily, but if that's not the case, they'll have to go down the rabbit hole to figure out what went wrong. For example, a NixOS module may use `lib.getExe` on a package-typed option which is then used in the system configuration. This then typically leads to a failure *after* deployment, which is bad, and it's quite likely that the user will debug the package output contents before digging through the NixOS module, which is bad. Furthermore the `getExe` call is rather inconspicuous as it does not contain something like "/bin/foo", which is bad. Also modules can be hard to read for a newbie, which is bad. All of this can be avoided by requiring `meta.mainProgram`. Many packages already have the attribute, and I would expect 80% of `getExe` usages to be covered by 20% of packages, because plenty of packages aren't used with `getExe` anyway. Finally we could make an effort to set `mainProgram` semi-automatically using `nix-index`.
13 tasks
Unfortunately there's no test for me to confirm that it works, so all I can do is ask for maintainers, unfortunately -- I mean... This is your opportunity!
This should fix most warnings getExe in based on grepping `nixos/`.
drupol
approved these changes
Jul 31, 2023
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.
LGTM and I support this.
68b6646
to
e82c082
Compare
Based on ofborg feedback. Part of NixOS#246386
e82c082
to
0ed9e35
Compare
12 tasks
12 tasks
12 tasks
12 tasks
This pull request has been mentioned on NixOS Discourse. There might be relevant details there: |
Artturin
pushed a commit
that referenced
this pull request
Sep 19, 2023
toastal
pushed a commit
to toastal/nixpkgs
that referenced
this pull request
Sep 25, 2023
12 tasks
12 tasks
12 tasks
This was referenced Oct 15, 2023
arcnmx
added a commit
to arcnmx/nixpkgs
that referenced
this pull request
Oct 28, 2023
13 tasks
arcnmx
added a commit
to arcnmx/nixpkgs
that referenced
this pull request
Jan 18, 2024
13 tasks
13 tasks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
6.topic: GNOME
GNOME desktop environment and its underlying platform
6.topic: lib
The Nixpkgs function library
6.topic: nixos
Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS
6.topic: python
8.has: clean-up
8.has: module (update)
This PR changes an existing module in `nixos/`
10.rebuild-darwin: 0
This PR does not cause any packages to rebuild on Darwin
10.rebuild-linux: 1-10
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Before this commit, getExe assumes that if
meta.mainProgram
is unset, it has a main program that's named after the package name.While this is probable, it leads to a bad error when the assumption does not hold. If the user called
getExe
themselves, they might narrow down the location of the assumption quite easily, but if that's not the case, they'll have to go down the rabbit hole to figure out what went wrong.For example, a NixOS module may use
lib.getExe
on a package-typed option which is then used in the system configuration. This then typically leads to a failure after deployment, which is bad, and it's quite likely that the user will debug the package output contents before digging through the NixOS module, which is bad.Furthermore the
getExe
call is rather inconspicuous as it does not contain something like "/bin/foo", which is bad.Also modules can be hard to read for a newbie, which is bad.
All of this can be avoided by requiring
meta.mainProgram
. Many packages already have the attribute, and I would expect 80% ofgetExe
usages to be covered by 20% of packages, because plenty of packages aren't used withgetExe
anyway.Finally we could make an effort to set
mainProgram
semi-automatically usingnix-index
.Description of changes
Adds a warning to the unreliable behavior.
Context
Introduced in lib/meta: add getExe to get the main program of a drv #167247
Tangentially related to the point of off-topic: Make getExe (writeScript x y) work #173675
Things done
sandbox = true
set innix.conf
? (See Nix manual)nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD"
. Note: all changes have to be committed, also see nixpkgs-review usage./result/bin/
)