How to install github released binary?

I’m using direnv and nix to manage my paths so I can have reproducible versions of my cli tools. There is a tool called kexpand GitHub - kopeio/kexpand which I need. To keep things simple (so I can get it done today) I just want to fetch the binary from the release, based on my os.

I’m new to nix and still learning the language and idioms. Anyone have a working example of fetching a binary from github or some other url and installing that? Right now I don’t have the time/interest in actually building kexpand from scratch though that seems to be what all the examples I’ve seen so far would do.

1 Like

I don’t know of any working examples, but whenever I need to use precompiled binaries on NixOS I follow this guide. In summary it comes down to patching the dynamic loader, checking which dynamic libraries it’s looking for, and patching the RPATH of the binary to where these libraries are located in the Nix Store.

But since the tool is written in Go, does it have any external dependencies? You might have an easier time building the program instead; but I don’t know how well Go is supported in nixpkgs.

It depends on your use case.

  • If you expect your users to already have Nix installed, I would recommend using nix-store --export to create a .nar file and nix-store --import to import and nix-env -i /nix/store/path to install the resulting path.
  • If your users will not have Nix installed, you can package it with nix-bundle:

Quickly built the package, you can give it a try here: kexpand: init at 2017-05-12 by manveru · Pull Request #49554 · NixOS/nixpkgs · GitHub

Here is how a pure binary version would look like:

$ nix-prefetch-url
path is '/nix/store/znn9l9dzyiz1xd99p6a0hz0jir04phx5-kexpand-linux-amd64'


{ pkgs ? import <nixpkgs> {} }:
pkgs.stdenv.mkDerivation {
  name = "kexpand";
  src = pkgs.fetchurl {
    url = "";
    sha256 = "0ldh303r5063kd5y73hhkbd9v11c98aki8wjizmchzx2blwlipy7";
  phases = ["installPhase" "patchPhase"];
  installPhase = ''
    mkdir -p $out/bin
    cp $src $out/bin/kexpand
    chmod +x $out/bin/kexpand

Now you can call nix-env -f . -i to install it. Or use pkgs.callPackage ./kexpand.nix {}; in your shell.nix to load it.

There is currently a bug that not all the libraries are reachable so it will have to be fixed further.


Thank you @manveru! With your files I was able to get kexpand installed.

@zimbatm that worked for me (I’m on os x so I had to change the url and sha256).

Hosted by Flying Circus.