NixOS / nix.dev

Official documentation for getting things done with Nix.
https://nix.dev
Creative Commons Attribution Share Alike 4.0 International
2.56k stars 252 forks source link

Building docker images on macOS doesn't work #827

Open salamehsameera opened 11 months ago

salamehsameera commented 11 months ago

Hi I just want to point out that this part of the tutorial (link) doesn't work

Cross compile to Linux by replacing pkgsLinux.hello with pkgs.pkgsCross.musl64.hello

I was trying to run that script on macOS and it kept erroring out, probably better to suggest using a VM. I used Multipass https://multipass.run/ and it's very easy to use, so probably suggesting that is better. Thanks

fricklerhandwerk commented 11 months ago

Thanks for reporting. There is a highlight box saying

macOS/Darwin is a special case, as not the whole OS is open-source. It’s only possible to cross compile between aarch64-darwin and x86_64-darwin. aarch64-darwin support was recently added, so cross compilation is barely tested.

We should probably point that out more clearly.

The whole point of cross compilation (and much of Nix) is exactly that one doesn't need virtual machines, but that recent macOS work in fact allows using VMs transparently. @olafklingt I can imagine we could provide simple VM instructions for macOS, most of that is already in place, right?

salamehsameera commented 11 months ago

@fricklerhandwerk sorry I can't even find that part in the tutorial. Can you please screenshot it / point it out with a link?

olafklingt commented 11 months ago

@salamehsameera which architecture are you on? you can find the mentioned comment here Can you describe in detail what is not working? I am not on mac-os so i don't know the pitfalls yet.

fricklerhandwerk commented 11 months ago

@salamehsameera oh sorry, I made a mistake and looked at the linked article, as @olafklingt noted: https://nix.dev/tutorials/cross-compilation What I wanted to say is that the instruction to do cross compilation may not actually work, as the note on that other page suggests. Both pages were not actively maintained until you asked.

Please show what exactly you did (post the expressions you used and the commands you ran), otherwise we can't help figuring it out.

salamehsameera commented 10 months ago

I just updated the description to point out to the tutorial page I was referring to. It should be https://nix.dev/tutorials/nixos/building-and-running-docker-images.

I'm on mac, and the tutorial suggests to cross compile to linux: Screenshot 2023-12-21 at 12 54 50 PM

Here is a screenshot of the error when executing the code from the tutorial Screenshot 2023-12-21 at 12 56 34 PM

Full error is:

these 6 derivations will be built:
  /nix/store/26bcr8wfcx4lv09rjb9ivl1y420cfqm8-jshon-20170302.drv
  /nix/store/8nr28caac7chz1c31grj7czn59cw90z3-hello-x86_64-unknown-linux-musl-2.12.1.drv
  /nix/store/cfarcfgic55nf1g2ahaf0x2fmvys371a-hello-docker-config.json.drv
  /nix/store/86yi7zkjpcxp2syr17c64r6w6r9cczfb-docker-layer-hello-docker.drv
  /nix/store/x6mhgpvqgj8kp97la682yjx0b46p3rd1-runtime-deps.drv
  /nix/store/nlvyp9f3gbhavi0qqdnby8h9carxifsf-docker-image-hello-docker.tar.gz.drv
these 2 paths will be fetched (0.02 MiB download, 0.11 MiB unpacked):
  /nix/store/5pnq935mmp8b13sbnq99yvqvvv54j4gr-stdenv-darwin
  /nix/store/j5hdavfzx22avjg2d9zjk1c6ydscxcsa-x86_64-unknown-linux-musl-gcc-wrapper-12.3.0
warning: Ignoring setting 'auto-allocate-uids' because experimental feature 'auto-allocate-uids' is not enabled
warning: Ignoring setting 'impure-env' because experimental feature 'configurable-impure-env' is not enabled
building '/nix/store/26bcr8wfcx4lv09rjb9ivl1y420cfqm8-jshon-20170302.drv'...
copying path '/nix/store/j5hdavfzx22avjg2d9zjk1c6ydscxcsa-x86_64-unknown-linux-musl-gcc-wrapper-12.3.0' from 'https://cache.nixos.org'...
copying path '/nix/store/5pnq935mmp8b13sbnq99yvqvvv54j4gr-stdenv-darwin' from 'https://cache.nixos.org'...
unpacking sources
unpacking source archive /nix/store/6qrdq6xjpycpwjj39xxww6gzg9biqifl-source
source root is source
patching sources
applying patch /nix/store/65ychbjyrl6md08s2zskzfn7cgwl4bnn-96b4e9dbf578be7b31f29740b608aa7b34df3318.patch
patching file jshon.c
configuring
no configure script, doing nothing
building
build flags: SHELL=/nix/store/0ly5lpwanagc5qpmnqrw8aqxb4ivw7kf-bash-5.2-p15/bin/bash
clang -std=c99 -Wall -pedantic -Wextra -Werror    -c -o jshon.o jshon.c
jshon.c:189:25: error: a function declaration without a prototype is deprecated in all versions of C [-Werror,-Wstrict-prototypes]
json_t** stack_safe_peek()
                        ^
                         void
jshon.c:222:23: error: a function declaration without a prototype is deprecated in all versions of C [-Werror,-Wstrict-prototypes]
mapping* map_safe_peek()
                      ^
                       void
jshon.c:229:13: error: a function declaration without a prototype is deprecated in all versions of C [-Werror,-Wstrict-prototypes]
void MAPPUSH()
            ^
             void
jshon.c:251:13: error: a function declaration without a prototype is deprecated in all versions of C [-Werror,-Wstrict-prototypes]
void MAPNEXT()
            ^
             void
jshon.c:276:12: error: a function declaration without a prototype is deprecated in all versions of C [-Werror,-Wstrict-prototypes]
void MAPPOP()
           ^
            void
jshon.c:846:15: error: a function declaration without a prototype is deprecated in all versions of C [-Werror,-Wstrict-prototypes]
void debug_map()
              ^
               void
6 errors generated.
make: *** [<builtin>: jshon.o] Error 1
error: builder for '/nix/store/26bcr8wfcx4lv09rjb9ivl1y420cfqm8-jshon-20170302.drv' failed with exit code 2;
       last 10 log lines:
       > jshon.c:276:12: error: a function declaration without a prototype is deprecated in all versions of C [-Werror,-Wstrict-prototypes]
       > void MAPPOP()
       >            ^
       >             void
       > jshon.c:846:15: error: a function declaration without a prototype is deprecated in all versions of C [-Werror,-Wstrict-prototypes]
       > void debug_map()
       >               ^
       >                void
       > 6 errors generated.
       > make: *** [<builtin>: jshon.o] Error 1
       For full logs, run 'nix-store -l /nix/store/26bcr8wfcx4lv09rjb9ivl1y420cfqm8-jshon-20170302.drv'.
error: 1 dependencies of derivation '/nix/store/nlvyp9f3gbhavi0qqdnby8h9carxifsf-docker-image-hello-docker.tar.gz.drv' failed to build
karlhepler commented 5 months ago

I tried something similar, except with my own cross-compiled binary, and got exactly the same error. MacOS Sonoma 14.5 on Apple M2 Pro.

tysonzero commented 3 months ago

Same issue on MacOS Sonoma 14.4 with an Intel Core i9, both with and without using haskell.nix's projectCross.