Skip to content

Instantly share code, notes, and snippets.

parallel_map() {
local func="$1"
local num_cores
num_cores=$(nproc 2>/dev/null || echo 4)
local pipe_buf_size
pipe_buf_size=$(getconf PIPE_BUF / 2>/dev/null || echo 4096)
local tmpdir
tmpdir=$(mktemp -d)
trap 'rm -rf "$tmpdir"' EXIT
@Mic92
Mic92 / kexec-installer.nix
Last active March 22, 2025 18:18
kexec-based installer for nixos to install nixos from every linux!
## USAGE
# $ nix-build kexec-installer.nix
# can be deployed remote like this
# $ rsync -aL -e ssh result/ root@host:
# $ ssh root@host ./kexec-installer
## Customize it like this
# # custom-installer.nix
# import ./kexec-installer.nix {
# extraConfig = {pkgs, ... } {
# user.extraUsers.root.openssh.authorizedKeys.keys = [ "<your-key>" ];
From 3ceb739b696ac712dddfc6acf1f88e492d6f07d3 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= <joerg@thalheim.io>
Date: Sat, 20 Jul 2024 10:23:57 +0200
Subject: [PATCH] detect systemd by name rather than relying on
SYSTEMD_BINARY_PATH
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
This allows us in NixOS to run systemd binaries from the nix store
@Mic92
Mic92 / gitolite-anongit
Last active January 29, 2025 04:41
Anonymous ssh access for gitolite
#/bin/sh
# save as /usr/local/bin/gitolite-anongit
# and chmod +x /usr/local/bin/gitolite-anongit
# ForceCommand may depend on the gitolite distribution
/usr/share/gitolite/gl-auth-command anongit "$@"
#!/bin/bash
set -eux -o pipefail
# Create mount point if it doesn't exist
mkdir -p /run/testmount
# Clean up on exit
trap 'umount /run/testmount; rmdir /run/testmount' EXIT
@Mic92
Mic92 / 0_description.md
Last active December 3, 2024 14:33
Tvix (79246855d1a0fd9b81be113b16a56379c7641aa1) vs nix (2.19.2) evaluation of the hello package

Tvix is a new implementation of the Nix language and package manager. In this benchmark we test it's performance when instantiating the hello package from nix. Note that at the time tvix does not have its own store implementation yet and it has to execute nix-store whenever it needs to copy files to the store.

{ pkgs, config, ... }:
{
nixpkgs.config.allowUnfree = true;
nixpkgs.config.nvidia.acceptLicense = true;
# enable the nvidia driver
services.xserver.videoDrivers = [ "nvidia" ];
hardware.opengl.enable = true;
hardware.nvidia.datacenter.enable = true;
hardware.nvidia.package = config.boot.kernelPackages.nvidiaPackages.dc_535;
hyperfine --show-output 'rm -R ~/.cache/nix/binary-cache-*.sqlite*; rm -rf /tmp/cache; nix copy --from "{url}" --to "file:///tmp/cache?compression=none" /nix/store/jlkypcf54nrh4n6r0l62ryx93z752hb2-firefox-132.0' -L url https://nixos.tvix.store,https://cache.nixos.org/
Benchmark 1: rm -R ~/.cache/nix/binary-cache-*.sqlite*; rm -rf /tmp/cache; nix copy --from "https://nixos.tvix.store" --to "file:///tmp/cache?compression=none" /nix/store/jlkypcf54nrh4n6r0l62ryx93z752hb2-firefox-132.0
  Time (mean ± σ):      5.090 s ±  0.113 s    [User: 4.721 s, System: 2.555 s]
  Range (min … max):    4.942 s …  5.332 s    10 runs

Benchmark 2: rm -R ~/.cache/nix/binary-cache-*.sqlite*; rm -rf /tmp/cache; nix copy --from "https://cache.nixos.org/" --to "file:///tmp/cache?compression=none" /nix/store/jlkypcf54nrh4n6r0l62ryx93z752hb2-firefox-132.0
  Time (mean ± σ):      6.729 s ±  0.148 s    [User: 15.829 s, System: 2.904 s]
  Range (min … max):    6.560 s …  7.049 s    10 runs
diff --git a/nixos/modules/system/etc/build-composefs-dump.py b/nixos/modules/system/etc/build-composefs-dump.py
index fe739a621ec4..42287ea35842 100644
--- a/nixos/modules/system/etc/build-composefs-dump.py
+++ b/nixos/modules/system/etc/build-composefs-dump.py
@@ -1,5 +1,3 @@
-#!/usr/bin/env python3
-
"""Build a composefs dump from a Json config
See the man page of composefs-dump for details about the format:
// This code was autogenerated with `dbus-codegen-rust `, see https://github.com/diwic/dbus-rs
use dbus as dbus;
#[allow(unused_imports)]
use dbus::arg;
use dbus::blocking;
pub trait OrgFreedesktopDBusPeer {
fn ping(&self) -> Result<(), dbus::Error>;
fn get_machine_id(&self) -> Result<String, dbus::Error>;
}