lib.getExe: Do not make assumptions about the main program#246386
Merged
roberth merged 5 commits intoNixOS:masterfrom Aug 2, 2023
Merged
lib.getExe: Do not make assumptions about the main program#246386roberth merged 5 commits intoNixOS:masterfrom
roberth merged 5 commits intoNixOS:masterfrom
Conversation
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/`.
68b6646 to
e82c082
Compare
Based on ofborg feedback. Part of NixOS#246386
e82c082 to
0ed9e35
Compare
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
13 tasks
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.mainProgramis 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
getExethemselves, 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.getExeon 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
getExecall 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% ofgetExeusages to be covered by 20% of packages, because plenty of packages aren't used withgetExeanyway.Finally we could make an effort to set
mainProgramsemi-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 = trueset 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/)