Skip to content
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

[WIP] ghc.withPackages: can add user arguments to wrapper #58341

Closed
wants to merge 1 commit into from

Conversation

teto
Copy link
Member

@teto teto commented Mar 26, 2019

Motivation for this change

I am trying to debug a haskell library used by my program. Everytime I change this library, I need to relaunch the nix-shell of my haskell program to get an up to date ghc environment.
My idea is to wrap the GHC with an -i/local/lib/we/debug. Because the library I debug is also in NIX_GHC_LIBDIR, I wonder if I can prefix NIX_GHC_LIBDIR so that ghc picks the debug version over the one in the environment.
If there is a better way let me know.

One difficulty is I am not sure how to pass postBuild, makeWrapper args to withPackages, the feature seem unused ?

Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nix-review --run "nix-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Determined the impact on package closure size (by running nix path-info -S before and after)
  • Assured whether relevant documentation is up to date
  • Fits CONTRIBUTING.md.

@teto teto changed the title ghc.withPackages: can add user arguments to wrapper [WIP] ghc.withPackages: can add user arguments to wrapper Mar 26, 2019
@teto
Copy link
Member Author

teto commented Mar 26, 2019

@peti sry to ping you in peculiar not sure who is the current haskell maintainer. I wonder where/how one could pass postBuild/makeWrapperArgs in https://github.com/NixOS/nixpkgs/pull/58341/files#diff-290b63a2b3b2ea74530c5e12f9e17c4eR3 . does my approch look sensible ?

@peti
Copy link
Member

peti commented Mar 27, 2019

I am trying to debug a haskell library used by my program. Everytime I change this library, I need to relaunch the nix-shell of my haskell program to get an up to date ghc environment.
My idea is to wrap the GHC with an -i/local/lib/we/debug. Because the library I debug is also in NIX_GHC_LIBDIR, I wonder if I can prefix NIX_GHC_LIBDIR so that ghc picks the debug version over the one in the environment.

Honestly, I don't think that this makes much sense. First of all, you don't need to wrap ghc just to pass some -i flag. You can just pass those flags on the command-line or via stack or via cabal. There's really nothing to be gained by hard-coding the flag into the wrapper script.

Secondly, passing -i is probably not going to work. Instead, you'll have to have to mess with --hide-package and --package-db and flags like that to make the compiler prefer your library over the one found in the system tree.

Personally, I would simply run cabal get foo-1.2.3 and add a file cabal.project to the top-level of my project that says:

packages: .
          ./foo-1.2.3

Now, all commands like cabal new-build etc. will automatically prefer the local copy of foo in the build over the one that's part of ghc and edits you make in that local source tree have an immediate effect. I'm sure stack can do the same thing.

@teto
Copy link
Member Author

teto commented Mar 28, 2019

I've always only used nix since I always had problems with either stack or cabal. I've followed your advice and created this cabal.project file:

packages:
	./
	/home/teto/netlink-hs

then ran cabal new-build -v daemon

Preprocessing executable 'hsc2hs' for hsc2hs-0.68.4..
Building executable 'hsc2hs' for hsc2hs-0.68.4..
creating dist/build/hsc2hs
creating dist/build/hsc2hs/hsc2hs-tmp
/nix/store/vw0miqzi5jnf657g9ydd0qbz7sznd8b6-ghc-8.6.4-with-packages/bin/ghc --make -no-link -fbuilding-cabal-package -O -static -outputdir dist/build/hsc2hs/hsc2hs-tmp -odir dist/build/hsc2hs/hsc2hs-tmp -hidir dist/build/hsc2hs/hsc2hs-tmp -stubdir dist/build/hsc2hs/hsc2hs-tmp -i -idist/build/hsc2hs/hsc2hs-tmp -i. -idist/build/hsc2hs/autogen -idist/build/global-autogen -Idist/build/hsc2hs/autogen -Idist/build/global-autogen -Idist/build/hsc2hs/hsc2hs-tmp -optP-include -optPdist/build/hsc2hs/autogen/cabal_macros.h -hide-all-packages -Wmissing-home-modules -no-user-package-db -package-db /home/teto/.cabal/store/ghc-8.6.4/package.db -package-db dist/package.conf.inplace -package-id base-4.12.0.0 -package-id containers-0.6.0.1 -package-id directory-1.3.3.0 -package-id filepath-1.4.2.1 -package-id process-1.6.5.0 -XHaskell2010 C Common CrossCodegen DirectCodegen Flags HSCParser ATTParser UtilsCodegen Paths_hsc2hs ./Main.hs -hide-all-packages
[ 1 of 10] Compiling ATTParser        ( ATTParser.hs, dist/build/hsc2hs/hsc2hs-tmp/ATTParser.o )
[ 2 of 10] Compiling Common           ( Common.hs, dist/build/hsc2hs/hsc2hs-tmp/Common.o )
[ 3 of 10] Compiling Flags            ( Flags.hs, dist/build/hsc2hs/hsc2hs-tmp/Flags.o )
[ 4 of 10] Compiling HSCParser        ( HSCParser.hs, dist/build/hsc2hs/hsc2hs-tmp/HSCParser.o )
[ 5 of 10] Compiling C                ( C.hs, dist/build/hsc2hs/hsc2hs-tmp/C.o )
[ 6 of 10] Compiling CrossCodegen     ( CrossCodegen.hs, dist/build/hsc2hs/hsc2hs-tmp/CrossCodegen.o )
[ 7 of 10] Compiling Paths_hsc2hs     ( dist/build/hsc2hs/autogen/Paths_hsc2hs.hs, dist/build/hsc2hs/hsc2hs-tmp/Paths_hsc2hs.o )
[ 8 of 10] Compiling UtilsCodegen     ( UtilsCodegen.hs, dist/build/hsc2hs/hsc2hs-tmp/UtilsCodegen.o )
[ 9 of 10] Compiling DirectCodegen    ( DirectCodegen.hs, dist/build/hsc2hs/hsc2hs-tmp/DirectCodegen.o )
[10 of 10] Compiling Main             ( Main.hs, dist/build/hsc2hs/hsc2hs-tmp/Main.o )
Linking...
/nix/store/vw0miqzi5jnf657g9ydd0qbz7sznd8b6-ghc-8.6.4-with-packages/bin/ghc --make -fbuilding-cabal-package -O -static -outputdir dist/build/hsc2hs/hsc2hs-tmp -odir dist/build/hsc2hs/hsc2hs-tmp -hidir dist/build/hsc2hs/hsc2hs-tmp -stubdir dist/build/hsc2hs/hsc2hs-tmp -i -idist/build/hsc2hs/hsc2hs-tmp -i. -idist/build/hsc2hs/autogen -idist/build/global-autogen -Idist/build/hsc2hs/autogen -Idist/build/global-autogen -Idist/build/hsc2hs/hsc2hs-tmp -optP-include -optPdist/build/hsc2hs/autogen/cabal_macros.h -L -hide-all-packages -Wmissing-home-modules -no-user-package-db -package-db /home/teto/.cabal/store/ghc-8.6.4/package.db -package-db dist/package.conf.inplace -package-id base-4.12.0.0 -package-id containers-0.6.0.1 -package-id directory-1.3.3.0 -package-id filepath-1.4.2.1 -package-id process-1.6.5.0 -XHaskell2010 C Common CrossCodegen DirectCodegen Flags HSCParser ATTParser UtilsCodegen Paths_hsc2hs ./Main.hs -o dist/build/hsc2hs/hsc2hs -hide-all-packages
ghc: unrecognised flag: -L
did you mean one of:
  -L
  -D
  -F

Not sure why ghc doesn't recognize the -L flag; also I use https://github.com/haskell/haskell-ide-engine which doesn't support yet new-style so if you had an old-style recommandation, that would be great as well.

@teto
Copy link
Member Author

teto commented Mar 28, 2019

Right I think I am making progress little by little. Closing this.

@teto teto closed this Mar 28, 2019
@teto teto deleted the haskell/withPackages branch May 13, 2020 09:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants