Fil-C on Nix

Filnix wiki

mbrock/filnix

httpd/lib/builders.nix

λpkgs, ports, filcc

Memory-safe bash script wrapper

8bashScript=
λname
λdeps?, code?, src?, excludeShellChecks?, bashOptions?
depsdefault [ ]
codedefault null
srcdefault null
excludeShellChecksdefault [ ]
bashOptionsdefault "errexit" "nounset" "pipefail"
pkgs.writeShellApplication
22inherit
name excludeShellChecks bashOptions
23runtimeInputs=
24text=
if src ≢ null then builtins.readFilesrc else code
25derivationArgs=
26postBuild=
substituteInPlace $out/bin/${name} \
--replace-fail '${pkgs.runtimeShell}' '${ports.bash}/bin/bash'

Memory-safe C/C++ program builder

34filcProgram=
λname
λdeps?, code?, src?, lang?
depsdefault [ ]
codedefault null
srcdefault null
langdefault "c++"
let
43extension=
if lang ≡ "c++" then "cpp" else "c"
used by sourceFile
44compiler=
if lang ≡ "c++" then "clang++" else "clang"
45sourceFile=
if src ≢ null then src else pkgs.writeText"${name}.${extension}" code
uses extension
in
pkgs.stdenv.mkDerivation
49inherit
name
51nativeBuildInputs=
52buildInputs=
53unpackPhase=
"true"
55CFLAGS=
pkgs.lib.concatMapStringsSep" " dep: "-I${dep}/include" deps
57LDFLAGS=
pkgs.lib.concatMapStringsSep" " dep: "-L${dep}/lib" deps
59buildPhase=
${compiler} -o ${name} $src $CFLAGS $LDFLAGS -O2
63installPhase=
mkdir -p $out/bin
cp ${name} $out/bin/

Build CGI document root from attrset of scripts

70cgi-bin=
λscripts
pkgs.runCommand"cgi-bin" { }
mkdir -p $out
${pkgs.lib.concatStringsSep"\n" pkgs.lib.mapAttrsToListname: drv: '' ln -s ${drv}/bin/${name} $out/${name} '' scripts}

Build document root with both CGI scripts and static files

82www-root=
λscripts?, static?
scriptsdefault { }
staticdefault { }
pkgs.runCommand"www-root" { }
mkdir -p $out
${pkgs.lib.concatStringsSep"\n" pkgs.lib.mapAttrsToListname: drv: '' ln -s ${drv}/bin/${name} $out/${name} '' scripts}
${pkgs.lib.concatStringsSep"\n" pkgs.lib.mapAttrsToListname: file: '' ln -s ${file} $out/${name} '' static}