openbooks: init at 4.5.0

This commit is contained in:
Bruno BELANYI 2025-05-01 19:50:09 +01:00
parent 0d149c1c31
commit 5b1167fd14
4 changed files with 124 additions and 0 deletions

View file

@ -0,0 +1,17 @@
{ lib, fetchFromGitHub }:
rec {
version = "4.5.0";
src = fetchFromGitHub {
owner = "evan-buss";
repo = "openbooks";
rev = "v${version}";
hash = "sha256-gznaMcj8/9xW8wvz/pQaw4tY/hDW8K6duFfJD74E47E=";
};
meta = with lib; {
homepage = "https://evan-buss.github.io/openbooks/";
license = licenses.mit;
maintainers = with maintainers; [ ambroisie ];
};
}

View file

@ -0,0 +1,27 @@
{
buildNpmPackage,
callPackage,
}:
let
common = callPackage ./common.nix { };
in
buildNpmPackage {
pname = "openbooks-frontend";
inherit (common) version;
src = "${common.src}/server/app";
npmDepsHash = "sha256-OtXPOFK18b6tzFIvXkThafLUw0GlioRmxjzcKYeTalU=";
installPhase = ''
runHook preInstall
cp -r dist $out
runHook postInstall
'';
meta = common.meta // {
description = "openbooks frontend";
};
}

View file

@ -0,0 +1,34 @@
{
lib,
buildGoModule,
callPackage,
fetchFromGitHub,
}:
let
common = callPackage ./common.nix { };
frontend = callPackage ./frontend.nix { };
in
buildGoModule (finalAttrs: {
pname = "openbooks";
inherit (common) version src;
vendorHash = "sha256-ETN5oZanDH7fOAVnfIHIoXyVof7CfEMkPSOHF2my5ys=";
postPatch = ''
cp -r ${finalAttrs.passthru.frontend} server/app/dist/
'';
subPackages = [ "cmd/openbooks" ];
passthru = {
inherit frontend;
updateScript = ./update.sh;
};
meta = common.meta // {
description = "Search and Download eBooks";
mainProgram = "openbooks";
};
})

View file

@ -0,0 +1,46 @@
#!/usr/bin/env nix-shell
#!nix-shell -i bash -p nix wget prefetch-npm-deps nix-prefetch-github nurl jq
# shellcheck shell=bash
if [ -n "${GITHUB_TOKEN:-}" ]; then
TOKEN_ARGS=(--header "Authorization: token $GITHUB_TOKEN")
fi
if [ "$#" -gt 1 ] || [[ $1 == -* ]]; then
echo "Regenerates packaging data for the openbooks package."
echo "Usage: $0 [git release tag]"
exit 1
fi
version="$1"
rev="v$version"
set -euo pipefail
NIXPKGS_ROOT="$(git rev-parse --show-toplevel)"
if [ -z "$version" ]; then
rev="$(wget -O- "${TOKEN_ARGS[@]}" "https://api.github.com/repos/evan-buss/openbooks/releases?per_page=1" | jq -r '.[0].tag_name')"
version="${rev#v}"
fi
package_src="https://raw.githubusercontent.com/evan-buss/openbooks/$rev"
src_hash=$(nix-prefetch-github evan-buss openbooks --rev "$rev" | jq -r .hash)
tmpdir=$(mktemp -d)
trap 'rm -rf "$tmpdir"' EXIT
pushd "$tmpdir"
wget "${TOKEN_ARGS[@]}" "$package_src/server/app/package-lock.json"
npm_hash=$(prefetch-npm-deps package-lock.json)
popd
cd "$(dirname "${BASH_SOURCE[0]}")"
sed -i -E -e "s#version = \".*\"#version = \"$version\"#" common.nix
sed -i -E -e "s#hash = \".*\"#hash = \"$src_hash\"#" common.nix
sed -i -E -e "s#npmDepsHash = \".*\"#npmDepsHash = \"$npm_hash\"#" frontend.nix
vendor_hash=$(nurl -e "(import $NIXPKGS_ROOT/. { }).openbooks.goModules")
sed -i -E -e "s#vendorHash = \".*\"#vendorHash = \"$vendor_hash\"#" package.nix