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: introduce binPath #67392
lib: introduce binPath #67392
Conversation
hmm, maybe only use builtins.parseDrvName to infer the binary name.
|
One idea is that if nixpkgs is consistently mapped, it will make it easy to build single-program containers with docker / firejail / ... |
It would be nice to also be able to annotate which packages don't have a default executable so they can fail during evaluation. |
renamed |
|
When wouldn't they return the same thing?
|
I was actually thinking about this recently in relation to NixOS modules :) One concern I had is that a user might override a package with a new However, I'm not sure to what extent anyone actually cares about being able to override the |
@@ -63,6 +63,9 @@ rec { | |||
# Pointless to do this on a remote machine. | |||
preferLocalBuild = true; | |||
allowSubstitutes = false; | |||
meta = { | |||
binPath = destination; |
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.
maybe only for executable
s?
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.
While working on this PR I discovered that there is already an executables
(plural) attribute. I have no idea what it's for.
$ rg "executables = \["
pkgs/os-specific/linux/autofs/default.nix
45: executables = [ "automount" ];
pkgs/tools/text/patchutils/generic.nix
23: executables = [ "combinediff" "dehtmldiff" "editdiff" "espdiff"
pkgs/tools/backup/dirvish/default.nix
13: executables = [ "dirvish" "dirvish-runall" "dirvish-expire" "dirvish-locate" ];
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.
summoning @winpat who added dirvish
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.
quick review suggests those are used only for build process, so probably not a subject for this PR
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.
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.
Good! Can you also add some real usages inside NixOS or Nixpkgs? Though I understand it's main purpose is to be used externally (by update bots most likely)
loosely related NixOS/nix#1049 |
also, loosely related https://github.com/NixOS/nixpkgs/pull/861/files. The idea is to force create With this PR, it could be inversed (as a NixOS module) - autocreate "/bin" symlinks based on |
I will convert the code inside of nixpkgs once the naming has stabilized. Most calls to Once the API is stable I also think that tools like nix-bundle and dockerTools.buildImage can be adapted to work 99% of the time. |
|
This could potentially benefit NixOS modules, see NixOS/rfcs#42 (comment) |
Ehh, it's a bit long...
Well, the function can't fail, but I get what you mean. I'm not sure that it's much worse than doing it manually, but I guess it is akin to a partial function in some sense.
👍 I like this. Then we can, for example, require |
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.
I think packages should instead declare that variable in their passthru
. E.g., for Python we have
python3.interpreter
which is the path to the Python executable (python3.executable
).
Don't we also somewhere have an attribute set which a bunch of these executables?
Yeah! That would be really nice. I had an old issue about this a while back: @edolstra wants to use the "defaultApp" in Flakes to accomplish this (NixOS/nix#2909), but we may be able to have some way to put this on plain derivations. |
I'm not sure how to move this forward. @domenkozar has a good point that bad paths wouldn't be detected automatically. On the other hand adding a derivation per derivation is also a lot of overhead. |
A lot of derivations have a *main* executable. For example pkgs.curl has bin/curl, pkgs.bash has bin/bash. Writing those can be repetitive: "${lib.getBin pkgs.bash}/bin/bash" Introduce a new `lib.binPath` function that can be used to infer a default binary path for all packages. "${lib.binPath pkgs.bash}" By default the binary is at $out/bin/$pname. For the package where that doesn't match it's possible to provide a `meta.binPath` attribute that contains the relative path to the binary.
Support the lib.binPath interface nix-repl> pkgs = import ./. {} nix-repl> pkg = pkgs.writeScript "foo" "hohoho" nix-repl> pkgs.lib.pkgBin pkg "/nix/store/v9xjci3rz9ck1amyfndh6wjz2f4d5v1l-foo" nix-repl> pkg2 = pkgs.writeScriptBin "foo" "hahaha" nix-repl> pkgs.lib.pkgBin pkg2 "/nix/store/0zp2hj619874rh2g1v8n62958f6scp6f-foo/bin/foo"
flakes are introducing a similar idea so maybe it's worth resurrecting this. { drv, name ? drv.pname or drv.name, exePath ? "/bin/${name}" }:
{
type = "app";
program = "${drv}${exePath}";
} |
replaced with #95615 which mimics the heuristic of |
A lot of derivations have a main executable. For example pkgs.curl has
bin/curl, pkgs.bash has bin/bash. Writing those can be repetitive:
Introduce a new
lib.binPath
function that can be used to infer adefault binary path for all packages.
By default the binary is at $out/bin/$pname. For the package where that
doesn't match it's possible to provide a
meta.binPath
attribute thatcontains the relative path to the binary.
Motivation for this change
Things done
sandbox
innix.conf
on non-NixOS)nix-shell -p nix-review --run "nix-review wip"
./result/bin/
)nix path-info -S
before and after)Notify maintainers
cc @