about summary refs log tree commit diff
path: root/nixpkgs/pkgs/applications/editors/standardnotes
diff options
context:
space:
mode:
Diffstat (limited to 'nixpkgs/pkgs/applications/editors/standardnotes')
-rw-r--r--nixpkgs/pkgs/applications/editors/standardnotes/default.nix52
-rw-r--r--nixpkgs/pkgs/applications/editors/standardnotes/src.json13
-rw-r--r--nixpkgs/pkgs/applications/editors/standardnotes/update.nix54
3 files changed, 119 insertions, 0 deletions
diff --git a/nixpkgs/pkgs/applications/editors/standardnotes/default.nix b/nixpkgs/pkgs/applications/editors/standardnotes/default.nix
new file mode 100644
index 000000000000..461e8dc504dc
--- /dev/null
+++ b/nixpkgs/pkgs/applications/editors/standardnotes/default.nix
@@ -0,0 +1,52 @@
+{ callPackage, lib, stdenv, appimageTools, autoPatchelfHook, desktop-file-utils
+, fetchurl, libsecret  }:
+
+let
+  srcjson = builtins.fromJSON (builtins.readFile ./src.json);
+  version = srcjson.version;
+  pname = "standardnotes";
+  name = "${pname}-${version}";
+  throwSystem = throw "Unsupported system: ${stdenv.hostPlatform.system}";
+
+  src = fetchurl (srcjson.appimage.${stdenv.hostPlatform.system} or throwSystem);
+
+  appimageContents = appimageTools.extract {
+    inherit name src;
+  };
+
+  nativeBuildInputs = [ autoPatchelfHook desktop-file-utils ];
+
+in appimageTools.wrapType2 rec {
+  inherit name src;
+
+  extraPkgs = pkgs: with pkgs; [
+    libsecret
+  ];
+
+  extraInstallCommands = ''
+    # directory in /nix/store so readonly
+    cd $out
+    chmod -R +w $out
+    mv $out/bin/${name} $out/bin/${pname}
+
+    # fixup and install desktop file
+    ${desktop-file-utils}/bin/desktop-file-install --dir $out/share/applications \
+      --set-key Exec --set-value ${pname} ${appimageContents}/standard-notes.desktop
+    ln -s ${appimageContents}/usr/share/icons share
+  '';
+
+  passthru.updateScript = callPackage ./update.nix {};
+
+  meta = with lib; {
+    description = "A simple and private notes app";
+    longDescription = ''
+      Standard Notes is a private notes app that features unmatched simplicity,
+      end-to-end encryption, powerful extensions, and open-source applications.
+    '';
+    homepage = "https://standardnotes.org";
+    license = licenses.agpl3;
+    maintainers = with maintainers; [ mgregoire chuangzhu squalus ];
+    sourceProvenance = [ sourceTypes.binaryNativeCode ];
+    platforms = builtins.attrNames srcjson.appimage;
+  };
+}
diff --git a/nixpkgs/pkgs/applications/editors/standardnotes/src.json b/nixpkgs/pkgs/applications/editors/standardnotes/src.json
new file mode 100644
index 000000000000..19e8e545e149
--- /dev/null
+++ b/nixpkgs/pkgs/applications/editors/standardnotes/src.json
@@ -0,0 +1,13 @@
+{
+  "version": "3.154.1",
+  "appimage": {
+    "x86_64-linux": {
+      "url": "https://github.com/standardnotes/app/releases/download/%40standardnotes/desktop%403.154.1/standard-notes-3.154.1-linux-x86_64.AppImage",
+      "hash": "sha512-eMKrRCMVEpgtKLuLTIIOkwDVKmkFFWqlAg2UXs+h8axQwKyEnnA6dGaWfQvE/NSQwgWvmZRJZNMUE2atTc9AAw=="
+    },
+    "aarch64-linux": {
+      "url": "https://github.com/standardnotes/app/releases/download/%40standardnotes/desktop%403.154.1/standard-notes-3.154.1-linux-arm64.AppImage",
+      "hash": "sha512-6EllhNEaLPL/5Nmt1NxtU6x6wi7DnU+k7oyr1HaLWMmkE673vQTyYW+fyFRrxnyBUlmjG4i+ztWYEzxN8CBlqg=="
+    }
+  }
+}
diff --git a/nixpkgs/pkgs/applications/editors/standardnotes/update.nix b/nixpkgs/pkgs/applications/editors/standardnotes/update.nix
new file mode 100644
index 000000000000..7b5f6616602b
--- /dev/null
+++ b/nixpkgs/pkgs/applications/editors/standardnotes/update.nix
@@ -0,0 +1,54 @@
+{ writeScript
+, lib, curl, runtimeShell, jq, coreutils, moreutils, nix, gnused }:
+
+writeScript "update-standardnotes" ''
+  #!${runtimeShell}
+  PATH=${lib.makeBinPath [ jq curl nix coreutils moreutils gnused ]}
+
+  set -euo pipefail
+  set -x
+
+  tmpDir=$(mktemp -d)
+  srcJson=pkgs/applications/editors/standardnotes/src.json
+  jsonPath="$tmpDir"/latest
+
+  oldVersion=$(jq -r .version < "$srcJson")
+
+  curl https://api.github.com/repos/standardnotes/app/releases/latest > "$jsonPath"
+
+  tagName=$(jq -r .tag_name < "$jsonPath")
+
+  if [[ ! "$tagName" =~ "desktop" ]]; then
+    echo "latest release '$tagName' not a desktop release"
+    exit 1
+  fi
+
+  newVersion=$(jq -r .tag_name < "$jsonPath" | sed s,@standardnotes/desktop@,,g)
+
+  if [[ "$oldVersion" == "$newVersion" ]]; then
+    echo "version did not change"
+    exit 0
+  fi
+
+  function getDownloadUrl() {
+    jq -r ".assets[] | select(.name==\"standard-notes-$newVersion-$1.AppImage\") | .browser_download_url" < "$jsonPath"
+  }
+
+  function setJsonKey() {
+    jq "$1 = \"$2\"" "$srcJson" | sponge "$srcJson"
+  }
+
+  function updatePlatform() {
+    nixPlatform="$1"
+    upstreamPlatform="$2"
+    url=$(getDownloadUrl "$upstreamPlatform")
+    hash=$(nix-prefetch-url "$url" --type sha512)
+    sriHash=$(nix hash to-sri --type sha512 $hash)
+    setJsonKey .appimage[\""$nixPlatform"\"].url "$url"
+    setJsonKey .appimage[\""$nixPlatform"\"].hash "$sriHash"
+  }
+
+  updatePlatform x86_64-linux linux-x86_64
+  updatePlatform aarch64-linux linux-arm64
+  setJsonKey .version "$newVersion"
+''