Fil-C on Nix

Filnix wiki

mbrock/filnix

runtime/yolo-glibc.nix

λpkgs, sources?
pkgs
sourcesdefault import../lib/sources.nix inherit pkgs;
let
7lib=
import../lib inherit pkgs;
8inherit lib
setupCcache
in
rec

This just builds the Fil-C glibc yolo fork with the normal host GCC toolchain.

13yolo-glibc-impl=
pkgs.stdenv.mkDerivation
rec
14pname=
"yolo-glibc-impl"
15version=
"2.44"
16src=
"${sources.yolo-glibc-src}/projects/yolo-glibc-${version}"

Use single output (glibc tries to split into multiple outputs by default)

19outputs=
"out"
21enableParallelBuilding=
true
23nativeBuildInputs=
with pkgs; python3 git file patchelf gnumake pkg-config lib.autoconf272 bison gcc-unwrapped binutils-unwrapped ccache
37preConfigure=
export NIX_CFLAGS_COMPILE=""
export NIX_LDFLAGS=""
# Set up ccache manually
export CC="ccache gcc"
export CXX="ccache g++"
# glibc requires out-of-tree build
autoconf
cd ..
mkdir -p build
cd build
configureScript=$PWD/../$sourceRoot/configure
# Set these in shell so $out actually expands
configureFlagsArray+=(
"libc_cv_slibdir=$out/lib"
)
59configureFlags=
"--disable-mathvec" "--disable-nscd" "--disable-werror" "--with-headers=${pkgs.linuxHeaders}/include"

Rename yolo-glibc components so they don't conflict with normal glibc

68yolo-glibc=
pkgs.runCommand"yolo-glibc" nativeBuildInputs = pkgs.patchelf;
mkdir -p $out/lib
cd $out/lib
# Copy all .o files
cp ${yolo-glibc-impl}/lib/*.o .
# Copy and rename static libs
cp ${yolo-glibc-impl}/lib/libc.a libyoloc.a
cp ${yolo-glibc-impl}/lib/libc_nonshared.a libyoloc_nonshared.a
cp ${yolo-glibc-impl}/lib/libm.a libyolom.a
cp ${yolo-glibc-impl}/lib/*.a . # Copy other .a files as-is
chmod -R u+w .
# Fil-C's glibc names its loader ld-fil1-x86_64.so itself. Patching
# the loader with patchelf misbehaves with some older kernels.
cp ${yolo-glibc-impl}/lib/${lib.dynamicLinker} .
# Copy and patch libc implementation
cp ${yolo-glibc-impl}/lib/libc.so.6 libyolocimpl.so
chmod u+w libyolocimpl.so
patchelf --set-soname libyolocimpl.so \
--set-rpath '$ORIGIN' \
libyolocimpl.so
# Copy and patch libm implementation
cp ${yolo-glibc-impl}/lib/libm.so.6 libyolomimpl.so
chmod u+w libyolomimpl.so
patchelf --set-soname libyolomimpl.so \
--replace-needed libc.so.6 libyolocimpl.so \
--set-rpath '$ORIGIN' \
libyolomimpl.so
# Create linker scripts
cat > libyolom.so <<'EOF'
OUTPUT_FORMAT(${lib.elfFormat})
GROUP(libyolomimpl.so)
EOF
cat > libyoloc.so <<'EOF'
OUTPUT_FORMAT(${lib.elfFormat})
GROUP(libyolocimpl.so libyoloc_nonshared.a AS_NEEDED(${lib.dynamicLinker}))
EOF