summaryrefslogtreecommitdiffstats
path: root/pkgs/by-name/ti/tiny-rdm/package.nix
blob: acfac3947220b89e0e6f6fb48976bf4318857c5c (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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
{
  lib,
  buildGoModule,
  fetchFromGitHub,
  fetchNpmDeps,
  imagemagick,
  npmHooks,
  nodejs,
  wails,
  webkitgtk_4_1,
  pkg-config,
  copyDesktopItems,
  makeDesktopItem,
  autoPatchelfHook,
  writeScript,
}:

buildGoModule (finalAttrs: {
  pname = "tiny-rdm";
  version = "1.2.7";

  src = fetchFromGitHub {
    owner = "tiny-craft";
    repo = "tiny-rdm";
    tag = "v${finalAttrs.version}";
    hash = "sha256-MyIMGgKzP6SnRzlOd4OQvMNiih7lsjfVFFckkPS2J+w=";
  };

  postPatch = ''
    substituteInPlace frontend/src/App.vue \
      --replace-fail "prefStore.autoCheckUpdate" "false"
  '';

  vendorHash = "sha256-DaD/NM1ZNVt0X/CJuaGfHqeS9ySTWFd0y5bzog6Yn+E=";

  env = {
    CGO_ENABLED = 1;
    npmDeps = fetchNpmDeps {
      src = "${finalAttrs.src}/frontend";
      hash = "sha256-DUYUk4OK5UWDanSR5hSVDYloYX4fYD41omYThzi/700=";
    };
    npmRoot = "frontend";
  };

  nativeBuildInputs = [
    wails
    pkg-config
    autoPatchelfHook
    nodejs
    npmHooks.npmConfigHook
    copyDesktopItems
    imagemagick
  ];

  buildInputs = [ webkitgtk_4_1 ];

  buildPhase = ''
    runHook preBuild

    wails build -m -trimpath -devtools -tags webkit2_41 -o tiny-rdm

    runHook postBuild
  '';

  desktopItems = [
    (makeDesktopItem {
      name = "tiny-rdm";
      exec = "tiny-rdm %U";
      icon = "tiny-rdm";
      type = "Application";
      terminal = false;
      desktopName = "Tiny RDM";
      startupWMClass = "tinyrdm";
      categories = [ "Office" ];
      mimeTypes = [ "x-scheme-handler/tinyrdm" ];
      comment = "Tiny Redis Desktop Manager";
    })
  ];

  installPhase = ''
    runHook preInstall

    install -Dm 0755 build/bin/tiny-rdm $out/bin/tiny-rdm
    mkdir -p $out/share/icons/hicolor/96x96/apps
    magick frontend/src/assets/images/icon.png -resize 96x96 $out/share/icons/hicolor/96x96/apps/tiny-rdm.png

    runHook postInstall
  '';

  passthru = {
    inherit (finalAttrs.env) npmDeps;
    updateScript = writeScript "update-tiny-rdm" ''
      #!/usr/bin/env nix-shell
      #!nix-shell -i bash -p bash nix nix-update common-updater-scripts
      set -eou pipefail
      version=$(nix eval --log-format raw --raw --file default.nix tiny-rdm.version)
      nix-update tiny-rdm || true
      latestVersion=$(nix eval --log-format raw --raw --file default.nix tiny-rdm.version)
      if [[ "$latestVersion" == "$version" ]]; then
        exit 0
      fi
      update-source-version tiny-rdm "$latestVersion" --source-key=npmDeps --ignore-same-version
      nix-update tiny-rdm --version skip
    '';
  };

  meta = {
    description = "Modern, colorful, super lightweight Redis GUI client";
    homepage = "https://github.com/tiny-craft/tiny-rdm";
    mainProgram = "tiny-rdm";
    license = lib.licenses.gpl3Plus;
    maintainers = [ ];
    platforms = lib.platforms.linux;
  };
})