How to package a command line tool in Nix?

Suppose you have a simple collection of scripts bash

that make up a command line tool, with a main script in bin/

and some library scripts in lib/

, all of which will be packaged with Nix with tool.nix

s default.nix

for convenience:

scriptdir
 └─ bin/
     └─ tool
 └─ lib/
 └─ default.nix
 └─ tool.nix

      

What should it look like tool.nix

to properly package this tool to be tool

wrapped with tool <args>

?

+3


source to share


1 answer


After some help IRC works tool.nix

:

{ stdenv }:

let

    version = "0.0.1";

in stdenv.mkDerivation 
rec 
{

    name = "tool-${version}";

    src = ./.;

    installPhase =
        ''
            mkdir -p $out
            cp -R ./bin $out/bin
            cp -R ./lib $out/lib
        '';

}

      

For completeness it default.nix

will look like



{ pkgs ? import <nixpkgs> {} }:

pkgs.callPackage ./tool.nix {}

      

and can be set by calling nix-env -f ./default.nix -i

from scriptdir

.

+2


source







All Articles