Nix package
2mol opened this issue · comments
There seems to be demand for creating a nix package for this application (#3)
Since I don't use nix yet, this is the place to discuss what needs to be done within the repository, and what we need to do on the nixpkgs side.
This is how I did it:
default.nix:
{ pkgs ? import <nixpkgs> {}, ... }:
let
# This is equivalent of lts 11.9
haskellPackages = (import (pkgs.fetchFromGitHub {
owner = "NixOS";
repo = "nixpkgs";
rev = "9cd1702502630eb3fc76d7b0e6a4548afdd37ede";
sha256 = "1xsam8mwl93d203qqb80k8b2sxlkr0f1973zn6n262sn2k8630qx";
}) {}).haskellPackages;
pboy = pkgs.callPackage ./pboy.nix {haskellPackages=haskellPackages;};
# This is where I'm showing that I'm not yet too familiar with nix packaging
# Basically I'm just creating a wrapper around the haskell package that has the poppler dependency as a runtime dependency
builder = pkgs.writeScript "builder" ''
#!${pkgs.bash}/bin/bash
export PATH=${pkgs.coreutils}/bin:$PATH
source ${pkgs.makeWrapper}/nix-support/setup-hook
mkdir -p $out/bin/
cp ${pboy}/bin/pboy $out/bin/pboy
SHELL=${pkgs.bash}/bin/bash
wrapProgram $out/bin/pboy --set PATH ${pkgs.poppler_utils}/bin:$PATH
'';
in
derivation {
name = "paperboy";
version = "0.1.0";
builder = "${pkgs.bash}/bin/bash";
args = [ builder ];
system = builtins.currentSystem;
}
pboy.nix
{ haskellPackages, fetchFromGitHub, ... }:
haskellPackages.callCabal2nix "pboy" (fetchFromGitHub {
owner = "2mol";
repo = "pboy";
rev = "a85329bf17557beae73ca9a97f9935a61f050432";
sha256 = "1a9m7n3n02pn7lnpqcviimfkgfdkixsqbgpbmcn363gkmrmqza7s";
}) {}
Thanks @MasseR !
Do you know how this differs from what cabal2nix --shell ./. > default.nix
gives?
I never worked with nix, so any clarification are welcome. For example, how can I reproduce your files whenever I update paperboy?
Yeah. The cabal2nix --shell
creates a nix file that is suitable for starting either a nix shell or building / installing the package itself. It's a file that needs to be generated every time the cabal file changes. I'm calling the callCabal2nix
function which does that behind the scenes, but at the same time it also calls it every time the package is needed to be built.
What my solution has more than just cabal2nix is that it pins a specific version of nixpkgs and haskell dependencies to lts-11.9. It also creates a wrapper over the ghc built binary that has an explicit dependency over the system command pdftotext
. This makes sure that if the binary is installed, so is the pdftotext
command.
If you have nix installed, you can try this by creating a directory and putting these two files there and then run nix build -f <dir>
(disclaimer: I don't have a machine to test this command at the moment, but should work)