summaryrefslogtreecommitdiffstats
path: root/pkgs/by-name/om/omnom/package.nix
blob: bd2ff886101f33c293c6910bd5aa768460e53f55 (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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
{
  lib,
  buildGoModule,
  fetchFromGitHub,
  nix-update-script,
  makeWrapper,
  nixosTests,

  # for addons
  buildNpmPackage,
  zip,
}:

buildGoModule (finalAttrs: {
  pname = "omnom";
  version = "0.9.0";

  src = fetchFromGitHub {
    owner = "asciimoo";
    repo = "omnom";
    tag = "v${finalAttrs.version}";
    hash = "sha256-cG+cAsarbDqi3BLrIiSnH4VQS0fdfyMgkvbQvzKUXNw=";
    fetchSubmodules = true;
  };

  vendorHash = "sha256-meToyr93nmKLZ//h8Gc0rp2hc4vOV9ULU+FbBXmbDv8=";

  passthru.updateScript = nix-update-script { };

  nativeBuildInputs = [ makeWrapper ];

  ldflags = [
    "-s"
    "-w"
  ];

  postInstall = ''
    mkdir -p $out/share/addons

    # Copy Firefox and Chrome addons
    cp -r ${finalAttrs.passthru.omnom-addons}/*.zip $out/share/addons

    mkdir -p $out/share/examples

    cp -r static templates $out/share
    cp config.yml_sample $out/share/examples/config.yml
  '';

  passthru = {
    omnom-addons = buildNpmPackage (finalAttrs': {
      pname = "omnom-addons";
      inherit (finalAttrs) version src;

      npmDepsHash = "sha256-CIzp6/mBTuSaEFv0lk3d/GZyq1VRDvCSoqrujz4AG/E=";
      sourceRoot = "${finalAttrs'.src.name}/ext";
      npmPackFlags = [ "--ignore-scripts" ];

      nativeBuildInputs = [ zip ];

      # Fix path for the `static` directory
      postConfigure = ''
        substituteInPlace webpack.config.js \
        --replace-fail '"..", ".."' '".."'
      '';

      postBuild = ''
        mkdir -p $out

        zip -r "$out/omnom_ext_src.zip" README.md src utils package* webpack.config.js

        pushd build
          zip "$out/omnom_ext_chrome.zip" ./* icons/* -x manifest_ff.json
          cp manifest_ff.json manifest.json
          zip "$out/omnom_ext_firefox.zip" ./* icons/* -x manifest_ff.json
        popd
      '';

      postCheck = ''
        npm run build-test
      '';
    });

    tests = nixosTests.omnom;
  };

  meta = {
    description = "Webpage bookmarking and snapshotting service";
    homepage = "https://omnom.zone/";
    downloadPage = "https://github.com/asciimoo/omnom";
    changelog = "https://github.com/asciimoo/omnom/releases/tag/v${finalAttrs.version}";
    license = lib.licenses.agpl3Only;
    teams = [ lib.teams.ngi ];
    mainProgram = "omnom";
  };
})