Skip to content

Instantly share code, notes, and snippets.

@freeman42x
Last active August 19, 2019 17:22
Show Gist options
  • Save freeman42x/a0a6c6c1853a08a9afc6ad4af1471c66 to your computer and use it in GitHub Desktop.
Save freeman42x/a0a6c6c1853a08a9afc6ad4af1471c66 to your computer and use it in GitHub Desktop.
How to add nix package with executable that can be used from nix-shell?
{ nixpkgs ? import <nixpkgs> {}, compiler ? "default", doBenchmark ? false }:
let
inherit (nixpkgs) pkgs;
f = { mkDerivation, base, hedgehog, hedgehog-fn, hint, hpack
, placeholders, stdenv, template-haskell
}:
mkDerivation {
pname = "artificial-general-intelligence";
version = "0.1.0.0";
src = ./.;
isLibrary = true;
isExecutable = true;
libraryHaskellDepends = [
base hint placeholders template-haskell
];
libraryToolDepends = [ hpack ];
executableHaskellDepends = [ base ];
testHaskellDepends = [ base hedgehog hedgehog-fn ];
preConfigure = "hpack";
homepage = "https://github.com/razvan-panda/artificial-general-intelligence#readme";
license = stdenv.lib.licenses.bsd3;
};
haskellPackages = if compiler == "default"
then pkgs.haskellPackages
else pkgs.haskell.packages.${compiler};
variant = if doBenchmark then pkgs.haskell.lib.doBenchmark else pkgs.lib.id;
drv = variant (haskellPackages.callPackage f {});
in
if pkgs.lib.inNixShell then drv.env.overrideAttrs (drv: { buildInputs = drv.buildInputs or [] ++ [ pkgs.gnumake ]; }) else drv
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment