-
Notifications
You must be signed in to change notification settings - Fork 11
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 with nix (and docker) #11
Conversation
If you want to merge and maintain that, it’s your call. I’m not going to take responsibility for anything nix related. |
Around 6 months ago, I built a static And I pushed the images here: https://hub.docker.com/r/psibi/pid1/tags And I just ran that docker image to confirm that it was indeed static:
|
@snoyberg haha yeah I can totally understand that! :D My thinking was that this "app" is mostly done and I don't see it needing to be updated all that often...like say a library released to hackage might. The dependencies are very minimal and unless there's a catastrophic bug in GHC that produces programs that eat your computer I doubt we have to update it at all. And this way everything is "cemented" forever. @psibi I don't know anything about https://github.com/fpco/alpine-haskell-stack .. this is the first time I'm hearing about it. It's not mentioned anywhere in this repo. I tried changing In summary...if https://github.com/fpco/alpine-haskell-stack is maintained we can switch to that by merging the changes linked above instead of the nix stuff in this PR. It's not perfect but if you're more comfortable in debugging that setup instead of nix that's fine by me of course. It could probably also be automated in a github action just fine. What do you guys think? |
I think I had to remove the upx step to make it work as the binary was segfaulting with it. Seems it was removing something extra. (Maybe I'm misremembering things)
I do think it is maintained. I think stack also uses it to build the static binary: https://github.com/commercialhaskell/stack/blob/69f55d401d8ef719d255b7876884899fbfcd546e/stack.yaml#L14
I'm fine with either of those things. But since you are the going to be maintaining it, I would leave the decision to you. :-) |
Hi Deni, it looks good to me. If you like, you can upgrade the LTS to a newer one, and use a newer static-haskell-nix version that uses GHC 8.10. That newer version needs less stuff built, so compiles should be faster. I made a PR into your branch here, in case you want to check it out: denibertovic#1 On maintenance: For a simple program like this, I think any approach will do that produces a static binary that people can use. If Docker currently doens't work and adding a nix build provides an easy solution without having to figure things out, that's good, and in case that in the future a Docker build becomes easier/faster again, that could take over again. |
static binary on lts-17
* Moves build script into makefile * Removes static-base (as it no longer builds and isn't used)
da7fff5
to
fa6b0e8
Compare
@nh2 those were my thoughts as well. That said I thought I could bring back the docker build stuff and update to use the newer maintained images (fpco/alpine-haskell-stack). I pushed the new changes that should streamline the process a bit. Basically:
[1] I also made sure to actually use the /home/build directory this time so that global .stack persist. Now the interesting bits. This worked fine with lts-14.27 and fpco/alpine-haskell-stack:8.6.5.
I have no idea why it would work with lts-14.27 and fpco/alpine-haskell-stack:8.6.5 and not with the latest version. :/ @snoyberg @psibi Perhaps some of you know how to fix this? (I didn't want to touch the .travis.yml file in this PR even though it doesn't work anymore since the project was not moved to the new travis site....but then again it didn't actually use any of the scripts used to release things so....) |
Sorry about the late reply. Finally at work, I had some requirements for working on pid1. I faced similar issue:
I fixed it like this: #12 I have also pushed newer docker image based on ubuntu 22.04 LTS. |
I don't really know how this compares to #1 but perhaps @nh2 and @dysinger can weigh in? All I know is that the existing
static-base/Dockerfile
didn't build for me anymore. Anyway, I've only tested this binary on debian and ubuntu so far. I haven't tested with alpine but I imagine it should work with every distro since it is a true static binary.I had to bump the LTS to get a newer compiler version because otherwise stack2nix complained. I used a version I have on some of my other projects just because it was convenient but other than that it was arbitrary.
To build it run
make static
. It will output the path to the binary at the end. Of course this will take a very long time unless you already have the build cache locally from some other projects (like I have)...or a remote builder etc. Then again this should not necessarily be ran locally but in CI (ideally using cachix and other types of caching). I'll see if I can find the time to make a github actions pipeline but I figured that can be a separate PR and doesn't have to wait for this. In any case this is what I used to make the latest release here: https://github.com/fpco/pid1/releases/tag/pid1-0.1.3.0