2024-05-25 22:30:22 +02:00
{
2024-05-26 00:10:13 +02:00
stdenvNoCC ,
jq ,
moreutils ,
nodePackages ,
cacert ,
2024-05-25 22:30:22 +02:00
lib ,
2024-05-26 00:10:13 +02:00
buildGoModule ,
2024-05-25 22:30:22 +02:00
fetchFromGitHub ,
2024-05-26 00:10:13 +02:00
} : let
pname = " h o m e b o x " ;
2024-05-25 22:30:22 +02:00
version = " 0 . 1 0 . 3 " ;
src = " ${ fetchFromGitHub {
owner = " h a y - k o t " ;
repo = " h o m e b o x " ;
rev = " v ${ version } " ;
2024-05-26 00:10:13 +02:00
hash = " s h a 2 5 6 - H e j / d M 0 B g t R W i M O p p / S D V r 3 H 1 I b Y b 9 3 5 T 1 p f X 8 a p j p E = " ;
# Inspired by: https://github.com/NixOS/nixpkgs/blob/f2d7a289c5a5ece8521dd082b81ac7e4a57c2c5c/pkgs/applications/graphics/pdfcpu/default.nix#L20-L32
# The intention here is to write the information into files in the `src`'s
# `$out`, and use them later in other phases (in this case `preBuild`).
# In order to keep determinism, we also delete the `.git` directory
# afterwards, imitating the default behavior of `leaveDotGit = false`.
# More info about git log format can be found at `git-log(1)` manpage.
leaveDotGit = true ;
postFetch = ''
cd " $ o u t "
git log -1 - - pretty = % H > " b a c k e n d / C O M M I T "
git log -1 - - pretty = % cd - - date = format:'%Y-%m-%dT%H:%M:%SZ' > " b a c k e n d / S O U R C E _ D A T E "
rm - rf " . g i t "
'' ;
} } " ;
frontend = stdenvNoCC . mkDerivation {
pname = " ${ pname } - f r o n t e n d " ;
inherit version ;
src = " ${ src } / f r o n t e n d " ;
preBuild = ''
export HOME = $ ( mktemp - d )
export STORE_PATH = $ ( mktemp - d )
2024-05-25 22:30:22 +02:00
2024-05-26 00:10:13 +02:00
pnpm config set store-dir " ${ pnpm-deps } "
pnpm install - - offline - - frozen-lockfile - - shamefully-hoist
patchShebangs node_modules / { * , . * }
'' ;
2024-05-25 22:30:22 +02:00
2024-05-26 00:10:13 +02:00
buildPhase = ''
runHook preBuild
2024-05-25 22:30:22 +02:00
2024-05-26 00:10:13 +02:00
pnpm build
2024-05-25 22:30:22 +02:00
2024-05-26 00:10:13 +02:00
runHook postBuild
'' ;
env . NUXT_TELEMETRY_DISABLED = 1 ;
2024-05-25 22:30:22 +02:00
2024-05-26 00:10:13 +02:00
nativeBuildInputs = [
nodePackages . pnpm
#breakpointHook
] ;
installPhase = ''
runHook preInstall
2024-05-25 22:30:22 +02:00
2024-05-26 00:10:13 +02:00
mkdir - p $ out
cp - r .output/public /* $ o u t /
runHook postInstall
'' ;
2024-05-25 22:30:22 +02:00
} ;
2024-05-26 00:10:13 +02:00
pnpm-deps = stdenvNoCC . mkDerivation {
pname = " ${ pname } - p n p m - d e p s " ;
inherit version ;
src = " ${ src } / f r o n t e n d " ;
nativeBuildInputs = [
jq
moreutils
nodePackages . pnpm
cacert
] ;
installPhase = ''
export HOME = $ ( mktemp - d )
pnpm config set store-dir $ out
# This version of the package has different versions of esbuild as a dependency.
# You can use the command below to get esbuild binaries for a specific platform and calculate hashes for that platforms. (linux, darwin for os, and x86, arm64, ia32 for cpu)
# cat package.json | jq '.pnpm.supportedArchitectures += { "os": ["linux"], "cpu": ["arm64"] }' | sponge package.json
pnpm install - - frozen-lockfile - - ignore-script
# Remove timestamp and sort the json files.
rm - rf $ out/v3/tmp
for f in $ ( find $ out - name " * . j s o n " ) ; do
sed - i - E - e ' s / " c h e c k e d A t " : [ 0 -9 ] + , // g' $ f
jq - - sort-keys . $ f | sponge $ f
done
'' ;
dontBuild = true ;
dontFixup = true ;
outputHashMode = " r e c u r s i v e " ;
outputHash = " s h a 2 5 6 - B V Z S d c 8 e 6 v + p a M z M Y a z E d n K S N w + O n C p j S z G S E K x V l 2 4 = " ;
} ;
in
buildGoModule {
inherit pname version ;
src = " ${ src } / b a c k e n d " ;
vendorHash = " s h a 2 5 6 - T t F z + d D p o M s 3 P A Q j i Y Q m 1 + Q 6 p r n 4 H i a f 7 x q W t 4 1 o Y 7 w = " ;
CGO_ENABLED = 0 ;
GOOS = " l i n u x " ;
doCheck = false ;
# options used by upstream:
# https://github.com/simulot/immich-go/blob/0.13.2/.goreleaser.yaml
ldflags = [
" - s "
" - w "
" - e x t l d f l a g s = - s t a t i c "
" - X m a i n . v e r s i o n = ${ version } "
] ;
preBuild = ''
ldflags + = " - X m a i n . c o m m i t = $ ( c a t C O M M I T ) "
ldflags + = " - X m a i n . d a t e = $ ( c a t S O U R C E _ D A T E ) "
mkdir - p ./app/api/static/public
cp - r $ { frontend } /* . / a p p / a p i / s t a t i c / p u b l i c
'' ;
meta = with lib ; {
2024-06-05 23:00:40 +02:00
mainProgram = " a p i " ;
2024-06-09 20:55:50 +02:00
homepage = " h t t p s : / / h a y - k o t . g i t h u b . i o / h o m e b o x / " ;
2024-06-05 23:00:40 +02:00
maintainers = with maintainers ; [ patrickdag ] ;
2024-06-09 20:55:50 +02:00
license = licenses . agpl3Only ;
description = " A i n v e n t o r y a n d o r g a n i z a t i o n s y s t e m b u i l t f o r t h e H o m e U s e r " ;
platforms = platforms . all ;
2024-05-26 00:10:13 +02:00
} ;
}