Skip to content

Instantly share code, notes, and snippets.

@edef1c
Last active April 13, 2026 01:19
Show Gist options
  • Select an option

  • Save edef1c/066169b2b1a587905c58c7f1bdf18a73 to your computer and use it in GitHub Desktop.

Select an option

Save edef1c/066169b2b1a587905c58c7f1bdf18a73 to your computer and use it in GitHub Desktop.
communicating through the Nix store
edef@vixen ~/t/2020-06-20 (master)> nix-build --no-out-link -A write --arg value true
these derivations will be built:
  /nix/store/hf26690li13x8sflx43qxdzfk7lwr0gw-hello.drv
building '/nix/store/hf26690li13x8sflx43qxdzfk7lwr0gw-hello.drv'...
/nix/store/0k2h9r7y2jh5kzs0f3cn06h8y6ws42nh-hello
edef@vixen ~/t/2020-06-20 (master)> cat (nix-build --no-out-link -A read)
these derivations will be built:
  /nix/store/48fgw5gj6gnm9y59rsghbwkn1l874ky8-hello.drv
building '/nix/store/48fgw5gj6gnm9y59rsghbwkn1l874ky8-hello.drv'...
true
edef@vixen ~/t/2020-06-20 (master)> nix-store --delete /nix/store/0k2h9r7y2jh5kzs0f3cn06h8y6ws42nh-hello --quiet
finding garbage collector roots...
deleting unused links...
1 store paths deleted, 0.00 MiB freed

edef@vixen ~/t/2020-06-20 (master)> nix-build --no-out-link -A write --arg value false
these derivations will be built:
  /nix/store/j16cb5x13ax2nnlbi2r7d2cpv6y3xdrb-hello.drv
building '/nix/store/j16cb5x13ax2nnlbi2r7d2cpv6y3xdrb-hello.drv'...
/nix/store/0k2h9r7y2jh5kzs0f3cn06h8y6ws42nh-hello
edef@vixen ~/t/2020-06-20 (master)> cat (nix-build --no-out-link -A read)
these derivations will be built:
  /nix/store/py1wcrni0sh5y25n60k427d4jmqikl4f-hello.drv
building '/nix/store/py1wcrni0sh5y25n60k427d4jmqikl4f-hello.drv'...
false
edef@vixen ~/t/2020-06-20 (master)> nix-store --delete /nix/store/0k2h9r7y2jh5kzs0f3cn06h8y6ws42nh-hello --quiet
finding garbage collector roots...
deleting unused links...
1 store paths deleted, 0.00 MiB freed

edef@vixen ~/t/2020-06-20 (master)> cat (nix-build --no-out-link -A read)
these derivations will be built:
  /nix/store/j16cb5x13ax2nnlbi2r7d2cpv6y3xdrb-hello.drv
  /nix/store/lhszg4nqhc4wxdjys9lam914xakbr3xr-hello.drv
building '/nix/store/j16cb5x13ax2nnlbi2r7d2cpv6y3xdrb-hello.drv'...
building '/nix/store/lhszg4nqhc4wxdjys9lam914xakbr3xr-hello.drv'...
false
with import <nixpkgs> {};
let
file = builtins.toFile "true" "";
drv = { script, attrs }: derivation ({
name = "hello";
inherit system;
builder = "${bash}/bin/bash";
args = [ "-e" (builtins.toFile "builder.sh" script) ];
} // attrs);
write = value: drv {
script = "echo 1fbhb0f7c5afcmc5jw08l6gi5sj4j917 > $out";
attrs = {
outputHashMode = "recursive";
outputHashAlgo = "sha256";
outputHash = "09pgnalr38z9pknq3bgyjszzybsibxg0yhaqyhwywbllnrjy84w5";
} // lib.optionalAttrs value { inherit file; };
};
read = {}: drv {
script = ''
if [ -f /nix/store/1fbhb0f7c5afcmc5jw08l6gi5sj4j917-true ]; then
echo true > $out
else
echo false > $out
fi
'';
attrs.file = write false;
attrs.time = builtins.currentTime;
};
in {
write = { value }: write value;
read = read;
}
@edef1c
Copy link
Copy Markdown
Author

edef1c commented Apr 13, 2026

Published for historical purposes. Releases from Nix 2.4 onwards reject FOD outputs with references.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment