Skip to content

Instantly share code, notes, and snippets.

@evanrelf
Created June 18, 2021 20:20
Show Gist options
  • Save evanrelf/0f3258b4f71ff4eb316c23fb110e2083 to your computer and use it in GitHub Desktop.
Save evanrelf/0f3258b4f71ff4eb316c23fb110e2083 to your computer and use it in GitHub Desktop.
Simple example of "import from derivation" in Nix
{ expr }:
let
pkgs = import <nixpkgs> { };
drv =
pkgs.runCommand "script" { } ''
echo 'Building during evaluation to generate a Nix expression!'
${pkgs.cowsay}/bin/cowsay '${expr}'
echo '${expr}' > $out
'';
in
import /* from */ drv
λ nix-instantiate ifd.nix --eval --read-write-mode --argstr expr "2 + 2"
copying path '/nix/store/y6pjym3f1njrcphjyw60ydd1hrfqfrx0-cowsay-3.04' from 'https://cache.nixos.org'...
building '/nix/store/1hf02dd7l1dlq4dmspbzbrkcpq8i4xmq-script.drv'...
Building during evaluation to generate a Nix expression!
_______
< 2 + 2 >
-------
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||
4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment