Skip to content

Instantly share code, notes, and snippets.

@danidiaz
Last active August 5, 2023 16:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danidiaz/744606d4daa496982421c28b9b8f5594 to your computer and use it in GitHub Desktop.
Save danidiaz/744606d4daa496982421c28b9b8f5594 to your computer and use it in GitHub Desktop.
ifd
# https://nixos.wiki/wiki/Import_From_Derivation
# https://discourse.nixos.org/t/how-to-import-a-derivation-with-import/15375
# https://nixos.org/manual/nix/stable/language/builtins#builtins-import
# https://nixos.org/manual/nix/stable/language/values.html#type-string
let
pkgs = import <nixpkgs> {};
derivation-to-import = pkgs.writeText "inner" "5";
imported-nix-value = import derivation-to-import;
in pkgs.writeText "foo" ''
The value from the inner derivation was: ${toString imported-nix-value}
''
# https://nixos.wiki/wiki/Import_From_Derivation
# https://discourse.nixos.org/t/how-to-import-a-derivation-with-import/15375
# https://nixos.org/manual/nix/stable/language/builtins#builtins-import
# https://nixos.org/manual/nix/stable/language/values.html#type-string
let
pkgs = import <nixpkgs> {};
derivation-to-import = pkgs.writeText "inner" ''
pkgs :
pkgs.runCommand "imported" {}
'''
sleep 6
# This is the out of the imported derivation,
# not of the outer derivation
# https://releases.nixos.org/nix-dev/2015-December/019018.html
echo 5 > ''$out
'''
'';
imported-nix-value = import derivation-to-import pkgs;
in pkgs.writeText "outer" ''
The value from the inner derivation was: ${imported-nix-value}
''
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment