How to install package from github?

I want to add hocker to environment.systemPackages in my configuration.nix so that hocker-image, docker2nix, etc is available for all users.

I naively tried to create the following hocker.nix file:

{ pkgs ? import <nixpkgs> {} }:

pkgs.stdenv.mkDerivation rec {
  name = "hocker-${version}";
  version = "git-2018-06-30";

  src = pkgs.fetchFromGitHub {
    owner  = "awakesecurity";
    repo   = "hocker";
    rev    = "88150c7b8a0664a70757ffd88b2ac12b84dd0604";
    sha256 = "1mb3gfg01mj7ajjl1ylw24mnwamcnnifbxkakzal2j6ibqyqw6rq";
  };
  
  buildInputs = [ pkgs.nix ];

  buildPhase = ''
    nix-build ${src}/release.nix
  '';
}

but when running nix-build hocker.nix it fails:

these derivations will be built:
  /nix/store/spn3x38vvyfrvc86psw2v1k31mp1gay9-hocker-git-2018-06-30.drv
building '/nix/store/spn3x38vvyfrvc86psw2v1k31mp1gay9-hocker-git-2018-06-30.drv'...
unpacking sources
unpacking source archive /nix/store/br8ni51dhyb90f4v7qn00jiilb4nhh9m-source
source root is source
patching sources
configuring
no configure script, doing nothing
building
error: cannot open connection to remote store 'daemon': reading from file: Connection reset by peer
(use '--show-trace' to show detailed location information)
builder for '/nix/store/spn3x38vvyfrvc86psw2v1k31mp1gay9-hocker-git-2018-06-30.drv' failed with exit code 1
error: build of '/nix/store/spn3x38vvyfrvc86psw2v1k31mp1gay9-hocker-git-2018-06-30.drv' failed
1 Like

I found out that hocker is available under pkgs.haskellPackages.hocker so I don’t need to install it from github.

Another solution that worked was cloning the repo into /etc/nixos/hocker and importing ./hocker/release.nix from configuration.nix.

  buildPhase = ''
    nix-build ${src}/release.nix
  '';

You don’t want to nix-build while building a derivation. For future reference what you want to do is commonly known as “Import From Derivation” (IFD), and it is pretty much what it sounds like:

let src = pkgs.fetchFromGitHub {
    owner  = "awakesecurity";
    repo   = "hocker";
    rev    = "88150c7b8a0664a70757ffd88b2ac12b84dd0604";
    sha256 = "1mb3gfg01mj7ajjl1ylw24mnwamcnnifbxkakzal2j6ibqyqw6rq";
  };
in
import "${src}/release.nix"

(or use callPackage instead of import if you need)

5 Likes