Skip to content

Instantly share code, notes, and snippets.

View nh2's full-sized avatar

Niklas Hambüchen nh2

View GitHub Profile
@nh2
nh2 / filterSourceConvenience.nix
Created March 6, 2019 18:56
A convenient function for filtering nix src input
# Example usage:
#
# src = filterSourceConvenience.filter ./. {
# srcDirs = [
# ./src
# ./app
# ./images
# ];
# srcFiles = [
# ./mypackage.cabal

Keybase proof

I hereby claim:

  • I am nh2 on github.
  • I am nh2 (https://keybase.io/nh2) on keybase.
  • I have a public key ASDKBpC_rW52PREKyp33ebXJ9PYSfVhlvco2_3mZ2QiMOQo

To claim this, I am signing this object:

@nh2
nh2 / autoconf-cross-feature-detection.md
Created December 16, 2018 22:04
How autoconf does some feature detection on cross compilation

Originally from #ghc on freenode, 2018-12-16:

Most of the checks seem to actually be no-ops for cross-compilation. E.g. checking for working strnlen is just hardcoded to "yes" on all targets but AIX (in similar other cases, it just prints "guessing yes").

For checking size of int *, it does a binary search as you say, and NOT invoke the compiled programs. It does it by generating a static array with known size, like arr[1 - 2 * (sizeof(int*) <= BINARY_SEARCH_VAR)], so that the static size is either [1] or [-1]. C compilers happen to complain about arrays of negative static size, so that's how it figures that out. See ac_fn_c_compute_int().

To see this, I use for compilation of GNU hello, the following added to configure.ac:

@nh2
nh2 / add-bluetoothd-flag.nix
Created December 9, 2018 18:28
Shows how to add `-P` to bluetoothd in NixOS
with import <nixpkgs> {};
stdenv.mkDerivation {
name = "bluez-patched-systemd-unit";
buildCommand = let
in ''
set -eo pipefail
cp -rvs ${pkgs.bluez} --no-preserve=mode $out
sed --in-place 's:bluetooth/bluetoothd:bluetooth/bluetoothd -P:g' $out/etc/systemd/system/bluetooth.service
'';
@nh2
nh2 / dmesg.txt
Last active December 3, 2018 17:27
dmesg output showing failure of 2 devices in RAID1
$ dmesg
[ 0.000000] microcode: CPU0 microcode updated early to revision 0x1f, date = 2018-02-07
[ 0.000000] Initializing cgroup subsys cpuset
[ 0.000000] Initializing cgroup subsys cpu
[ 0.000000] Initializing cgroup subsys cpuacct
[ 0.000000] Linux version 4.4.0-131-generic (buildd@lgw01-amd64-015) (gcc version 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.10) ) #157-Ubuntu SMP Thu Jul 12 15:51:36 UTC 2018 (Ubuntu 4.4.0-131.157-generic 4.4.134)
[ 0.000000] Command line: BOOT_IMAGE=/vmlinuz-4.4.0-131-generic root=/dev/mapper/vg0-ubuntu1604 ro console=tty1 console=ttyS0,115200
[ 0.000000] KERNEL supported cpus:
[ 0.000000] Intel GenuineIntel
[ 0.000000] AMD AuthenticAMD
@nh2
nh2 / Setup.hs
Last active December 1, 2018 05:52
Haskell: Patching libc with Cabal postBuild hook
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# OPTIONS_GHC -Wall #-}
import Control.Concurrent.Async (forConcurrently_)
import Data.Foldable (for_)
import Data.List (intercalate)
import qualified Data.Map as Map
import Data.Semigroup ((<>))
import qualified Data.Text as T
@nh2
nh2 / gdb-stracktrace.txt
Created November 28, 2018 04:11
Crazy sched_yield() spam in GHC-compiled program that is quite idle but takes high CPU usage
#0 0x00007f5b1ebe458f in pthread_cond_wait@@GLIBC_2.3.2 () from /nix/store/hwwqshlmazzjzj7yhrkyjydxamvvkfd3-glibc-2.26-131/lib/libpthread.so.0
#1 0x0000000001d06f69 in waitCondition ()
#2 0x0000000001cf533b in yieldCapability ()
#3 0x0000000001cf26c9 in schedule ()
#4 0x0000000001cf37ac in scheduleWorker ()
#5 0x00007f5b1ebde2a7 in start_thread () from /nix/store/hwwqshlmazzjzj7yhrkyjydxamvvkfd3-glibc-2.26-131/lib/libpthread.so.0
#6 0x00007f5b002a757f in clone () from /nix/store/hwwqshlmazzjzj7yhrkyjydxamvvkfd3-glibc-2.26-131/lib/libc.so.6
@nh2
nh2 / ghc_1.s
Created November 26, 2018 22:44
Investigation of Cabal c-sources not yielding debugging symbols
.file "lz4frame.c"
.text
.Ltext0:
.section .text.unlikely,"ax",@progbits
.LCOLDB0:
.text
.LHOTB0:
.p2align 4,,15
.section .text.unlikely
.Ltext_cold0:
@nh2
nh2 / ghc-g-to-as.txt
Last active November 26, 2018 21:38
Passing -g to as via GHC
Using ghc-8.2.2
-g -optc-g -opta-g -optc-Wa,-g -opta-Wa,-g
passes -g to as
-g -optc-g -opta-g -optc-Wa,-g
does not pass -g to as
-g -optc-g -opta-g -opta-Wa,-g
passes -g to as
#!/usr/bin/env python3
import argparse
import copy
import json
import sys
def migrate(input_dict):
j = copy.deepcopy(input_dict)