gotify: refactor, use nix-update
This commit is contained in:
parent
154dc02a88
commit
5761b7411e
7 changed files with 47 additions and 191 deletions
|
@ -5,19 +5,18 @@
|
||||||
, sqlite
|
, sqlite
|
||||||
, callPackage
|
, callPackage
|
||||||
, nixosTests
|
, nixosTests
|
||||||
|
, nix-update-script
|
||||||
}:
|
}:
|
||||||
|
|
||||||
buildGoModule rec {
|
buildGoModule rec {
|
||||||
pname = "gotify-server";
|
pname = "gotify-server";
|
||||||
# should be update just like all other files imported like that via the
|
version = "2.2.4";
|
||||||
# `update.sh` script.
|
|
||||||
version = import ./version.nix;
|
|
||||||
|
|
||||||
src = fetchFromGitHub {
|
src = fetchFromGitHub {
|
||||||
owner = "gotify";
|
owner = "gotify";
|
||||||
repo = "server";
|
repo = "server";
|
||||||
rev = "v${version}";
|
rev = "v${version}";
|
||||||
sha256 = import ./source-sha.nix;
|
hash = "sha256-jhCS9UBzvOEoXTNw87wmUgTJb0/BP9TToifCDEuihM0=";
|
||||||
};
|
};
|
||||||
|
|
||||||
# With `allowGoReference = true;`, `buildGoModule` adds the `-trimpath`
|
# With `allowGoReference = true;`, `buildGoModule` adds the `-trimpath`
|
||||||
|
@ -26,20 +25,28 @@ buildGoModule rec {
|
||||||
# server[780]: stat /var/lib/private/ui/build/index.html: no such file or directory
|
# server[780]: stat /var/lib/private/ui/build/index.html: no such file or directory
|
||||||
allowGoReference = true;
|
allowGoReference = true;
|
||||||
|
|
||||||
vendorSha256 = import ./vendor-sha.nix;
|
vendorHash = "sha256-TxxiyfWzlzQ2R2hgeBzB11FIiOz5rIBfaIm15DQ+dL0=";
|
||||||
|
|
||||||
doCheck = false;
|
doCheck = false;
|
||||||
|
|
||||||
buildInputs = [ sqlite ];
|
buildInputs = [
|
||||||
|
sqlite
|
||||||
|
];
|
||||||
|
|
||||||
ui = callPackage ./ui.nix { };
|
ui = callPackage ./ui.nix { };
|
||||||
|
|
||||||
preBuild = ''
|
preBuild = ''
|
||||||
cp -r ${ui}/libexec/gotify-ui/deps/gotify-ui/build ui/build && go run hack/packr/packr.go
|
if [ -n "$ui" ] # to make the preBuild a no-op inside the goModules fixed-output derivation, where it would fail
|
||||||
|
then
|
||||||
|
cp -r $ui ui/build && go run hack/packr/packr.go
|
||||||
|
fi
|
||||||
'';
|
'';
|
||||||
|
|
||||||
passthru = {
|
passthru = {
|
||||||
updateScript = ./update.sh;
|
# For nix-update to detect the location of this attribute from this
|
||||||
|
# derivation.
|
||||||
|
inherit (ui) offlineCache;
|
||||||
|
updateScript = nix-update-script { };
|
||||||
tests = {
|
tests = {
|
||||||
nixos = nixosTests.gotify-server;
|
nixos = nixosTests.gotify-server;
|
||||||
};
|
};
|
||||||
|
@ -60,5 +67,4 @@ buildGoModule rec {
|
||||||
maintainers = with maintainers; [ doronbehar ];
|
maintainers = with maintainers; [ doronbehar ];
|
||||||
mainProgram = "server";
|
mainProgram = "server";
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,87 +0,0 @@
|
||||||
{
|
|
||||||
"name": "gotify-ui",
|
|
||||||
"version": "0.2.0",
|
|
||||||
"private": true,
|
|
||||||
"homepage": ".",
|
|
||||||
"proxy": "http://localhost:80",
|
|
||||||
"dependencies": {
|
|
||||||
"@material-ui/core": "^4.11.4",
|
|
||||||
"@material-ui/icons": "^4.9.1",
|
|
||||||
"axios": "^0.21.1",
|
|
||||||
"codemirror": "^5.61.1",
|
|
||||||
"detect-browser": "^5.2.0",
|
|
||||||
"js-base64": "^3.6.1",
|
|
||||||
"mobx": "^5.15.6",
|
|
||||||
"mobx-react": "^6.3.0",
|
|
||||||
"mobx-utils": "^5.6.1",
|
|
||||||
"notifyjs": "^3.0.0",
|
|
||||||
"prop-types": "^15.6.2",
|
|
||||||
"react": "^16.4.2",
|
|
||||||
"react-codemirror2": "^7.2.1",
|
|
||||||
"react-dom": "^16.4.2",
|
|
||||||
"react-infinite": "^0.13.0",
|
|
||||||
"react-markdown": "^6.0.2",
|
|
||||||
"react-router": "^5.2.0",
|
|
||||||
"react-router-dom": "^5.2.0",
|
|
||||||
"react-timeago": "^6.2.1",
|
|
||||||
"remark-gfm": "^1.0.0",
|
|
||||||
"remove-markdown": "^0.3.0",
|
|
||||||
"typeface-roboto": "1.1.13"
|
|
||||||
},
|
|
||||||
"scripts": {
|
|
||||||
"start": "react-scripts start",
|
|
||||||
"build": "react-scripts build",
|
|
||||||
"test": "react-scripts test --env=node",
|
|
||||||
"eject": "react-scripts eject",
|
|
||||||
"lint": "eslint \"src/**/*.{ts,tsx}\"",
|
|
||||||
"format": "prettier \"src/**/*.{ts,tsx}\" --write",
|
|
||||||
"testformat": "prettier \"src/**/*.{ts,tsx}\" --list-different"
|
|
||||||
},
|
|
||||||
"devDependencies": {
|
|
||||||
"@types/codemirror": "5.60.0",
|
|
||||||
"@types/detect-browser": "^4.0.0",
|
|
||||||
"@types/get-port": "^4.0.0",
|
|
||||||
"@types/jest": "^26.0.23",
|
|
||||||
"@types/js-base64": "^3.3.1",
|
|
||||||
"@types/node": "^15.12.2",
|
|
||||||
"@types/notifyjs": "^3.0.2",
|
|
||||||
"@types/puppeteer": "^5.4.6",
|
|
||||||
"@types/react": "^16.9.49",
|
|
||||||
"@types/react-dom": "^16.9.8",
|
|
||||||
"@types/react-infinite": "0.0.35",
|
|
||||||
"@types/react-router-dom": "^5.1.7",
|
|
||||||
"@types/remove-markdown": "^0.3.0",
|
|
||||||
"@types/rimraf": "^3.0.0",
|
|
||||||
"@typescript-eslint/eslint-plugin": "^4.1.0",
|
|
||||||
"@typescript-eslint/parser": "^4.1.0",
|
|
||||||
"eslint-config-prettier": "^6.11.0",
|
|
||||||
"eslint-plugin-import": "^2.22.0",
|
|
||||||
"eslint-plugin-jest": "^24.0.0",
|
|
||||||
"eslint-plugin-prefer-arrow": "^1.2.2",
|
|
||||||
"eslint-plugin-react": "^7.20.6",
|
|
||||||
"eslint-plugin-unicorn": "^21.0.0",
|
|
||||||
"get-port": "^5.1.1",
|
|
||||||
"prettier": "^2.3.1",
|
|
||||||
"puppeteer": "^17.1.3",
|
|
||||||
"react-scripts": "^4.0.3",
|
|
||||||
"rimraf": "^3.0.2",
|
|
||||||
"tree-kill": "^1.2.0",
|
|
||||||
"typescript": "4.0.2",
|
|
||||||
"wait-on": "^5.3.0"
|
|
||||||
},
|
|
||||||
"eslintConfig": {
|
|
||||||
"extends": "react-app"
|
|
||||||
},
|
|
||||||
"browserslist": {
|
|
||||||
"production": [
|
|
||||||
">0.2%",
|
|
||||||
"not dead",
|
|
||||||
"not op_mini all"
|
|
||||||
],
|
|
||||||
"development": [
|
|
||||||
"last 1 chrome version",
|
|
||||||
"last 1 firefox version",
|
|
||||||
"last 1 safari version"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1 +0,0 @@
|
||||||
"1kc4l95hrhi7lb9x8gy19xpwj12j4syg6w1kbllf3g3k83sr444f"
|
|
|
@ -1,67 +1,47 @@
|
||||||
{ yarn2nix-moretea
|
{ stdenv
|
||||||
, fetchFromGitHub, applyPatches
|
, yarn
|
||||||
|
, fixup_yarn_lock
|
||||||
|
, nodejs-slim
|
||||||
|
, fetchFromGitHub
|
||||||
, fetchYarnDeps
|
, fetchYarnDeps
|
||||||
|
, gotify-server
|
||||||
}:
|
}:
|
||||||
|
|
||||||
yarn2nix-moretea.mkYarnPackage rec {
|
stdenv.mkDerivation rec {
|
||||||
pname = "gotify-ui";
|
pname = "gotify-ui";
|
||||||
|
inherit (gotify-server) version;
|
||||||
|
|
||||||
packageJSON = ./package.json;
|
src = gotify-server.src + "/ui";
|
||||||
|
|
||||||
offlineCache = fetchYarnDeps {
|
offlineCache = fetchYarnDeps {
|
||||||
yarnLock = "${src}/yarn.lock";
|
yarnLock = "${src}/yarn.lock";
|
||||||
hash = "sha256-ejHzo6NHCMlNiYePWvfMY9Blb58pj3UQ5PFI0V84flI=";
|
hash = "sha256-ejHzo6NHCMlNiYePWvfMY9Blb58pj3UQ5PFI0V84flI=";
|
||||||
};
|
};
|
||||||
|
|
||||||
version = import ./version.nix;
|
nativeBuildInputs = [ yarn fixup_yarn_lock nodejs-slim ];
|
||||||
|
|
||||||
src_all = applyPatches {
|
postPatch = ''
|
||||||
src = fetchFromGitHub {
|
export HOME=$NIX_BUILD_TOP/fake_home
|
||||||
owner = "gotify";
|
yarn config --offline set yarn-offline-mirror $offlineCache
|
||||||
repo = "server";
|
fixup_yarn_lock yarn.lock
|
||||||
rev = "v${version}";
|
yarn install --offline --frozen-lockfile --ignore-scripts --no-progress --non-interactive
|
||||||
sha256 = import ./source-sha.nix;
|
patchShebangs node_modules/
|
||||||
};
|
|
||||||
postPatch = ''
|
|
||||||
substituteInPlace ui/yarn.lock \
|
|
||||||
--replace \
|
|
||||||
"https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001237.tgz" \
|
|
||||||
"https___registry.npmjs.org_caniuse_lite___caniuse_lite_1.0.30001237.tgz"
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
src = "${src_all}/ui";
|
|
||||||
|
|
||||||
buildPhase = ''
|
|
||||||
export HOME=$(mktemp -d)
|
|
||||||
export WRITABLE_NODE_MODULES="$(pwd)/tmp"
|
|
||||||
export NODE_OPTIONS=--openssl-legacy-provider
|
|
||||||
mkdir -p "$WRITABLE_NODE_MODULES"
|
|
||||||
|
|
||||||
# react-scripts requires a writable node_modules/.cache, so we have to copy the symlink's contents back
|
|
||||||
# into `node_modules/`.
|
|
||||||
# See https://github.com/facebook/create-react-app/issues/11263
|
|
||||||
cd deps/gotify-ui
|
|
||||||
node_modules="$(readlink node_modules)"
|
|
||||||
rm node_modules
|
|
||||||
mkdir -p "$WRITABLE_NODE_MODULES"/.cache
|
|
||||||
cp -r $node_modules/* "$WRITABLE_NODE_MODULES"
|
|
||||||
|
|
||||||
# In `node_modules/.bin` are relative symlinks that would be broken after copying them over,
|
|
||||||
# so we take care of them here.
|
|
||||||
mkdir -p "$WRITABLE_NODE_MODULES"/.bin
|
|
||||||
for x in "$node_modules"/.bin/*; do
|
|
||||||
ln -sfv "$node_modules"/.bin/"$(readlink "$x")" "$WRITABLE_NODE_MODULES"/.bin/"$(basename "$x")"
|
|
||||||
done
|
|
||||||
|
|
||||||
ln -sfv "$WRITABLE_NODE_MODULES" node_modules
|
|
||||||
cd ../..
|
|
||||||
|
|
||||||
yarn build
|
|
||||||
|
|
||||||
cd deps/gotify-ui
|
|
||||||
rm -rf node_modules
|
|
||||||
ln -sf $node_modules node_modules
|
|
||||||
cd ../..
|
|
||||||
'';
|
'';
|
||||||
|
|
||||||
|
buildPhase = ''
|
||||||
|
runHook preBuild
|
||||||
|
|
||||||
|
export NODE_OPTIONS=--openssl-legacy-provider
|
||||||
|
yarn --offline build
|
||||||
|
|
||||||
|
runHook postBuild
|
||||||
|
'';
|
||||||
|
|
||||||
|
installPhase = ''
|
||||||
|
runHook preInstall
|
||||||
|
|
||||||
|
mv build $out
|
||||||
|
|
||||||
|
runHook postInstall
|
||||||
|
'';
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,40 +0,0 @@
|
||||||
#!/usr/bin/env nix-shell
|
|
||||||
#!nix-shell -i bash -p wget yarn2nix-moretea.yarn2nix nix-prefetch-git jq
|
|
||||||
|
|
||||||
set -euo pipefail
|
|
||||||
|
|
||||||
dirname="$(dirname "$0")"
|
|
||||||
|
|
||||||
latest_release=$(curl --silent https://api.github.com/repos/gotify/server/releases/latest)
|
|
||||||
version=$(jq -r '.tag_name' <<<"$latest_release")
|
|
||||||
echo got version $version
|
|
||||||
echo \""${version#v}"\" > "$dirname/version.nix"
|
|
||||||
printf '%s\n' $(nix-prefetch-git --quiet --rev ${version} https://github.com/gotify/server | jq .sha256) > $dirname/source-sha.nix
|
|
||||||
tput setaf 1
|
|
||||||
echo zeroing vendorSha256 in $dirname/vendor-sha.nix
|
|
||||||
tput sgr0
|
|
||||||
printf '"%s"\n' "0000000000000000000000000000000000000000000000000000" > $dirname/vendor-sha.nix
|
|
||||||
|
|
||||||
GOTIFY_WEB_SRC="https://raw.githubusercontent.com/gotify/server/$version"
|
|
||||||
|
|
||||||
curl --silent "$GOTIFY_WEB_SRC/ui/package.json" -o $dirname/package.json
|
|
||||||
echo downloaded package.json
|
|
||||||
curl --silent "$GOTIFY_WEB_SRC/ui/yarn.lock" -o $dirname/yarn.lock
|
|
||||||
echo downloaded yarndeps.nix
|
|
||||||
echo running yarn2nix
|
|
||||||
yarn2nix --lockfile=$dirname/yarn.lock > $dirname/yarndeps.nix
|
|
||||||
rm $dirname/yarn.lock
|
|
||||||
echo removed yarn.lock
|
|
||||||
|
|
||||||
echo running nix-build for ui
|
|
||||||
nix-build -A gotify-server.ui
|
|
||||||
echo running nix-build for gotify itself in order to get vendorSha256
|
|
||||||
set +e
|
|
||||||
vendorSha256="$(nix-build -A gotify-server 2>&1 | grep "got:" | cut -d':' -f2)"
|
|
||||||
set -e
|
|
||||||
printf '"%s"\n' "$vendorSha256" > $dirname/vendor-sha.nix
|
|
||||||
tput setaf 2
|
|
||||||
echo got vendorSha256 of: $vendorSha256
|
|
||||||
tput sgr0
|
|
||||||
echo running nix-build -A gotify-server which should build gotify-server normally
|
|
||||||
nix-build -A gotify-server
|
|
|
@ -1 +0,0 @@
|
||||||
"sha256-TxxiyfWzlzQ2R2hgeBzB11FIiOz5rIBfaIm15DQ+dL0="
|
|
|
@ -1 +0,0 @@
|
||||||
"2.2.4"
|
|
Loading…
Reference in a new issue