Fil-C on Nix

Filnix wiki

mbrock/filnix

runtime/filc-glibc.nix

λpkgs, filc, libpizlo, sources?
pkgs
filc
libpizlo
sourcesdefault import../lib/sources.nix inherit pkgs;
let
9lib=
import../lib inherit pkgs;
used by filc-glibc
in

Memory-safe glibc compiled with Fil-C

15filc-glibc=
pkgs.stdenv.mkDerivation
16pname=
"filc-glibc"
17version=
"2.44"
18src=
"${sources.user-glibc-src}/projects/user-glibc-2.44"
19outputs=
"out"
20patches=

Honour LOCALE_ARCHIVE and NixOS' system archive, as Nixpkgs' glibc does; its 2.42 writes the same archive format as 2.44.

pkgs.path + "/pkgs/development/libraries/glibc/nix-locale-archive.patch"

nftw, scandirat and fts stopped the program on a raw openat syscall.

brk, sched_setattr and pidfd_spawn stopped the program; fail instead.

settimeofday(NULL, tz) stopped the program (systemd after switch-root).

32enableParallelBuilding=
true
34nativeBuildInputs=
with pkgs; gnumake lib.autoconf272 bison python3 binutils glibc.dev

aarch64 has no inotify_init syscall; upstream's inotify_init.c now calls zsys_inotify_init, so this x86_64 workaround is kept only to leave the staging build unchanged. Official uses upstream's wrapper.

46postPatch=
pkgs.lib.optionalStringsources.variant ≡ "staging" ∧ pkgs.stdenv.hostPlatform.isx86_64
# Add inotify_init to x86_64 syscalls.list so make-syscalls.sh generates
# a pizlonated wrapper using zsys_inotify_init instead of using the
# hand-written inotify_init.c which has INLINE_SYSCALL_CALL
echo 'inotify_init - inotify_init i: __inotify_init inotify_init' \
>> sysdeps/unix/sysv/linux/x86_64/syscalls.list
# Remove the .c file so syscalls.list takes precedence
rm -f sysdeps/unix/sysv/linux/inotify_init.c
60preConfigure=
# Fil-C compiler flags from build script
FILCXXFLAGS="-nostdlibinc -Wno-ignored-attributes -Wno-pointer-sign"
FILCFLAGS="$FILCXXFLAGS -yolo-assembler -Wno-unused-command-line-argument -Wno-macro-redefined"
export CC="${filc}/bin/clang $FILCFLAGS -isystem ${libpizlo}/include"
export CXX="${filc}/bin/clang++ $FILCXXFLAGS -isystem ${libpizlo}/include"
# glibc requires out-of-tree build
autoconf
cd ..
mkdir -p build
cd build
configureScript=$PWD/../$sourceRoot/configure
# Fil-C defaults to the host's /lib/locale, which Nix builds and NixOS
# do not have. Use this output, as upstream glibc does.
echo "complocaledir=$out/lib/locale" > configparms
# Set these in shell so $out actually expands
configureFlagsArray+=(
"libc_cv_slibdir=$out/lib"
)
85configureFlags=
"--disable-mathvec" "--disable-nscd" "--disable-werror" "--with-headers=${pkgs.linuxHeaders}/include"

Ship C.UTF-8, as Nixpkgs' glibc does. The localedef built here is a Fil-C program that cannot run yet, so use the build platform's, as Nixpkgs does when cross-compiling glibc. Its 2.42 writes the same locale file format; the definitions come from this source.

96postInstall=
mkdir -p $out/lib/locale
I18NPATH=../$sourceRoot/localedata \
${pkgs.lib.getBinpkgs.glibc}/bin/localedef \
--no-archive \
--alias-file=../$sourceRoot/intl/locale.alias \
-i ../$sourceRoot/localedata/locales/C \
-f ../$sourceRoot/localedata/charmaps/UTF-8 \
$out/lib/locale/C.utf8
107meta.description=
"Memory-safe glibc compiled with Fil-C"
uses lib