nix-pills icon indicating copy to clipboard operation
nix-pills copied to clipboard

pill 7.7 fails on Darwin

Open pasunboneleve opened this issue 7 years ago • 9 comments

7.7. Enough of nix-repl

Fails to build in OSX. Solution, inspired on #35:

with (import <nixpkgs> {});

let gcc = stdenv.cc;
in

derivation {
 name = "simple";
 builder = "${bash}/bin/bash";
 args = [ ./simple_builder.sh ];
 inherit gcc coreutils;
 src = ./simple.c;
 system = builtins.currentSystem;
}

pasunboneleve avatar Aug 20 '18 01:08 pasunboneleve

What is the output?

Mic92 avatar Aug 20 '18 09:08 Mic92

copying path '/nix/store/il6yvbnfqgh4gmrx3kxnr9ggsmk26zyq-mpfr-3.1.6' from 'https://cache.nixos.org'...
copying path '/nix/store/r24xdkvwi3mx4lyaxzi1r1cdadifndim-pcre-8.41' from 'https://cache.nixos.org'...
copying path '/nix/store/wf58m510x6g6ik42pxi0ddbwyh3vxilx-libmpc-1.1.0' from 'https://cache.nixos.org'...
copying path '/nix/store/c3sa761qjcaa5rg0s8h8qxj0mghkidv5-gnugrep-3.1' from 'https://cache.nixos.org'...
copying path '/nix/store/hx3siphz67qji0ag17hnnblywi3136z2-gcc-7.3.0' from 'https://cache.nixos.org'...
copying path '/nix/store/7j56b0vlaw1klmvscjz7sgkaplah7dyn-gcc-wrapper-7.3.0' from 'https://cache.nixos.org'...
building '/nix/store/d58dk1vq84c6xap1x3xgsa4bg7iyx1ax-simple.drv'...
/nix/store/9nld1c5cfjlq0af0s2758vczfky5bq0z-simple.c: In function 'main':
/nix/store/9nld1c5cfjlq0af0s2758vczfky5bq0z-simple.c:2:3: warning: implicit declaration of function 'puts' [-Wimplicit-function-declaration]
   puts("SIMPLE!");
   ^~~~
/nix/store/7j56b0vlaw1klmvscjz7sgkaplah7dyn-gcc-wrapper-7.3.0/bin/as: assembler (clang) not installed
builder for '/nix/store/d58dk1vq84c6xap1x3xgsa4bg7iyx1ax-simple.drv' failed with exit code 1
error: build of '/nix/store/d58dk1vq84c6xap1x3xgsa4bg7iyx1ax-simple.drv' failed

pasunboneleve avatar Aug 20 '18 12:08 pasunboneleve

I disagree with adding platform specific conditionals to the examples, they should be as straightforward as possible to avoid confusion. Adding a disclaimer that these are intentionally linux only and suggesting to use a docker container if they want to build the examples would be better IMHO.

eg. the stdenv has not been introduced at this point yet.

LnL7 avatar Aug 20 '18 17:08 LnL7

How about adding a second listing for macOS/clang?

Mic92 avatar Aug 20 '18 17:08 Mic92

Not sure, because the darwin stdenv has some impurities so I think it wouldn't be straightforward to make a proper example.

LnL7 avatar Aug 20 '18 17:08 LnL7

Wouldn’t using docker defeat the purpose of showing that Nix is a superior tool for this kind of job?

I want my software team at work to adopt Nix. If they needed Docker to do a simple “hello world”... That would make Nix redundant and further entrench their view that Docker is all they need.

-- Daniel Vianna

On 21 Aug 2018, at 3:53 am, Daiderd Jordan [email protected] wrote:

Not sure, because the darwin stdenv has some impurities so I think it wouldn't be straightforward to make a proper example.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.

pasunboneleve avatar Aug 20 '18 19:08 pasunboneleve

Next thing we'd have to do for hello is introduce darwin.cctools and there are probably more cases like that.

The purpose of these examples is to explain the essentials of what the stdenv is and why it exists, not a walkthrough of the implementation with all it's quirks. The actual implementation is pretty complex and only a few people fully understand it. A section or pill on some the differences between different platforms and how the stdenv generalises these (eg. gcc/clang => stdenv.cc) is something that would make sense. Since in that case it's the actual subject.

FYI. I'm one of the active darwin maintainers. I do very much care about compatibility in nixpkgs, however reinventing the wheel in a tutorial seems pointless and confusing to me.

LnL7 avatar Aug 21 '18 01:08 LnL7

same problem:

nix-repl> :b simple
builder for '/nix/store/xggwdhl9mw8acgjidcvgsvj5qdxm3jb5-simple.drv' failed with exit code 1; last 1 log lines:
  /nix/store/xs8x90rif8vp3ymhdyqpc66cx0l7s2c9-gcc-wrapper-7.3.0/bin/as: assembler (clang) not installed
[0 built (1 failed)]
error: build of '/nix/store/xggwdhl9mw8acgjidcvgsvj5qdxm3jb5-simple.drv' failed

cmal avatar Nov 15 '18 05:11 cmal

An alternative would be to replace the current example with one that works equally well on both platforms. E.g., this OCaml equivalent:

simple.ml

print_string "Hello world!\n"

simpler_builder.sh

export PATH="$coreutils/bin:$ocaml/bin"
mkdir $out
ocamlc -o $out/simple $src

and the derivation

nix-repl> simple = derivation { name = "simple"; builder = "${bash}/bin/bash"; args = [ ./simple_builder.sh ]; ocaml = ocaml; coreutils = coreutils; src = ./simple.ml; system = builtins.currentSystem; }

This builds fine on my mac, and I expect it should do the same on linux.

shonfeder-da avatar Jan 06 '19 01:01 shonfeder-da