Skip to content

Instantly share code, notes, and snippets.

View fzakaria's full-sized avatar

Farid Zakaria fzakaria

View GitHub Profile
@fzakaria
fzakaria / nixpkgs-pins.py
Last active August 31, 2026 22:05
Every nixpkgs revision the Nix flake ecosystem pins, joined against every published channel bump
#!/usr/bin/env nix
#! nix shell nixpkgs#python3 --command python3
"""Every nixpkgs revision the flake ecosystem pins, and which channel it was.
Reads `pins.jsonl` from a checkout of https://github.com/fzakaria/omniflake --
one row per indexed flake, carrying the nixpkgs its lock file names -- joins it
against every channel bump the nix release archive ever published, and writes
nixpkgs-pins.csv.
git clone https://github.com/fzakaria/omniflake
@fzakaria
fzakaria / README.md
Created August 20, 2026 18:24
SQLite compiled to WebAssembly, running inside the Nix evaluator via builtins.wasm — arbitrary SQL against a database read through Nix host functions

SQLite inside the Nix evaluator, via builtins.wasm

A real SQLite, compiled to WebAssembly, running inside Nix evaluation and answering arbitrary SQL against a database it never opens as a file.

# query.nix
builtins.wasm { path = ./sqlite_nix.wasm; } {
  db  = ./index.db;
  sql = "SELECT version, rev FROM versions
#!/usr/bin/env nix-shell
#! nix-shell -i python3 --pure
#! nix-shell -p "python3.withPackages(ps: with ps; [ plotnine pandas numpy scipy ])"
#! nix-shell -I nixpkgs=https://github.com/NixOS/nixpkgs/archive/72841a4a8761d1aed92ef6169a636872c986c76d.tar.gz
"""
Generate the figures for the "look at your data" post.
Self-contained: the shebang above pins nixpkgs to an exact commit and pulls in
plotnine + friends, so `./latency_charts.py` reproduces every figure on any
machine with Nix installed -- no virtualenv, no pip, no system packages.
// SPDX-License-Identifier: GPL-2.0
/*
* shebang_origin.bpf.c - $ORIGIN-relative shebang (#!) interpreter resolution.
*
* A binfmt_misc_ops handler for scripts whose interpreter line is
* "#!$ORIGIN/...": the interpreter is resolved relative to the directory of
* the script and selected via bpf_binprm_set_interp(). Ordinary scripts are
* declined so binfmt_script handles them.
*
* The whole shebang line is in the prefetched bprm->buf, so no file read is
@fzakaria
fzakaria / flake.nix
Created July 12, 2026 03:48
flake.nix to test Linux kernel with selftests and additional eBPF testing
{
description = "Linux Kernel Development Environment";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-25.11";
};
outputs = {
self,
nixpkgs,
@fzakaria
fzakaria / qemu_aarch64_filter.bpf.c
Created July 4, 2026 21:04
eBPF binfmt qemu aarch64 example
// SPDX-License-Identifier: GPL-2.0
/*
* binfmt_misc 'B' (BPF) program: match aarch64 ELF binaries and choose the
* interpreter (qemu-aarch64) dynamically via bpf_binprm_set_interp().
*
* The program is given the BINPRM_BUF_SIZE file header as context. It inspects
* the ELF header and, on a match, sets the interpreter and returns 1. This
* makes the handler a superset of a traditional magic rule: the program both
* decides the match and computes the interpreter path (it could equally derive
* a path relative to the binary).
@fzakaria
fzakaria / build.go
Last active June 21, 2026 19:59
Nix build in under 100 lines
package main
import (
"encoding/json"
"fmt"
"os"
"os/exec"
"strings"
)
@fzakaria
fzakaria / README.md
Created June 8, 2026 15:12
Cache-aware struct benchmarks: pointer-chasing staircase & AoS vs SoA

Cache-Aware Struct Benchmarks

Benchmarks demonstrating how struct size and memory layout affect performance due to CPU cache behavior. Companion code for the blog post Every byte matters.

Benchmarks

1. Pointer-Chasing (cache staircase)

@fzakaria
fzakaria / def.bzl
Created June 12, 2025 23:40
Compile jar to source jar mapping
ClassPathInfo = provider(
"Provider for classpath information",
fields = {
"compile_jars": "A json fragment containing the mapping of the current jar to its source jar",
},
)
def _classpath_aspect_impl(target, ctx):
java_info = target[JavaInfo]
compile_jars = depset(
@fzakaria
fzakaria / flatbuffer.bzl
Created May 19, 2025 21:38
Creating Java libraries for flatbuffers with flatc
"""
FlatBuffer Java rule for Bazel
"""
FlatbufferInfo = provider(
doc = "A provider for FlatBuffer schema files.",
fields = {
"fbs_files": "The list of fbs files that were used as inputs",
},
)