Created
November 10, 2021 16:19
-
-
Save madjam002/2b75f089b39bd70b7744d85895f98d8e to your computer and use it in GitHub Desktop.
Nix pass function as dependency to derivation
This file contains 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
{ pkgs }: | |
let | |
some_function = { arg1, arg2 }: '' | |
echo "hello world" | |
${pkgs.nodejs}/bin/node --version | |
${pkgs.vault}/bin/vault --version | |
''; | |
drv = pkgs.stdenv.mkDerivation { | |
name = "test"; | |
# depends_on = some_function; | |
phases = ["build"]; | |
build = "touch $out"; | |
}; | |
in | |
drv // { | |
inherit some_function; | |
} |
This file contains 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
{ | |
"nodes": { | |
"nixpkgs": { | |
"locked": { | |
"lastModified": 1636333654, | |
"narHash": "sha256-3wh9PtCzcaJQuZrgZ+ygKfhltkDNNqT6zOzGsRbjZEo=", | |
"owner": "NixOS", | |
"repo": "nixpkgs", | |
"rev": "e74894146a42ba552ebafa19ab2d1df7ccbc1738", | |
"type": "github" | |
}, | |
"original": { | |
"id": "nixpkgs", | |
"ref": "nixos-21.05", | |
"type": "indirect" | |
} | |
}, | |
"root": { | |
"inputs": { | |
"nixpkgs": "nixpkgs" | |
} | |
} | |
}, | |
"root": "root", | |
"version": 7 | |
} |
This file contains 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
{ | |
description = "A very basic flake"; | |
inputs = { | |
nixpkgs.url = "nixpkgs/nixos-21.05"; | |
}; | |
outputs = { self, nixpkgs }: | |
let | |
pkgs = nixpkgs.legacyPackages.x86_64-linux; | |
in | |
{ | |
default = import ./default.nix { inherit pkgs; }; | |
}; | |
} |
This file contains 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
# build the derivation | |
nix build .#default | |
# get the value of some_function with args passed in | |
nix eval .#default.some_function --apply '(fn: fn { arg1 = "test"; arg2 = "test"; })' | |
"echo \"hello world\"\n/nix/store/md401gf1prrzlsrrx1gqa5sh6lxjrbih-nodejs-14.18.1/bin/node --version\n/nix/store/sfq1x03vfjd24r88y9xfs4zdc88clbak-vault-1.7.4/bin/vault --version\n" | |
# How do I get | |
# /nix/store/md401gf1prrzlsrrx1gqa5sh6lxjrbih-nodejs-14.18.1 | |
# and | |
# /nix/store/sfq1x03vfjd24r88y9xfs4zdc88clbak-vault-1.7.4 | |
# to build with the derivation implicitly from some_function without passing the arguments? | |
# As the arguments will only be known at runtime during nix eval like above. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment