Graft: replace dependencies CLI
Announcements - NixOS Discourse(claude was used… extensively)
Graft replaces dependencies at the store layer, bypassing the normal Nix eval. Inspired by Guix graft.
While we do have replaceDependency and system.replaceDependencies I thought it would be nice to have a Guix-style CLI to run grafts more manually and without having to re-evaluate Nix expressions that you may/may-not still have around. Eg:
$ nix run nixpkgs/nixos-25.11#curl -- --version
curl 8.20.0 (x86_64-pc-linux-gnu) libcurl/8.20.0 OpenSSL/3.6.2 ...
$ export curl="$(nix eval nixpkgs/nixos-25.11#curl.outPath --raw)"
$ graft replace $curl --override-name openssl nixpkgs/nixos-26.05#openssl.out
...
grafted /nix/store/r4p5r6q0n3lmidd0yq2zblqxvim0xsb3-krb5-1.22.1-lib -> /nix/store/nxa80mkh75x6cik14mqcbd0d34b3c1nz-krb5-1.22.1-lib
grafted /nix/store/rngyrpv421p1cnn78d5ph2y5ylg133n7-curl-8.20.0 -> /nix/store/qap31yikgr3hadwg455pl96k8rs2bbjn-curl-8.20.0
grafted /nix/store/2nmfyy3jjgn2m8d1p7lwbbxakl4ciwfc-curl-8.20.0-bin -> /nix/store/yklqiif3wxlh67sidmaflv7il2dykmn6-curl-8.20.0-bin
5 grafted, 1 explicit replacement, 15 unchanged (21 total)
/nix/store/yklqiif3wxlh67sidmaflv7il2dykmn6-curl-8.20.0-bin
$ /nix/store/yklqiif3wxlh67sidmaflv7il2dykmn6-curl-8.20.0-bin/bin/curl --version
curl 8.20.0 (x86_64-pc-linux-gnu) libcurl/8.20.0 OpenSSL/3.6.5 ...
$ nix path-info -r /nix/store/yklqiif3wxlh67sidmaflv7il2dykmn6-curl-8.20.0-bin | grep openssl
/nix/store/kysvfcf8d8v26rr32xfqji8ri2lczlqk-openssl-3.6.5
Can this be very unsafe? YES! The tool is sharp. Beware the “Segmentation fault” and “version `GLIBC_2.43’ not found” when messing with libraries. Probably safer to be replacing full executable binaries.
Is this actually useful? Not sure, but there are some cases this can be useful. Let’s say I want to quickly test out an edit to a config file that I just can’t de-tangle from a convoluted NixOS module or I don’t have the Nix expressions for:
$ export EDITOR=vim
$ head /etc/nix/nix.conf
# WARNING: this file is generated from the nix.* options in
# your NixOS configuration, typically
# /etc/nixos/configuration.nix. Do not edit it!
...
$ graft replace /run/current-system --edit /etc/nix/nix.conf .
... changing settings and committing sins ...
...
grafted /nix/store/gb26m3dhkl2y15wm0d7kkia0cshilnns-etc -> /nix/store/9mwa5njhvd6afx2djpwk0bb4vxpq7gv7-etc
grafted /nix/store/84cnh54jh3f06hn5qavqjp54qdmcjs5g-nixos-system-tdesk-26.11.20260919.20b1ddd -> /nix/store/im48r35pkag211jm4i68wl8gm3vpdzmx-nixos-system-tdesk-26.11.20260919.20b1ddd
5 grafted, 1 explicit replacement, 2813 unchanged (2819 total)
/nix/store/im48r35pkag211jm4i68wl8gm3vpdzmx-nixos-system-tdesk-26.11.20260919.20b1ddd
$ head /nix/store/im48r35pkag211jm4i68wl8gm3vpdzmx-nixos-system-tdesk-26.11.20260919.20b1ddd/etc/nix/nix.conf
# HELLO THERE
# WARNING: this file is generated from the nix.* options in
# your NixOS configuration, typically
# /etc/nixos/configuration.nix. Do not edit it!
#
# MWAHAHAHAHAHHAHAHA!
...
Also try directly editing .drv files in order to override compilation flags + phases! Plus there is --report for an HTML page to see what kind of surgical horrors you have performed:

1 post - 1 participant