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

static binary on lts-17 #1

Merged

Conversation

nh2
Copy link

@nh2 nh2 commented Nov 16, 2021

Like fpco#11 but with upgraded LTS and newer static-haskell-nix, which requires less building.

@denibertovic denibertovic merged commit d8f20aa into denibertovic:deni/static-binary-nix Nov 18, 2021
@denibertovic
Copy link
Owner

Thanks @nh2 ! I assume this makes it faster and avoids recompiling a lof of stuff because it uses a newer nixpkgs which is available in cache.nixos.org, right?

Another quick question...what's a good way to get the path to the built binary programmatically? Or at least to the bin folder? I ask because I want to eventually automate the process of making a release tarball and uploading it to github.

@denibertovic
Copy link
Owner

FYI: I didn't measure it or anything but to me it doesn't seem the build goes any faster than before.

@nh2
Copy link
Author

nh2 commented Nov 19, 2021

@denibertovic

I assume this makes it faster and avoids recompiling a lof of stuff because it uses a newer nixpkgs which is available in cache.nixos.org, right?

Not because of the binary cache, but simply, but in the newer version of static-haskell-nix, I made that python doesn't have to be recompiled from scratch wtih musl (as ghc documentation is built with sphinx which is Python):

https://github.com/nh2/static-haskell-nix/blob/bd66b86b72cff4479e1c76d5916a853c38d09837/survey/default.nix#L813-L820

Another quick question...what's a good way to get the path to the built binary programmatically? Or at least to the bin folder?

The $(shell nix-build --no-link -A fullBuildScript) that you use in your make file is a nix-build invocation that prints out a nix store path, like /nix/store/46r5r40zwa2djrysnjlr5hhhq5yvkg59-pid1-0.1.3.0. So you can just append /bin/pid1 to that, e.g.:

echo $($(shell nix-build --no-link -A fullBuildScript))/bin/pid1

That gives: /nix/store/46r5r40zwa2djrysnjlr5hhhq5yvkg59-pid1-0.1.3.0/bin/pid1

@denibertovic
Copy link
Owner

@nh2 thanks... Yeah I guess I could to do something like this:

PATH_TO_BINARY=$(make static 2>&1 | tail -n 1)/bin/pid1

However I'm not sure how to deal with failure in this case. :/

@nh2
Copy link
Author

nh2 commented Nov 25, 2021

@denibertovic I don't follow, why would you want to do 2>&1? A main point of nix-build is that it prints to stdout only the built store path, so that you can cleanly script it, without having build message stderr output interleaved with the store path.

However I'm not sure how to deal with failure in this case

With "the usual" mechanics of POSIX shell to check error codes of programs, set -e -o pipefail (and re-doing so in subshells which forget this sensible setting) or whichever mechanism you want to use for control flow.

Or alternatively, if like me you think that shell scripting should never ever be used because nobody can write even shell oneliners without bugs correctly, use a sensible programming language of your choice (like Python) to invoke the nix-build, check its exit code, and only continue if it is good.

@denibertovic
Copy link
Owner

I don't follow, why would you want to do 2>&1? A main point of nix-build is that it prints to stdout only the built store path, so that you can cleanly script it, without having build message stderr output interleaved with the store path.

I was not aware of this...since I saw a bunch of output before the actual store path I figured it was also printed to stdout.

With "the usual" mechanics of POSIX shell to check error codes of programs, set -e -o pipefail (and re-doing so in subshells which forget this sensible setting) or whichever mechanism you want to use for control flow.

Or alternatively, if like me you think that shell scripting should never ever be used because nobody can write even shell oneliners without bugs correctly, use a sensible programming language of your choice (like Python) to invoke the nix-build, check its exit code, and only continue if it is good.

Yeah that makes sense. Makefile actually complicate things here a bit but I guess I can extract the relevant bits into a shell file (or alternative).

Thanks @nh2

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.

2 participants