-
Notifications
You must be signed in to change notification settings - Fork 0
/
packages.nix
151 lines (121 loc) · 4.33 KB
/
packages.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
{inputs, ...}: {
perSystem = {
lib,
pkgs,
...
}: {
packages = let
src = inputs.filestash;
version = src.shortRev;
packageJson = let
orig = lib.importJSON "${src}/package.json";
in
removeAttrs orig ["devDependencies"]
// {
dependencies = orig.dependencies // orig.devDependencies;
};
packageJsonFile = pkgs.writers.writeJSON "package.json" packageJson;
meta = with lib; {
description = "🦄 A modern web client for SFTP, S3, FTP, WebDAV, Git, Minio, LDAP, CalDAV, CardDAV, Mysql, Backblaze, …";
homepage = https://github.com/mickael-kerjean/filestash;
license = licenses.agpl3Only;
maintainers = with maintainers; [dermetfan];
platforms = platforms.linux;
};
in rec {
frontend = pkgs.buildNpmPackage rec {
inherit src version meta;
pname = "${packageJson.name}-frontend";
postPatch = ''
cp --force ${packageJsonFile} package.json
ln --symbolic ${./package-lock.json} package-lock.json
'';
npmDepsHash = "sha256-NX54LLtaIgbKWhkt6o17hhrK3CFzdDQiGVbUc5/HKes=";
npmInstallFlags = "--legacy-peer-deps";
makeCacheWritable = true;
NODE_ENV = "production";
nativeBuildInputs = with pkgs; [python3];
installPhase = "cp --recursive server/ctrl/static/www $out";
passthru.generate-package-lock-json = pkgs.writeShellApplication {
name = "generate-package-lock-json";
runtimeInputs = with pkgs; [nodejs];
text = ''
tmp=$(mktemp --directory)
trap 'rm --recursive "$tmp"' EXIT
ln --symbolic ${src}/* ${src}/.* "$tmp"/
ln --symbolic --force ${packageJsonFile} "$tmp"/package.json
pushd "$tmp"
npm install --package-lock-only ${npmInstallFlags}
popd
mv "$tmp"/package-lock.json .
'';
};
};
backend = pkgs.buildGo121Module {
pname = "filestash-backend";
inherit src version;
meta =
meta
// {
mainProgram = "filestash";
};
vendorHash = "sha256-cbpvwMt3Qp0lmcOrHtkOIFIo9NjstqC/wYUjkckV8f4=";
ldflags = [
"-X github.com/mickael-kerjean/filestash/server/common.BUILD_DATE=${toString src.lastModified}"
"-X github.com/mickael-kerjean/filestash/server/common.BUILD_REF=${src.rev}"
];
tags = ["fts5"];
excludedPackages = [
"server/generator"
];
buildInputs = with pkgs; [
vips
libjpeg
libpng
libwebp
libraw
giflib
libheif
];
nativeBuildInputs = with pkgs; [pkg-config gotools];
prePatch = "cp --recursive ${frontend} server/ctrl/static/www";
patches = [./cgo-ldflags.patch];
patchFlags = "--strip=0";
# fix "imported and not used" errors
postPatch = "goimports -w server";
preBuild = "go generate -x ./server/...";
postInstall = ''
rm $out/bin/public
mv $out/bin/{cmd,filestash}
'';
};
full =
pkgs.runCommand "filestash" {
inherit (backend) meta;
nativeBuildInputs = [pkgs.makeBinaryWrapper];
pathConfig = "/proc/self/cwd/state/config.json";
pathDb = "/proc/self/cwd/state/db";
pathLog = "/proc/self/cwd/state/log";
pathSearch = "/proc/self/cwd/state/search";
pathCert = "/proc/self/cwd/state/certs";
pathTmp = "/proc/self/cwd/cache";
} ''
mkdir --parents $out/bin
ln --symbolic ${backend}/bin/filestash $out/bin/filestash
wrapProgram $out/bin/filestash \
--set-default FILESTASH_PATH $out/libexec/filestash
mkdir --parents $out/libexec/filestash
pushd $out/libexec/filestash
mkdir --parents state/config
ln --symbolic ${frontend} public
ln --symbolic "$pathConfig" state/config/config.json
ln --symbolic "$pathDb" state/db
ln --symbolic "$pathLog" state/log
ln --symbolic "$pathSearch" state/search
ln --symbolic "$pathCert" state/certs
ln --symbolic "$pathTmp" cache
'';
default = full;
};
};
}