Skip to content

Instantly share code, notes, and snippets.

@madjar
Created January 16, 2019 15:48
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 madjar/2836e0727b9ff1a1103c98a906ad5b8c to your computer and use it in GitHub Desktop.
Save madjar/2836e0727b9ff1a1103c98a906ad5b8c to your computer and use it in GitHub Desktop.
Lazy binaries, that install the underlying command on invocation (the missing part is a gc root)
with import <nixpkgs> {};
let
mkLazyBin = { pkg, bin }:
writeTextFile {
name = bin;
executable = true;
text = ''
#!/bin/sh
[[ -d ${builtins.unsafeDiscardStringContext (pkg.outPath)} ]] || nix build --no-link ${builtins.unsafeDiscardStringContext (pkg.drvPath)}
${builtins.unsafeDiscardStringContext (pkg.outPath)}/bin/${bin}
'';
};
in mkLazyBin {
pkg = hello;
bin = "hello";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment