Skip to content

Instantly share code, notes, and snippets.

View thufschmitt's full-sized avatar

Théophane Hufschmitt thufschmitt

View GitHub Profile
#!/usr/bin/env bash
set -euo pipefail
gh_ () {
## Dry-run mode
echo "gh $@"
## Real mode
# gh "$@"
}
@thufschmitt
thufschmitt / docgen.ncl
Created October 27, 2023 15:34
Quick and dirty doc generator for Nickel
let lib = {
handle_record_field = fun rec_name { fields, type, contracts, documentation } =>
m%"
<details>
<summary>%{rec_name}</summary>
<div style="margin-left:12px">
%{if documentation != null then documentation else "_no documentation_"}
%{if type != null then "- *type*: %{type}" else ""}
%{if contracts != [] then "- *contracts*:\n%{
contracts
@thufschmitt
thufschmitt / modules.ncl
Created August 5, 2023 15:20
Modules for Nickel
# A library for NixOS-style “modules”
#
# Modules are records whose contract gets extended through merging: `Module c`
# is a contract semantically equivalent to `c`, except that if `foo` has
# contract `Module x` and `bar` has contract `Module y`, then `foo & bar` will
# have contract `Module (x&y)`.
{
empty = { contract.contract | optional },
@thufschmitt
thufschmitt / discardRefs.nix
Created May 15, 2023 08:13
Discard references in Nix
let p = import <nixpkgs> {}; in
let
discardReferences = path:
let
# We want to use a different nixpkgs here to make sure that the `noref`
# version won't accidentally share some build-time references with the
# original one
p2 = (builtins.getFlake "github:nixos/nixpkgs/nixos-unstable").legacyPackages.${builtins.currentSystem};
mangledPath = p2.runCommandNoCC "${path.name}.tar.gz" {} ''
@thufschmitt
thufschmitt / flake.nix
Last active March 30, 2023 13:52
Weird side effects in Nix
{
inputs.nixpkgs.url = "github:nixos/nixpkgs/a7cc81913bb3cd1ef05ed0ece048b773e1839e51";
outputs = { self, nixpkgs }: {
testPathExists =
let hello = nixpkgs.legacyPackages.x86_64-linux.hello; in
builtins.pathExists hello;
testPathExists2 =
# Output of `nix eval --inputs-from . nixpkgs\#hello.outPath`
@thufschmitt
thufschmitt / flake.lock
Created February 24, 2022 11:27
Nix eval cache benchmark
{
"nodes": {
"flake-utils": {
"locked": {
"lastModified": 1644229661,
"narHash": "sha256-1YdnJAsNy69bpcjuoKdOYQX0YxZBiCYZo4Twxerqv7k=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "3cecb5b042f7f209c56ffd8371b2711a290ec797",
"type": "github"
@thufschmitt
thufschmitt / test.nix
Created January 12, 2022 06:51
Nix path&git behavior
#!/usr/bin/env bash
set -euo pipefail
set -x
rm -rf A B
mkdir -p A B
pushd A
echo foo > foo
[
"criterion",
"1.4.1.0",
[
{
"reportAnalysis": {
"anMean": {
"estError": {
"confIntLDX": 0.00020337399737880256,
"confIntUDX": 0.0005146031421548181,
{ stdenv, ocaml, ocamlPackages, makeWrapper }:
stdenv.mkDerivation rec {
name = "ocaml_with_topfind-${version}";
version = lib.getVersion ocaml;
nativeBuildInputs = [ makeWrapper ];
buildCommand = ''
makeWrapper "${ocaml}/bin/ocaml" "$out/bin/ocaml_topfind" \
--add-flags "-I ${ocamlPackages.findlib}/lib/ocaml/${version}/site-lib"
'';
@thufschmitt
thufschmitt / tmux-2.0_true-colors_patch.diff
Created August 3, 2015 04:58
Patch for enabling true-colors int tmux 2.0
This diff is a modified version of a diff written by Arnis Lapsa.
[ The original can be found here: https://gist.github.com/ArnisL/6156593 ]
This diff adds support to tmux for 24-bit color CSI SRG sequences. This
allows terminal based programs that take advantage of it (e.g., vim or
emacs with https://gist.github.com/choppsv1/73d51cedd3e8ec72e1c1 patch)
to display 16 million colors while running in tmux.
The primary change I made was to support ":" as a delimeter as well