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

pkgs/haskellPackages: add nativeBuildInputs to shell env #28033

Closed

Conversation

Profpatsch
Copy link
Member

When in an env, the user normally wants to do a manual (incremental) build,
build tools are needed.

When in an env, the user normally wants to do a manual (incremental) build,
build tools are needed.
@Profpatsch Profpatsch requested a review from peti August 8, 2017 06:48
@mention-bot
Copy link

@Profpatsch, thanks for your PR! By analyzing the history of the files in this pull request, we identified @peti, @cstrahan and @shlevy to be potential reviewers.

Copy link
Member

@peti peti left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not in favor of this change.

@@ -349,7 +349,7 @@ stdenv.mkDerivation ({

env = stdenv.mkDerivation {
name = "interactive-${pname}-${version}-environment";
nativeBuildInputs = [ ghcEnv systemBuildInputs ]
nativeBuildInputs = [ ghcEnv systemBuildInputs nativeBuildInputs ]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left them out on purpose because Cabal needs to know the proper search paths for those libraries to bake those into the Cabal files. Without that information, configured builds won't work outside of a nix-shell environment.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don’t quite follow. I personally use a generated shell.nix like:

((import <nixpkgs> {}).haskellPackages.override {
  overrides = self: super: {
        my-pkg = let
          buildDepends = with self; [
            ansi-wl-pprint
            trifecta
          ];
          in super.mkDerivation {
            pname = "pkg-env";
            src = "/dev/null";
            version = "none";
            license = "none";
            inherit buildDepends;
            buildTools = with self; [
              ghcid
              cabal-install
              hpack
              (hoogleLocal {
                packages = buildDepends;
              })
            ];
          };
      };
}).my-pkg

for my projects, where buildTools are the tools needed to build the package in the env.
Why wouldn’t a configured package work outside the shell environment as long as the paths are absolute?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nix-shell configures gcc-wrapper magic to find those libraries without an explicit search path. Therefore, the build setup is broken once you leave that shell environment. When you pass --extra-{include,lib}-dir, however, then the configured build works fine inside and outside of the nix-shell environment.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pass --extra-{include,lib}-dir, however

What should I pass this to?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can't pass it anywhere. The best we can do is to create a convenient macro / alias / shell function that users of the environment can use to refer to those flags when invoking stack or cabal or tinc or whatever it is they are invoking.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my opinion these workarounds are required because of the flawed requirement that everything has to work outside of a nix shell after it is configured.
Naturally this breaks most workflows from the get-go.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The requirement that builds work outside of nix-shell is essential for everyone who uses long-running IDEs, like Emacs, to develop multiple projects with different kinds of environments without qutting and re-starting the IDE every time.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

like Emacs

I managed to configure my Emacs in a way that it uses the shell environment of the current project for Haskell projects, so I don’t experience that problem.

@3noch
Copy link
Contributor

3noch commented Sep 18, 2017

Progress on this?

@Profpatsch
Copy link
Member Author

Profpatsch commented Sep 19, 2017

I am using this patch locally, it is up to @peti whether we merge it or find some other solution.

$ git apply <(curl https://github.com/NixOS/nixpkgs/pull/28033.patch)

@peti
Copy link
Member

peti commented Sep 27, 2017

Sorry.

@peti peti closed this Sep 27, 2017
@oxij
Copy link
Member

oxij commented Sep 27, 2017 via email

@Profpatsch
Copy link
Member Author

Wait. Are you saying that if I cabal configure in nix-shell I would
get something that is uncabal buildable outside of nix-shell?

peti keeps cabal build working even outside of nix-shell. This patch here would have (probably) changed that.

@ttuegel
Copy link
Member

ttuegel commented Dec 19, 2017

@peti
I don't understand how to configure Cabal to find foreign dependencies in Nix. Other people are probably also lost, since I'm a Cabal maintainer and I can't figure it out. Could you give an example of how to configure a project with foreign dependencies?

@Profpatsch
Copy link
Member Author

Profpatsch commented Dec 19, 2017

I’m still using the non-merged patched of this PR locally in my projects, which just works for my use case (local projects with custom ghc & hoogle databases and tools like cabal or ghcid).

@ttuegel
Copy link
Member

ttuegel commented Dec 19, 2017

I’m still using the non-merged patched of this PR locally in my projects, which just works for my use case (local projects with custom ghc & hoogle databases and tools like cabal or ghcid).

I'm solving a related-but-different issue in #32821; I'm trying to get foreign libraries into the environment instead of build tools. I didn't add any new dependencies, I just moved systemBuildInputs from nativeBuildInputs to buildInputs. It's not even correct to have them in nativeBuildInputs anyway, because they won't be usable on the build machine if you are cross compiling!

@peti
Copy link
Member

peti commented Dec 21, 2017

@ttuegel,

I don't understand how to configure Cabal to find foreign dependencies in Nix.

you'll find plenty of examples at https://github.com/basvandijk/nix-workshop/blob/master/03-finding-system-libraries/run.sh. Unfortunately, the talk that went with that repo wasn't recorded (as I hoped it would be), so the material is a little terse. Given your background, however, I'm confident that you'll be able to follow the examples just fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants