Merge pull request #224355 from 5aaee9/master

This commit is contained in:
Sandro 2023-04-29 23:29:21 +02:00 committed by GitHub
commit 6f70b3d6bc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 6100 additions and 0 deletions

View file

@ -6696,6 +6696,12 @@
githubId = 55066419;
name = "Emily Lange";
};
indexyz = {
email = "indexyz@pm.me";
github = "5aaee9";
githubId = 7685264;
name = "Indexyz";
};
ineol = {
email = "leo.stefanesco@gmail.com";
github = "ineol";

View file

@ -0,0 +1,53 @@
{ fetchFromGitHub, buildGoModule, jq, buildNpmPackage, lib, makeWrapper }:
let
version = "0.12.2";
src = fetchFromGitHub {
owner = "usememos";
repo = "memos";
rev = "v${version}";
sha256 = "vAY++SHUMBw+jyuu6KFNt62kE5FM8ysGheQwBSOYos8=";
};
frontend = buildNpmPackage {
pname = "memos-web";
inherit version;
src = "${src}/web";
npmDepsHash = "sha256-vgO5HWbV/oR1GenK9q5a1bhlTSJqtF4HBcQTZ3DqZq8=";
postPatch = ''
cp ${./package-lock.json} package-lock.json
'';
installPhase = ''
cp -r dist $out
'';
};
in
buildGoModule rec {
pname = "memos";
inherit version src;
# check will unable to access network in sandbox
doCheck = false;
vendorSha256 = "sha256-P4OnICBiTAs/uaQgoYNKK50yj/PYntyH/bLihdPv88s=";
# Inject frontend assets into go embed
prePatch = ''
rm -rf server/dist
cp -r ${frontend} server/dist
'';
passthru = {
updateScript = ./update.sh;
};
meta = with lib; {
homepage = "https://usememos.com";
description = "A lightweight, self-hosted memo hub";
maintainers = with maintainers; [ indexyz ];
license = licenses.mit;
};
}

5983
pkgs/servers/memos/package-lock.json generated Normal file

File diff suppressed because it is too large Load diff

56
pkgs/servers/memos/update.sh Executable file
View file

@ -0,0 +1,56 @@
#!/usr/bin/env nix-shell
#!nix-shell -i bash -p nix wget nix-prefetch-github moreutils jq prefetch-npm-deps nodejs
set -euo pipefail
TARGET_VERSION_REMOTE=$(curl -s https://api.github.com/repos/usememos/memos/releases/latest | jq -r ".tag_name")
TARGET_VERSION=${TARGET_VERSION_REMOTE#v}
if [[ "$UPDATE_NIX_OLD_VERSION" == "$TARGET_VERSION" ]]; then
echo "memos is up-to-date: ${UPDATE_NIX_OLD_VERSION}"
exit 0
fi
extractVendorHash() {
original="${1?original hash missing}"
result="$(nix-build -A memos.go-modules 2>&1 | tail -n3 | grep 'got:' | cut -d: -f2- | xargs echo || true)"
[ -z "$result" ] && { echo "$original"; } || { echo "$result"; }
}
replaceHash() {
old="${1?old hash missing}"
new="${2?new hash missing}"
awk -v OLD="$old" -v NEW="$new" '{
if (i=index($0, OLD)) {
$0 = substr($0, 1, i-1) NEW substr($0, i+length(OLD));
}
print $0;
}' ./pkgs/servers/memos/default.nix | sponge ./pkgs/servers/memos/default.nix
}
# change version number
sed -e "s/version =.*;/version = \"$TARGET_VERSION\";/g" \
-i ./pkgs/servers/memos/default.nix
# update hash
SRC_HASH="$(nix-instantiate --eval -A memos.src.outputHash | tr -d '"')"
NEW_HASH="$(nix-prefetch-github usememos memos --rev v$TARGET_VERSION | jq -r .sha256)"
replaceHash "$SRC_HASH" "$NEW_HASH"
GO_HASH="$(nix-instantiate --eval -A memos.vendorSha256 | tr -d '"')"
EMPTY_HASH="$(nix-instantiate --eval -A lib.fakeSha256 | tr -d '"')"
replaceHash "$GO_HASH" "$EMPTY_HASH"
replaceHash "$EMPTY_HASH" "$(extractVendorHash "$GO_HASH")"
# update src yarn lock
SRC_FILE_BASE="https://raw.githubusercontent.com/usememos/memos/v$TARGET_VERSION"
trap 'rm -rf ./pkgs/servers/memos/package.json' EXIT
pushd ./pkgs/servers/memos
wget -q "$SRC_FILE_BASE/web/package.json"
npm install --package-lock-only
NPM_HASH=$(prefetch-npm-deps ./package-lock.json)
popd
sed -i -E -e "s#npmDepsHash = \".*\"#npmDepsHash = \"$NPM_HASH\"#" ./pkgs/servers/memos/default.nix

View file

@ -1594,6 +1594,8 @@ with pkgs;
metapixel = callPackage ../tools/graphics/metapixel { };
memos = callPackage ../servers/memos { };
midimonster = callPackage ../tools/audio/midimonster { };
midi-trigger = callPackage ../applications/audio/midi-trigger { };