summaryrefslogtreecommitdiff
path: root/nix/package.nix
blob: d0777400c3161b2ba8daa41e8a642d141d39b74d (plain) (blame)
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
{
  buildPackages,
  lib,
  openssl,
  stdenv,
  tcl,
  zlib,
  sources ? import ../npins,
}:

let
  version = lib.removeSuffix "\n" (builtins.readFile ../VERSION);
in
stdenv.mkDerivation {
  pname = "copland-fossil";
  version = "${version}-copland";

  src = lib.cleanSourceWith {
    name = "copland-fossil-source";
    src = ../.;
    filter = path: type:
      let
        name = baseNameOf (toString path);
      in
      lib.cleanSourceFilter path type
      && !(builtins.elem name [
        ".agents"
        ".build"
        ".codex"
        ".copland-preview"
        ".fslckout"
        ".references"
        ".repository"
        "jimsh0"
        "nix"
        "node_modules"
        "npins"
        "playwright-report"
        "result"
        "test-output"
      ]);
  };

  nativeBuildInputs = [ tcl ];
  buildInputs = [ openssl zlib ];

  configurePhase = ''
    runHook preConfigure
    mkdir build
    cd build
    CC_FOR_BUILD=${buildPackages.stdenv.cc}/bin/cc \
      ../configure --disable-fusefs --json \
        ${lib.optionalString stdenv.hostPlatform.isStatic "--static"} \
        --prefix="$out"
    runHook postConfigure
  '';

  buildPhase = ''
    runHook preBuild
    make -j''${NIX_BUILD_CORES:-1} fossil
    runHook postBuild
  '';

  doCheck = true;
  checkPhase = ''
    runHook preCheck
    make test TESTFLAGS='org.test wiki.test'
    runHook postCheck
  '';

  installPhase = ''
    runHook preInstall
    install -Dm755 fossil "$out/bin/fossil"
    install -Dm644 ../fossil.1 "$out/share/man/man1/fossil.1"

    testRoot="$(mktemp -d)"
    export HOME="$testRoot/home"
    export USER=builder
    export LOGNAME=builder
    mkdir -p "$HOME"
    "$out/bin/fossil" help test-org-render >/dev/null
    "$out/bin/fossil" test-org-render \
      ../tools/copland/tests/fixtures/org/all.org | grep -q 'class="org-document"'
    "$out/bin/fossil" test-builtin-get skins/copland/css.txt \
      | grep -q -- '--page-bg:'

    "$out/bin/fossil" init "$testRoot/fresh.fossil" >/dev/null
    printf 'GET /style.css HTTP/1.0\r\nHost: localhost\r\n\r\n' \
      | "$out/bin/fossil" test-http "$testRoot/fresh.fossil" \
      | grep -q -- '--page-bg:'
    rm -r "$testRoot"
    runHook postInstall
  '';

  meta = {
    description = "Copland's Fossil fork with native Org and the built-in Copland skin";
    homepage = "https://fossil-scm.org/";
    license = lib.licenses.bsd2;
    mainProgram = "fossil";
    platforms = lib.platforms.unix;
  };
}