Hi, i would like to crosscompile complex C++ applications to statically linked apps on top of musl.
One specialty of these apps is that they must be compiled with newer versions of clang (this is a requirement that i would like to get rid of, but unfortunately can’t).
Let’s have a look at the minimal example that triggers this behavior:
- Create a mini derivation with a hello-world C++ app
- create an overlay that results in the availability of
pkgs.hello-app
- obtain nixpkgs from current master branch (before anyone asks: 20.09 also doesnt work)
- build the app
let
mainCpp = builtins.toFile "main.cpp" ''
#include <iostream>
int main() { std::cout << "hello\n"; }
'';
deriv = { clang_11, overrideCC, clangStdenv }:
# this already does not work. refering to as error type A
#clangStdenv.mkDerivation {
# this is what i finally want to to. refering to this error as type B
(overrideCC clangStdenv clang_11).mkDerivation {
name = "hello-app";
src = mainCpp;
unpackPhase = ":";
buildPhase = "c++ $src -o hello";
installPhase = "mkdir -p $out/bin && install -m755 hello $out/bin/hello";
};
overlay = self: super: {
hello-app = self.callPackage deriv {};
};
nixpkgs = builtins.fetchTarball {
url = "https://github.com/nixos/nixpkgs/archive/f217c0ea7c148ddc0103347051555c7c252dcafb.tar.gz";
sha256 = "0cyksxg2lnzxd0pss09rmmk2c2axz0lf9wvgvfng59nwf8dpq2kf";
};
pkgs = import nixpkgs {
overlays = [ overlay ];
};
in
# works:
#pkgs.hello-app
# the following both attributes do not work:
# type B error
# error: attribute 'llvmPackages_11' missing, at /nix/store/pl5nzbz7s187b7x2scj27b4wpkm1g93h-source/pkgs/top-level/all-packages.nix:10374:27
#pkgs.pkgsCross.musl64.hello-app
pkgs.pkgsCross.musl64.pkgsStatic.hello-app
The code contains comments with the error messages. For clarity they are repeated in the following:
for pkgs.pkgsCross.musl64.pkgsStatic.hello-app
in combination with the clang11 clangStdenv i get error type B:
$ nix-build
error: attribute 'llvmPackages_11' missing, at /nix/store/pl5nzbz7s187b7x2scj27b4wpkm1g93h-source/pkgs/top-level/all-packages.nix:10374:27
(use '--show-trace' to show detailed location information)
for pkgs.pkgsCross.musl64.pkgsStatic.hello-app
in combination with the cdefault clangStdenv i get error type A:
$ nix-build
these derivations will be built:
/nix/store/2vi59br2ximhirad1ccg88lbvrplpgd0-hello-app-x86_64-unknown-linux-musl.drv
building '/nix/store/2vi59br2ximhirad1ccg88lbvrplpgd0-hello-app-x86_64-unknown-linux-musl.drv'...
unpacking sources
patching sources
updateAutotoolsGnuConfigScriptsPhase
configuring
no configure script, doing nothing
building
/nix/store/k29y87fvip8g0wvh6azg164m4xpghjjq-stdenv-linux/setup: line 1308: c++: command not found
builder for '/nix/store/2vi59br2ximhirad1ccg88lbvrplpgd0-hello-app-x86_64-unknown-linux-musl.drv' failed with exit code 127
error: build of '/nix/store/2vi59br2ximhirad1ccg88lbvrplpgd0-hello-app-x86_64-unknown-linux-musl.drv' failed
What is wrong here? I would expect that this just works, or did i do anything wrong?