Skip to content

Instantly share code, notes, and snippets.

View nh2's full-sized avatar

Niklas Hambüchen nh2

View GitHub Profile
# This `firefox-vm.nix` builds a simple NixOS VM with XFCE and Firefox inside.
# Build and run it with:
# nix-build '<nixpkgs/nixos>' -A vm -I nixos-config=./firefox-vm.nix
# result/bin/run-nixos-vm
# Log in as "root" with empty password.
# To delete the VM state (storage):
nh2 /
Last active May 22, 2024 07:07
Rigidly (+scale) aligns two point clouds with know point-to-point correspondences, in Python with numpy
import numpy as np
import numpy.linalg
# Relevant links:
# - (solution with scale)
# - "Least-Squares Rigid Motion Using SVD" (no scale but easy proofs and explains how weights could be added)
# Rigidly (+scale) aligns two point clouds with know point-to-point correspondences
# with least-squares error.
nh2 / ceph-benaco.nix
Created January 19, 2024 18:33
Open-sourcing Benaco's NixOS Ceph service module
{ config, lib, pkgs, ... }:
with lib;
cfg =;
inherit (pkgs.callPackage ../helpers.nix {}) ensureUnitExists;
nh2 /
Last active May 14, 2024 11:42
Understanding TCP_NODELAY

I believe the following is the best way to work with Nagle's algorithm / TCP_NODELAY / TCP_CORK.

It is described in this RedHat manual and the verdict is:

  • Set TCP_NODELAY = 1, always.
  • If you can batch data for sending by creating a buffer manually, or using writev(), prefer that.
  • If you cannot (e.g. "when using different libraries that provides abstractions for layers" from the above manual):
    • Set TCP_CORK = 1, then write the data, then set TCP_CORK = 0.
  • This builds a packet in kernel space and then flushes it out.
nh2 / gadt-equality.hs
Last active April 4, 2024 14:59
Shows how to implement an `instance Eq` for a GADT wrapped in an existential type, in Haskell.
-- Shows how to implement an `instance Eq` for a GADT wrapped in an existential type.
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE ExistentialQuantification #-}
{-# LANGUAGE TypeOperators #-}
import Data.Type.Equality
-- | A GADT. The example would also work if it had more than 1 type parameter.
nh2 / nixos-rootfs.nix
Last active March 27, 2024 14:34
Example of how to build a NixOS root file system
# Build with:
# NIX_PATH=nixpkgs=$HOME/src/nixpkgs nix-build --no-link '<nixpkgs/nixos>' -A -I nixos-config=thisfile.nix
# You can also use
# -A
# to build something you can browse locally (that uses symlinks into your nix store).
{config, pkgs, ...}:
# We need no bootloader, because the Chromebook can't use that anyway.
boot.loader.grub.enable = false;
nh2 / gist:9e16ce512bd082075e4dcd86115b21bb
Created March 10, 2024 18:48
"fastboot getvar all" on submerged, repaired Google Pixel 4a that had stock Android on it
(bootloader) product:sunfish
(bootloader) serialno:17191JEC203691
(bootloader) variant:SM7 UFS
(bootloader) max-download-size:0x10000000
(bootloader) slot-suffixes:_a,_b
(bootloader) version-bootloader:s5-0.5-10252351
(bootloader) version-baseband:g7150-00112-230505-B-10075601
(bootloader) secure-boot:PRODUCTION
(bootloader) secure:yes
(bootloader) hw-revision:MP1.0
nh2 /
Last active March 7, 2024 22:03
How to determine if the nix sandbox is in effect on a system

How to determine if the nix sandbox is in effect on a system

Do the same as the nix-info script, which nix-builds this file and inspects the exit code.

Short version:

nix-build --no-out-link -E 'import <nixpkgs/pkgs/tools/nix/info/multiuser.nix>' 2> /dev/null
#!/usr/bin/env bash
# Installs NixOS on an OVH server, wiping the server.
# This is for a specific server configuration; adjust where needed.
# Originally written for an OVH STOR-1 server.
# Prerequisites:
# * Create a LUKS key file at /root/benacofs-luks-key
# e.g. by copying it up.
nh2 /
Last active October 9, 2023 17:59 — forked from rmarchei/
route53 hook for dehydrated - python2 / python3 + boto2 version. Tested on Ubuntu 16.04
#!/usr/bin/env python3
# How to use:
# Ubuntu 16.04: apt install -y python-boto OR apt install -y python3-boto
# Specify the default profile on aws/boto profile files or use the optional AWS_PROFILE env var:
# AWS_PROFILE=example ./dehydrated -c -d -t dns-01 -k /etc/dehydrated/hooks/
# Manually specify hosted zone: