Conversation
otavio
left a comment
There was a problem hiding this comment.
Very nice. I found a minor issue in the env attribution. Please take a look.
2b11bc7 to
20009f9
Compare
thiagokokada
left a comment
There was a problem hiding this comment.
Also documentation.
|
Nice addition, if I understand correctly, this is an abstraction of https://github.com/NixOS/nixpkgs/blob/master/pkgs/shells/fish/wrapper.nix but for any shell? Right? |
Where should I put them?
IDK exactly. The idea here is to generate a wrapper script that runs the passed command inside a nix-shell like environment. |
In the same dir, check how the fetchers in |
20009f9 to
d0a60b5
Compare
d0a60b5 to
35058a6
Compare
Got it. Thank you. Next step: documentation. |
35058a6 to
26a1501
Compare
8adcbce to
5e2525a
Compare
|
Added docs, rendered locally and it seems everyting is fine. EDIT 1: Docs are much better to work with now, congratulations to the ones involved! |
5e2525a to
7021bba
Compare
7021bba to
599cf67
Compare
|
This pull request has been mentioned on NixOS Discourse. There might be relevant details there: https://discourse.nixos.org/t/prs-ready-for-review/3032/2677 |
There was a problem hiding this comment.
I think there should be a better name for this, when I first saw this PR I thought it was a function to wrap shell's like bash and zsh.
Maybe runInMkShell
There's runInLinuxImage and runInLinuxVM in vmTools
There was a problem hiding this comment.
Well. I suggested that actually because the name is like mkShell. I also added the documentation for it right after mkShell because of SEO, discoverability.
I already did this kind of SEO many times like when I added a section in Hugo docs and opened issues while I was troubleshooting stuff and closed them right after with the solution I found so that would get better SEO and reach more people.
There was a problem hiding this comment.
changed to runInMkShell
There was a problem hiding this comment.
Would be better to just have users pass a drv always, and rename the argument to shellDrv.
There was a problem hiding this comment.
This is the reference behaviour but as most of the usecases are just passing packages in or passing the output of mkShell I think that is useful to support these usecases.
The drv name I got from the function that it's based on (dockerTools.streamNixShellImage).
599cf67 to
fc1714d
Compare
roberth
left a comment
There was a problem hiding this comment.
This idea fits the direction Nix+Nixpkgs should take; see comment.
I hope you can refactor it to share code for with the dockerTools function.
If done later, it might feel like runInMkShell is hard to change.
There was a problem hiding this comment.
I would like this to be the other way around. Currently Nix has suboptimal, yet ossified logic to implement "shells" because it couples with Nixpkgs stdenv. By flipping this around and making this function the default nix shell implementation, we could solve that architectural problem and let the behavior of nix-shell/nix develop evolve in a future proof way by pinning/locking Nixpkgs.
This would happen through an indirection such as a pkg.devShell attribute, e.g.
This idea was received quite positively by the Nix team (even though we don't have an approved issue for it - I think we discussed it before the label).
It's fine to describe it this way until nix uses the devShell (or similarly named) attribute, so no change required here.
There was a problem hiding this comment.
Not quite happy about the name.
runInis a prefix that was also used forrunInLinuxVM, but this is not a derivation wrapper that runs the wrapped builder as part of its builder.MkShellwould suggest that it's specific to that function, but it's more general.mkused to be for functions that are "data constructors"; functions that return their arguments in a specific, checked form.
Maybe not the best suggestion, but here's one:
| # pkgs.runInMkShell {#sec-pkgs-runInMkShell} | |
| # pkgs.buildShell {#sec-pkgs-buildShell} |
There was a problem hiding this comment.
What about buildShellWrapper?
There was a problem hiding this comment.
What about buildShellWrapper?
There was a problem hiding this comment.
Best to describe in terms of what it does. Something about a wrapper script that provides an environment similar to what Nix and stdenv provide.
There was a problem hiding this comment.
I explained a bit about the context of it's creation there.
There was a problem hiding this comment.
It would be good to generate a script in $out/bin, "writeScriptBin style". That way the same function can produce for instance a file with just the environment variables for use in different shells (zsh, fish, ...), and potentially other files.
Splitting the executable and the bash library may also help with clarity.
Example files:
$out/bin/shell$out/shell.sh$out/shell.env
.env could be done later. It's fine to limit this to bash usage for the time being.
I'd suggest not to call it $out/bin/build-shell etc, because that would suggest that the shell has to be closely align with some build, which it does not. These files form an interface that's more broadly applicable, including proper development shells that aren't necessarily about any specific build.
There was a problem hiding this comment.
Isn't $stdenv/setup already coupled with Bash?
BTW the generated script already checks if it's being sourced and don't run the entrypoint if yes.
There was a problem hiding this comment.
checks if it's being sourced
Then you could symlink the .sh file to the executable.
My main point is that a directory can serve more purposes. For instance, shell.env could be the backend for nix print-dev-env, to support other shells, IDE extensions, ...
That's a bit more work to extract those variables, which is why I'm suggesting to do it later, but leave an "empty spot" for it in the output by making it a directory.
There was a problem hiding this comment.
writeScriptBin mostly accomplishes that.
I don't want Nix to impose a requirement that the script must also be source-able or anything, which is why I lean towards having separate files for these purposes.
For instance we'll probably want to do something like setPersonality at some point, which seems like it will need a little C wrapper, which would not be natural to also support with the source-able executable pattern.
There was a problem hiding this comment.
How can I export the environment from inside the shell?
It kind of works using env but there are variables that span to multiple lines.
There was a problem hiding this comment.
I was thinking about using python to dump os.environ as json
There was a problem hiding this comment.
I was experimenting on only dumping /proc/self/environ.
It splits each variable definition with an \00 but bash is not behaving nicely when using that IFS feature in the run command.
There was a problem hiding this comment.
That still didn't get multi line values
But this works nice: https://github.com/lucasew/playground/blob/master/shell/dump-env-from-proc
a7b8719 to
9dadcc2
Compare
e99b50a to
e55ed81
Compare
|
I added another dockerTools function because in my experience that function is kind of broken for the usecase I was using it. I wanted a behaviour kind of like happens with the official rclone container. After the image name you pass directly the arguments and by default you pass the command that would run inside that environment. That way the wrapper script would always run then use the rest of the arguments as the command itself to run. Very simple to use and I don't need to break a function that is already being used somewhere. |
a5aef00 to
3b49b3f
Compare
Signed-off-by: lucasew <lucas59356@gmail.com>
…Shell Signed-off-by: lucasew <lucas59356@gmail.com>
3b49b3f to
a80c08a
Compare



Description of changes
This is based on code from
dockerTools.streamNixShellImagein the hope that the same primitives could be generalized to other runtimes such as bundled executables, appimages, OCI containers and Singularity images.I am not an expert in this domain tho but I had to adapt
dockerTools.streamNixShellImageto use in production, also with guibou's nixGL so the GPUs get recognized.As of
dockerTools.streamNixShellImage,mkShellWrapperis based onmkShellbut instead of generating an image it generates a script, like awriteShellScriptthat one can use directly in the entrypoint then pass the command to run inside the environment as parameters. All the nix-shell goodness should hopefully work here.BTW drv can be either a derivation generated by
mkShellor a attrset withmkShellparameters.I am testing with the following snippet and can confirm it works:
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/)