-
Notifications
You must be signed in to change notification settings - Fork 63
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
Support cabal/stack/nix shebangs #217
Comments
Firstly, iirc, the fields
That used to work, but apparently there was some regression? E.g. when
Is there a way to get the ghci arguments from nix that are used to compile this script? |
Could we implement it first for one that works natively in all operating systems, please? 😄 |
I think by default it doesn't use any arguments to ghci. It just creates a ghc installation with the relevant packages installed, sets the environment variables to point to that ghcWithPackages and puts it in path and runs Another option for nix could be to fetch the environment variables that nix creates the same way that direnv does it. |
@jneira What do you mean with "natively"? Is WSL ok? If so, I would assume that all three should work in all three major environments (Linux, Mac, Windows), but I haven't tested it on Windows yet. Does shebangs work on windows at all without WSL? |
In fact i wanted to exclude it. 😉
Yeah, in a msys2 console, for example. |
Probably true, this makes it very complicated for us to know how to compile the given file. Without further support from nix, I dont think this will be easy to integrate at all. |
@fendor Why does not needing command line arguments make it difficult? I am not familiar with the internals of how hie-bios works. Why is not environment variables sufficient? If all we need is a ghci with the right environment, this should work:
But I assume something more is needed for the ide to work? |
Because hie-bios by design asks the build-tool how it should compile a given file. It tells these options to ghcide/hls, which use them to load and compile the given file. I dont really see how this workflow can integrate a nix-shell, since hie-bios would need to open the shell, but ghcide / hls will eventually use the options to compile the flag and they are not within the nix-shell anymore.
What information is given in environment variables? |
I was going to say "no flags are needed" again, but apparently there are flags, they are just sneakily applied through a wrapper shell script. The only relevant environment variable seems to be PATH, which includes a link to the generated GHC installation. This installation contains wrapper shell scripts for all the ghc* binaries. Here is for example the generated
and here is the generated
I guess we could parse these generated files to extract the arguments from that, or I could see if there is a more direct way to get the arguments. |
Here is the file that generates the wrapper-scripts: https://github.com/NixOS/nixpkgs/blob/f5b6ea126f0f85cd2126984607e95151daf9a859/pkgs/development/haskell-modules/with-packages-wrapper.nix But maybe we can see nix-shell as a build tool and simply forward Edit: Nope, it seems like at least ghcide doesn't support that option. So I guess the command line flags are needed. |
No, because this runs the shell, but HLS/ghcide itself is responsible for the ghci session. Some of these options seem helpful. Maybe we can craft a bios cradle that does what we want. |
Ah, right. We ask cabal/stack about the command line flags by feeding it a fake ghc that just prints its arguments here: https://github.com/mpickering/hie-bios/blob/2ac11025a109e5f09693c3f328cf05994f9fbb9d/src/HIE/Bios/Cradle.hs#L436-L439 I see. Yes, the same trick wouldn't quite work with nix-shell since the ghc it uses is hard coded in the script. So I guess we would either have to parse the shell script or just extract the base path and assume the relative path stays the same (except for ghc-version number). Or add some tool to Btw, I tried using |
You probably need: cradle:
direct:
arguments: ["-B/nix/store/c36yvssdnv05sgcszsmm5fj9iky7impx-ghc-8.8.3-with-packages/lib/ghc-8.8.3"] since it is a single option, not two. |
No. That is not the problem. It seems like it doesn't accept flags for some reason. Only a "module name or a source file". :/ |
A thing that I think would work for stack at least is to detect if there's a stack project and then use |
@wraithm If there is a stack project, then we basically do this already. |
@fendor In my experience, if there isn't an explicit component listed in the For example, I can do
I don't have a ghc installed globally. I'm only using stack. But even if I put the stack installed ghc into my path, it can't find the libraries I reference. It seems like it's trying to open the file with the "direct" cradle, but that doesn't work for my case.
|
Maybe you've fixed this in a newer version? |
I see what you mean and indeed, we do not default to the stack cradle ever, except when we find a "stack.yaml" (assuming stack can be found). cradle:
stack:
component: "<path/to/File.hs>" I think it opens it a "Default" Cradle which also needs a "ghc" on the $PATH. |
So, firstly, I'm opening this file inside of a stack.yaml containing project. This haskell file is actually in the same directory as the If I do the
I assume this means that the
I get:
Which again seems to be trying to use the direct cradle. The only thing that works is making a cabal file and registering that package with the |
All three tools support writing a self-contained haskell script with a shebang at the top which describes
what package dependencies the Haskell script has.
Cabal syntax
Cabal
Cabal syntax looks like this: https://github.com/nrolland/helloNixShebang/blob/master/cabal_hello.hs
and is documented ... here i guess?
Stack syntax
Stack
Stack syntax looks like this
or like this
and is documented here: https://docs.haskellstack.org/en/latest/GUIDE/#script-interpreter
Nix syntax
Nix
Nix syntax looks like this: https://github.com/nrolland/helloNixShebang/blob/master/nix_hello.hs
and is documented here (and here)
I would love to have support for any of the three formats in ghcide, whichever is easiest to implement.
The nix support could probably be implemented by having the process relaunch itself (or the ghci instance) in a nix-shell with the parameters from the
nix-shell
shebang line, excluding the-i runghc
part. I don't know if stack/cabal support would require any extra support from stack/cabal or if everything we need is already available.The text was updated successfully, but these errors were encountered: