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

Fails to link against tinfo (ncurses5) #14

Closed
nomeata opened this issue Mar 7, 2019 · 8 comments
Closed

Fails to link against tinfo (ncurses5) #14

nomeata opened this issue Mar 7, 2019 · 8 comments

Comments

@nomeata
Copy link

nomeata commented Mar 7, 2019

I am trying to build https://travis-ci.org/entropia/tip-toi-reveng/ statically using these instructions, and I made good progress by pinning nixpkgs to version NixOS/nixpkgs@2c07921 (which is the one mentioned in the README) and then buliding pkgs.pkgsMusl.haskell.packages.ghc843.tttool.

And indeed, as long as I stub out uses of TemplateHaskell in my program (it it expected that this is needed?), it builds… almost: It fails linking

Linking dist/build/tttool/tttool ...
/nix/store/3a74d03pq6d0cg3crkfw965k5s58hbn4-binutils-2.30/bin/ld: cannot find -ltinfo
collect2: error: ld returned 1 exit status
`cc' failed in phase `Linker'. (Exit code: 1)
builder for '/nix/store/4z8hp5bslaxlgasq69k4njxl2z1hnwz2-tttool-1.8.1.drv' failed with exit code 1
error: build of '/nix/store/4z8hp5bslaxlgasq69k4njxl2z1hnwz2-tttool-1.8.1.drv' failed

Blindly cargo-culting the example scotty app, I tried adding the following to my project.nix

  configureFlags = pkgs.lib.optional static [
     "--ghc-option=-optl=-static"
     "--extra-lib-dirs=${pkgs.gmp6.override { withStatic = true; }}/lib"
     "--extra-lib-dirs=${pkgs.zlib.static}/lib"
     "--extra-lib-dirs=${pkgs.ncurses5.override { enableStatic = true; }}/lib"
  ];

but it did not make a difference (and there was already a --extra-lib-dirs=/nix/store/1xwbnc903gymfi99zpvj8mdp5601yqz6-ncurses-6.1/lib commde line argument passed automatically somehow).

Is it maybe dubious that https://github.com/NixOS/nixpkgs/blob/2c07921cff84dfb0b9e0f6c2d10ee2bfee6a85ac/pkgs/development/libraries/ncurses/default.nix starts with

, enableStatic ? stdenv.hostPlatform.useAndroidPrebuilt
nomeata added a commit to entropia/tip-toi-reveng that referenced this issue Mar 7, 2019
`nix/static` is a plain `nixpkgs` setup, and almost builds a static
version of the binary, if it were not for
nh2/static-haskell-nix#14

`nix/` is using the tooling at https://github.com/input-output-hk/iohk-nix
as advised by @angerman, but it currenty fails to download or build
`/nix/store/j6m77ilz08bsdhs8cba9i0mhs4lw0vak-ghc-8.4.4.drv` because some
patches do not apply. Or something.
@nomeata
Copy link
Author

nomeata commented Mar 8, 2019

A work-around is to compile the haskeline package with -f-readline; I am not sure which features are lost this way.

nomeata added a commit to entropia/tip-toi-reveng that referenced this issue Mar 8, 2019
requires a patched `haskell.nix` due to
input-output-hk/haskell.nix#86
and disabled `terminfo` support in `haskelline` due to
nh2/static-haskell-nix#14

But it seems to work!
nh2 added a commit that referenced this issue Mar 22, 2019
@nh2
Copy link
Owner

nh2 commented Mar 22, 2019

Check out commit 76d2cd3. All that was needed was

tttool = self.callCabal2nix "tttool" (pkgs.fetchFromGitHub {
owner = "entropia";
repo = "tip-toi-reveng";
rev = "f83977f1bc117f8738055b978e3cfe566b433483";
sha256 = "05bbn63sn18s6c7gpcmzbv4hyfhn1i9bd2bw76bv6abr58lnrwk3";
}) {};

I could then build it with

NIX_PATH=nixpkgs=https://github.com/NixOS/nixpkgs/archive/88ae8f7d.tar.gz nix-build --no-link survey/default.nix -A haskellPackages.tttool

Since I have commited this, you can now build it the same way, and I have also uploaded it to the cachix.

(If you add tttool to Stackage, you will get that for free without an entry as I have committed now.)

For clarity, it is also possible to do this without adding code to static-haskell-nix, by importing it instead; example:

# In `survey` we provide a nixpkgs set with some fixes; import it here.
pkgs = (import ../survey/default.nix {
inherit normalPkgs;
overlays = [ pyopenssl-fix-test-buffer-size-overlay ];
}).pkgs;

@nh2
Copy link
Owner

nh2 commented Mar 22, 2019

I've also uploaded the static result: https://github.com/nh2/static-haskell-nix/releases/tag/tttool-static

7.7 MB uncompressed.

@nh2
Copy link
Owner

nh2 commented Mar 22, 2019

In other words, because you use pkgs.pkgsMusl instead of my overridden haskellPackages, you likely don't have any of my fixes to build stuff statically, including the one for tinfo.

@nomeata
Copy link
Author

nomeata commented Mar 22, 2019

Thanks for the fix and explanation!

I also managed to build it statically using haskell.nix, and since that also gives me windows builds, I will probably use that for now. But using plain nixpks eventually (with your work) would be nice!

@srid
Copy link

srid commented Sep 29, 2020

@nomeata Can plain nixpkgs not give Windows builds? Must one switch to haskell.nix for that?

@nomeata
Copy link
Author

nomeata commented Sep 29, 2020

Haven't tried recently, back then they had a fair amount of patches for cross compilation onto Windows that were not in upstream nixpkgs yet.

@nh2
Copy link
Owner

nh2 commented Jul 23, 2021

I believe that all tinfo / ncurses issues should be fixed with PR #98.

@nh2 nh2 closed this as completed Jul 23, 2021
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

No branches or pull requests

3 participants