-
-
Notifications
You must be signed in to change notification settings - Fork 14.8k
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
Unexpected dependencies when building docker image #155924
Comments
You can use The library needs to reference e. g. GHC as you need all libraries the library when linking against the library and |
Thank you! If you don't mind, I would like to get a better understanding of why static linking is necessary. Using the following cabal file, the result doesn't depend on ghc, even though I don't use justStaticExecutables:
You mention that base is bundled with ghc, but here I'm able to link to base without incurring a dependency on ghc. I'm confused about why this situation changes when a library is added to the cabal file, and why static linking is the issue. |
All executables are statically linked against all their Haskell dependencies ( For libraries you can't copy everything necessary into the library, since then you'll run into issues with the same function being defined in multiple libraries (e. g. In nixpkgs, executables are always statically linked, so naturally a cabal package without a library won't propagate GHC. All |
That's a great explanation, and I could verify that deleting the library is the only necessary change to default.nix:
It makes me wonder if there's a way to not include the library to begin with. Libraries in cabal files are internal if they're named, but using the name "lib" in my example didn't prevent it from being included. Is that perhaps a bug in how Nix builds cabal projects? |
It appears so, I've filed NixOS/cabal2nix#539 for now. It does, however, not really matter in most cases that are of concern to us (pure executable packages need manual intervention anyways most of the time and the rest we ship is mostly libraries), so I don't think it's a particularly urgent issue. I'll close this issue, since everything described is working as intended/expected, but do feel free to ask further questions in this thread if you have any. |
I really think this issue should remain open, at least to help others know it's a problem. I'm dealing with this problem right now, and wouldn't have seen any of this if I didn't decide to look through closed issues as well as open. |
@torgeirsh I also found this issue re-appears if the library uses & imports any data files (by importing the cabal-generated |
That's good to know. Can you work around it in the same way, by deleting files in postFixup? |
I don't think so. Nix finds a reference to the library in the executable produced.
Right now, I think the only way to avoid this is not use the |
I have the following default.nix:
And test.cabal looks like this:
Then I use docker.nix to build a docker image:
The resulting docker image is almost 400 MB, and contains ghc, gcc, documentation, and so on. However, if I remove the library from the cabal file, the resulting docker image is only 14 MB, and doesn't contain anything superfluous. I guess that when the cabal file contains a library, it becomes part of the build result, and since a library isn't useful on its own, it depends on ghc? However, I don't want to make the library available, it's only for building the executable. How can I get a lean docker image without a build environment, while keeping the library structure of the cabal project?
The text was updated successfully, but these errors were encountered: