summaryrefslogtreecommitdiffhomepage
path: root/package.nix
blob: bbe23cab90444be80b111bfdf06327291f01d6d4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# package.nix - spine_search CGI derivation (build logic)
#
# Standalone, callPackage-style derivation for the spine_search CGI
# binary. Used by shell.nix to put a freshly-built spine_search into
# the dev shell. May also be consumed via:
#   nix-build ./package.nix
#   pkgs.callPackage ./package.nix {}
#
# Compiler defaults to ldc/ldmd2 (matching the flake's default
# package `spine-search-nixpkgs-ldc`). Override to build with dmd:
#   pkgs.callPackage ./package.nix {
#     compilerPkg = pkgs.dmd;
#     compilerBin = "dmd";
#     buildType   = "dmd";
#   }
#
# Note: spine_search is a CGI binary and is installed to
# $out/cgi-bin/spine_search (not $out/bin/), since it is intended to
# be served by a web server, not invoked directly from PATH.
{
  lib,
  stdenv,
  dub,
  ldc,
  gnumake,
  sqlite,
  compilerPkg ? ldc,
  compilerBin ? "ldmd2",
  buildType   ? "ldmd2",
}:
stdenv.mkDerivation {
  pname   = "spine_search";
  version = "0.18.0";
  src     = lib.cleanSource ./.;
  buildInputs       = [ sqlite ];
  nativeBuildInputs = [ dub compilerPkg gnumake ];
  preBuild = ''
    export HOME=$(pwd)
  '';
  buildPhase = ''
    runHook preBuild
    buildCMD="dub run --cache=local \
      --compiler=$(type -P ${compilerBin}) \
      --build=${buildType} \
      --combined --skip-registry=all"
    echo $buildCMD
    $buildCMD
    runHook postBuild
  '';
  checkPhase = ''
    runHook preCheck
    dub test --combined --skip-registry=all
    runHook postCheck
  '';
  installPhase = ''
    runHook preInstall
    mkdir -p $out/cgi-bin
    install -m755 -D ./cgi-bin/spine_search $out/cgi-bin/spine_search
    runHook postInstall
  '';
  postInstall = ''
    echo `ls -la $out/cgi-bin/spine_search`
  '';
  meta = {
    description = "CGI search interface for spine document collections";
    homepage    = "https://sisudoc.org";
    license     = lib.licenses.agpl3Plus;
    platforms   = lib.platforms.linux;
    mainProgram = "spine_search";
  };
}