Skip to content

Instantly share code, notes, and snippets.

View Lillecarl's full-sized avatar
🦕
Dinosaurs are a lie!

Carl Lillecarl

🦕
Dinosaurs are a lie!
View GitHub Profile
#!/usr/bin/env python3
"""
nix-touch: Update Nix store path registration times for LRU garbage collection
This tool updates the registrationTime field in the Nix database for a store path
and its dependencies, effectively marking them as "recently used" for GC purposes.
"""
import argparse
import sqlite3
apiVersion: v1
kind: Pod
metadata:
annotations:
cknix-expr: hello
kubectl.kubernetes.io/last-applied-configuration: |
{"apiVersion":"v1","kind":"Pod","metadata":{"annotations":{"cknix-expr":"hello","kubenix/k8s-version":"1.33","kubenix/project-name":"kubenix"},"name":"testpod","namespace":"default"},"spec":{"containers":[{"command":["/nix/var/result/bin/sleep","infinity"],"env":[{"name":"PATH","value":"/nix/var/result/bin"}],"image":"dramforever/scratch:latest","name":"this","volumeMounts":[{"mountPath":"/etc/nix","name":"nix-config","readOnly":true},{"mountPath":"/nix","name":"cknix-volume","readOnly":false}]}],"hostNetwork":true,"volumes":[{"configMap":{"name":"nix-config"},"name":"nix-config"},{"csi":{"driver":"cknix.csi.store","volumeAttributes":{"expr":"let\n pkgs = (import (builtins.fetchTree {\n type = \"github\";\n repo = \"nixpkgs\";\n owner = \"NixOS\";\n ref = \"nixos-unstable\";\n }) {});\nin\n pkgs.buildEnv {\n name = \"testEnv\";\n paths = [\n pkgs.uutil
This file has been truncated, but you can view the full file.
 /
├──  bin
├──  boot
├──  dev
│ ├──  core ⇒ /proc/kcore
│ ├──  fd ⇒ /proc/self/fd
│ ├──  full
│ ├──  mqueue
│ ├──  null
│ ├──  ptmx ⇒ pts/ptmx
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
kubenix/k8s-version: '1.33'
kubenix/project-name: kubenix
name: expressions.cknix.cool
spec:
conversion:
strategy: None
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
kubenix/k8s-version: '1.33'
kubenix/project-name: kubenix
name: expressions.cknix.cool
spec:
conversion:
strategy: None
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
kubenix/k8s-version: '1.33'
kubenix/project-name: kubenix
name: expressions.cknix.cool
spec:
conversion:
strategy: None
let
pkgs = import <nixpkgs> { };
lib = pkgs.lib;
ipScript = pkgs.writeScript "sipscript" ''
#! ${lib.getExe pkgs.fish}
echo \'\'
${lib.getExe pkgs.ipcalc} $argv
echo \'\'
'';
# Apply function to all strings in an attrset recursively through lists as well.
mapStringsDeep =
function: value:
if builtins.isString value then
function value
else if builtins.isAttrs value then
lib.mapAttrs (name: mapStringsDeep function) value
else if builtins.isList value then
map (mapStringsDeep function) value
else
[01:22:40]❌1 ❯ nvd diff /nix/var/nix/profiles/system-838-link/ /nix/var/nix/profiles/system-839-link/
<<< /nix/var/nix/profiles/system-838-link
>>> /nix/var/nix/profiles/system-839-link
Version changes:
[U.] #001 bc 1.08.1 -> 1.08.2
[U.] #002 breeze-icons 6.14.0 -> 6.15.0
[U*] #003 curl 8.13.0 x2, 8.13.0-bin, 8.13.0-debug, 8.13.0-man -> 8.14.1 x2, 8.14.1-bin, 8.14.1-debug, 8.14.1-man
[U.] #004 elfutils 0.192 x2, 0.192-bin, 0.192-dev -> 0.193 x2, 0.193-bin, 0.193-dev
[U.] #005 ell 0.76 x2 -> 0.77 x2
[D*] #006 file 5.46 x3, 5.46-dev, 5.46-man -> 5.45 x3, 5.45-dev, 5.45-man
# Note: nix will also try to replace @@escapeCode@@ and @@text@@ with "@@" and whatever is in the full text. Won't matter in practice
let
replaceStrings' =
{ escapeCode, text, ... }@replacements:
let
names = builtins.map (name: "${escapeCode}${name}${escapeCode}") (builtins.attrNames replacements);
values = builtins.attrValues replacements;
replacedText = builtins.replaceStrings names values text;
verificationMatches = builtins.match "^.*(@@.*@@).*$" replacedText;
verificationError = "Found unreplaced text ${builtins.concatStringsSep " " verificationMatches}";