Created
June 18, 2021 20:20
-
-
Save evanrelf/0f3258b4f71ff4eb316c23fb110e2083 to your computer and use it in GitHub Desktop.
Simple example of "import from derivation" in Nix
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
λ 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