Skip to content

Instantly share code, notes, and snippets.

Niklas Hambüchen nh2

Block or report user

Report or block nh2

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@nh2
nh2 / Typechecking-git-history-fast.md
Created Jan 16, 2020
Haskell: Type-checking a git history of commits fast with interactive rebasing and ghci -e
View Typechecking-git-history-fast.md

Type-checking your whole Pull Request before submission

You want to make a pull request to a Haskell project, which requires that each commit in your PR compiles fine individually.

Here is an easy, automated and fast way to check it:

git rebase --interactive HEAD~~~ --exec "! grep 'error:' <(stack ghci mylibrary:lib --ghci-options='-e 1' 2>&1)"
@nh2
nh2 / detect-nix-sandbox.md
Last active Jan 16, 2020
How to determine if the nix sandbox is in effect on a system
View detect-nix-sandbox.md

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
@nh2
nh2 / Squashing commits on a branch including merges while retaining some individual commits.md
Created Jan 8, 2020
git: Squashing commits on a branch including merges while retaining some individual commits
View Squashing commits on a branch including merges while retaining some individual commits.md

Initial state

We want to squash the v commits in

v1
v2
v3
k1
k2
@nh2
nh2 / nixpkgs-duplicity-test-gpg-errors.txt
Created Dec 16, 2019
duplicity tests gpg invocations fail with double free or corruption (out) on nix-review for https://github.com/NixOS/nixpkgs/pull/73315
View nixpkgs-duplicity-test-gpg-errors.txt
% NIX_PATH=nixpkgs=. /usr/bin/time nix-build --no-link -A duplicity
these derivations will be built:
/nix/store/73in6wzsqzpsi6k4y4x2qqi3az9rnkff-duplicity-0.7.19.drv
building '/nix/store/73in6wzsqzpsi6k4y4x2qqi3az9rnkff-duplicity-0.7.19.drv' on 'ssh://static-haskell-nix-ci'...
copying path '/nix/store/75c1irykc5r095djhxhnxrj9r0s0gph7-1359.2.3' from 'https://cache.nixos.org'...
copying path '/nix/store/lcckqzhp6khmzb9833frnh47g7fsjgik-1359.2.2' from 'https://cache.nixos.org'...
copying path '/nix/store/srgh1frvgvz141rish0pyjn520rgff38-1359.2.1' from 'https://cache.nixos.org'...
copying path '/nix/store/q8mapr5b3z26h7hackmnsk3sirjxqcq8-duplicity-0.7.19.tar.gz' from 'https://cache.nixos.org'...
copying path '/nix/store/g2za9nam04lpb5h8s7dd0y51r3lg75x6-gnutar-in-test.patch' from 'https://cache.nixos.org'...
copying path '/nix/store/ijvka0qiq3c7sk19sgs1mvm49qwpzgpl-python2.7-pyOpenSSL-19.0.0' from 'https://cache.nixos.org'...
@nh2
nh2 / hetzner-dedicated-wipe-and-install-nixos.sh
Last active Dec 8, 2019
Example script to install NixOS on a Hetzner dedicated server via the Hetzner rescue mode
View hetzner-dedicated-wipe-and-install-nixos.sh
#!/usr/bin/env bash
# Installs NixOS on a Hetzner server, wiping the server.
#
# This is for a specific server configuration; adjust where needed.
#
# Prerequisites:
# * Update the script to adjust SSH pubkeys, hostname, NixOS version etc.
#
# Usage:
@nh2
nh2 / ghc-error-verbose.txt
Last active Nov 12, 2019
GHC build error trying to add fields to InstalledPackageInfo
View ghc-error-verbose.txt
% ./hadrian/build.stack.sh -j --flavour=quickest --verbose
| Building Stage1 libraries: binary, Cabal, ghc, ghc-boot, ghc-boot-th, ghc-heap, ghci, hpc, mtl, parsec, template-haskell, text, transformers, terminfo, array, base, bytestring, containers, deepseq, directory, filepath, ghc-compact, ghc-prim, haskeline, integer-gmp, pretty, process, rts, stm, time, xhtml, libiserv, unix
| Building Stage1 programs: ghc, ghc-pkg, hp2ps, hsc2hs, unlit, haddock, hpc, ghc-iserv, runghc
| Building Stage2 libraries: binary, Cabal, ghc, ghc-boot, ghc-boot-th, ghc-heap, ghci, hpc, mtl, parsec, template-haskell, text, transformers, terminfo, array, base, bytestring, containers, deepseq, directory, filepath, ghc-compact, ghc-prim, haskeline, integer-gmp, pretty, process, rts, stm, time, xhtml, libiserv, unix
| Building Stage2 programs: ghc, ghc-pkg, hp2ps, hsc2hs, unlit, haddock, hpc, ghc-iserv, runghc
| Building Stage3 libraries:
| Building Stage3 programs:
@nh2
nh2 / nix-ldd.txt
Last active Nov 10, 2019
Nix odp-dpdk problem investigation for flokli
View nix-ldd.txt
unpacking source archive /nix/store/cqq2m229cpgms09gcf3a3z07774d36d0-odp-dpdk-1.22.0.0_DPDK_18.11.tar.gz
source root is odp-dpdk-1.22.0.0_DPDK_18.11
setting SOURCE_DATE_EPOCH to timestamp 1566561796 of file odp-dpdk-1.22.0.0_DPDK_18.11/test/validation/api/traffic_mngr/traffic_mngr.c
patching sources
autoreconfPhase
autoreconf: Entering directory `.'
autoreconf: configure.ac: not using Gettext
autoreconf: running: aclocal --force -I m4
autoreconf: configure.ac: tracing
autoreconf: running: libtoolize --copy --force
@nh2
nh2 / TemplateHaskell-recompilation-problem.md
Created Oct 31, 2019
TemplateHaskell: The [TH] Recompilation Problem
View TemplateHaskell-recompilation-problem.md

"The [TH] Recompilation Problem"

Usually, when you use ghci's :reload or ghc --make (with -O0 to disable unfoldings which are used for cross-module inlining), after changing implementation code of functions, GHC will incrementally recompile only the modules you changed, making for a fast development experience when iterating on implementation details.

(When you change API like functions types, export lists, etc.,

@nh2
nh2 / makePython3JobScriptWithPythonPackages.nix
Created Oct 16, 2017
Nix code to conveniently write an inline Python script with Python dependencies
View makePython3JobScriptWithPythonPackages.nix
{
# Inspired by https://github.com/NixOS/nixpkgs/blob/3dea1972737f5ce7b2c5461fe20370bad10aae03/nixos/modules/system/boot/systemd.nix#L202
makePython3JobScriptWithPythonPackages = name: packagesSelectionFun: text:
let
shellEscape = (import <nixpkgs/nixos/modules/system/boot/systemd-lib.nix> (with pkgs; { inherit config pkgs lib; })).shellEscape;
mkScriptName = s: (builtins.replaceStrings [ "\\" ] [ "-" ] (shellEscape s) );
x = pkgs.writeTextFile { name = "unit-script.py"; executable = true; destination = "/bin/${mkScriptName name}"; text = "#!/usr/bin/env python3\n${text}"; };
deriv = pkgs.stdenv.mkDerivation {
name = mkScriptName name;
buildInputs = [ (pkgs.python36.withPackages (pythonPackages: packagesSelectionFun pythonPackages)) ];
@nh2
nh2 / ovh-dedicated-wipe-and-install-nixos.sh
Created Jun 3, 2019
Example script to install NixOS on an OVH dedicated server via the OVH rescue mode
View ovh-dedicated-wipe-and-install-nixos.sh
#!/usr/bin/env bash
# Installs NixOS on an OVH server in its rescue mode, 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/datafs-luks-key
# e.g. by copying it up.
You can’t perform that action at this time.