Fil-C on Nix

Filnix wiki

mbrock/filnix

lib/filc-system.nix

The Fil-C system: a NixOS or finix machine whose pkgs is filnix's Fil-C package set. NixOS and finix modules pick their programs from pkgs, so systemd or finit, PAM, D-Bus, OpenSSH and every service are Fil-C builds without being named here. The kernel, the bootloader and the other packages in lib/native-exceptions.nix come from native Nixpkgs, and so do the ones you add:

imports=
filnix.nixosModules.default
or finixModules.default
filc.enable=
true
filc.native=
native: inherit native tailscale;

nixos/default.nix and finix/default.nix import this with their os and add what differs between the two.

λfilnix, os
λconfig, lib, options, pkgs, …
let
24inherit lib
mkEnableOption mkIf mkOption types
30exceptions=
lib.filterAttrsname: e: lib.elemos e.os ∧ name ≢ "nix" ∨ cfg.nativeNix import./native-exceptions.nix
uses cfg used by config nativeRoots
33nativePkgs=
cfg.nativePackages ≢ null
→
cfg.nativePackages
else
filnix.lib.${cfg.system}.nativePackages

The user's exceptions, as given to the package set.

39userNative=

Every node that sets nothing shares one package set: each one made here is a fresh Nixpkgs import.

42shared=
options.filc.native.highestPrio ≥ 1500 ∧ cfg.nativePackages ≡ null ∧ cfg.nativeNix
uses cfg used by config

The store paths of the native exceptions. filc-ps allows a native process whose program is in one's closure. Without string context, so an exception the system does not use is not pulled into it.

50nativeRoots=
lib.concatMapv: lib.optionalslib.isDerivationv mapo: builtins.unsafeDiscardStringContextv.${o}.outPath v.outputs or "out" mapn: nativePkgs.${n} lib.attrNamesexceptions ++ lib.attrValuesuserNative
65filc-ps=
pkgs.writeShellScriptBin"filc-ps"
PATH=${lib.makeBinPathpkgs.coreutils pkgs.gnugrep pkgs.nix}:$PATH
roots=(${lib.escapeShellArgsnativeRoots})
${builtins.readFile./filc-ps.sh}
uses nativeRoots used by config
in

Its definitions are this file's, not those of the module importing it.

81options.filc=
82enable=
mkEnableOption"the Fil-C system: `pkgs` is filnix's Fil-C package set"
options filc.enable

Not read from nixpkgs.*: this module sets nixpkgs.pkgs, which makes those options unreadable.

86system=
87type=
types.enum"aarch64-linux" "x86_64-linux"
91default=
"x86_64-linux"
92description=

The system to build for.

options filc.system
95native=
96type=
types.functionTotypes.attrsOftypes.raw
97default=
_: { }
98defaultText=
lib.literalExpression ‹native: { }›
99example=
lib.literalExpression ‹native: inherit native tailscale ripgrep;›
100description=

Packages to take from the native package set instead of building them with Fil-C, as a function of that set. Use it for Rust and Go programs you want anyway, and for C programs that do not work yet. Each one runs as an ordinary native process with native libraries. A name the native set does not have fails evaluation. The packages in filnix's lib/native-exceptions.nix are always native.

options filc.native
110nativePackages=
111type=
types.nullOrtypes.raw
112default=
null
113defaultText=
lib.literalExpression ‹importfilnix.inputs.nixpkgs inherit config.filc system;›
114example=
lib.literalExpression ‹importnixpkgs system = "x86_64-linux";›
115description=

The native package set that the exceptions come from. By default, filnix's own Nixpkgs, imported natively. Your usual Nixpkgs works too and gets its binary cache hits.

122nativeNix=
123type=
types.bool
124default=
true
125description=

Whether Nix itself (the daemon and CLI) is the native build. The Fil-C build works but cannot sandbox builds, having no namespaces or seccomp; with this off, the build sandbox is turned off too.

132packages=
133type=
types.raw
134readOnly=
true
135description=

The resulting package set, which is also pkgs.

options filc.packages
139config=
cfg.enable
→
140filc.packages=
→
filnix.legacyPackages.${cfg.system}.pkgsFilcSystem.${os}
else
filnix.lib.${cfg.system}.mkPkgsFilcSystem
145inherit
os
146inherit cfg
native nativeNix
147nativePackages=
150nixpkgs.pkgs=
cfg.packages
152assertions=
map
λname
154assertion=
155message=
"filc: the native package set has no ${name}, a built-in native exception (lib/native-exceptions.nix). Was it renamed in Nixpkgs?"
lib.attrNamesexceptions
++

An inherit (native) x with a typo is lazy; forcing each value stops evaluation at the missing attribute.

161assertion=
lib.allv: builtins.seqv true lib.attrValuesuserNative
162message=
"filc.native: every value must evaluate."
166environment.systemPackages=