Giter Site home page Giter Site logo

shellHook does not seem to run about lorri HOT 13 CLOSED

target avatar target commented on June 24, 2024 8
shellHook does not seem to run

from lorri.

Comments (13)

Profpatsch avatar Profpatsch commented on June 24, 2024 1

Did you use it from direnv? shellHook is specifically only called from nix-shell, lorri direnv does not source it.

For your example, you can easily add FOO this way:

with import <nixpkgs> {};

mkShell {
  FOO="BAR"
}

(because everything you pass to mkShell is passed to mkDerivation (is passed to derivation), which convert each field in their argument attrset (like shellHook or buildPhase or in this case FOO) to an environment variable.

In general we might have to think about how to integrate shellHook in a way that is backwards-compatible to nix-shell. cc @grahamc

from lorri.

Fresheyeball avatar Fresheyeball commented on June 24, 2024 1

I have non-trivial scripts in my shellHook that expose bash functions that do things like setup test environments. It would be nice if everything in shellHook ran, so that echo "instructions on how to use this shell" get printed along without whatever else is going on.

from lorri.

danbst avatar danbst commented on June 24, 2024

yeah, sourcing shellHook would be great. Maybe even allow variable IS_IN_LORRI

from lorri.

sveitser avatar sveitser commented on June 24, 2024

Thanks for the quick reply. Yes, I was using it with direnv. We are prepending a local directory containing some utility scripts to PATH in the shellHook. When switching over from direnv + nix-shell to direnv + lorri those weren't available anymore.

from lorri.

Profpatsch avatar Profpatsch commented on June 24, 2024

Note that we have the same problem in lorri itself, so a good solution would be class.

As in: we add the paths both in .envrc and in shell.nix.

from lorri.

Profpatsch avatar Profpatsch commented on June 24, 2024

It looks like some packages set up implicit shell hooks as well: #23 (comment)

So this becomes more pressing to implement.

from lorri.

Profpatsch avatar Profpatsch commented on June 24, 2024

It’s a bit more complicated than that actually, we can’t just re-use existing shellHooks that packages provide, because they rely on the exact environment provided by the nix builder, which lorri cannot guarantee.

@grahamc gave an example of a problematic shellHook:

rm -rf $(find-the-thing)/*
and find-the-thing is defined in another hook which we don’t load.

so lorri/direnv would effectively execute rm -rf /* in that case.

We need to provide a good mechanism to achieve something similar with lorri.

from lorri.

danbst avatar danbst commented on June 24, 2024

maybe add an arg --shell-hook to make it opt-in?

from lorri.

Profpatsch avatar Profpatsch commented on June 24, 2024

maybe add an arg --shell-hook to make it opt-in?

We could do something like lorriHook which users can explicitely alias to shellHook if they want to use it with lorri as well. Then we can define a strict environments we provide.

But we can’t really allow shellHooks from transitive packages, for the reason I’ve outlined above. It’s just impossible to handle in the general case. But most of those hooks are pretty easy to adapt for the user I think (e.g. just manually write GOPATH=… into your hook).

from lorri.

Profpatsch avatar Profpatsch commented on June 24, 2024

I have no trivial scripts in my shellHook that expose bash functions that do things like setup test environments.

Does this mean you do have bash functions in your shellHook? Or the opposite?

from lorri.

Profpatsch avatar Profpatsch commented on June 24, 2024

As a stop-gap solution we could display a warning to the user that a shellHook was not executed (and maybe the contents of the shellHook).

from lorri.

Drainful avatar Drainful commented on June 24, 2024

I have a partial workaround for people who live in Emacs
https://gist.github.com/Drainful/a3cd702dc590480cf4897a9859fc499f

from lorri.

grahamc avatar grahamc commented on June 24, 2024

Addressed in #75

from lorri.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.