-
-
Notifications
You must be signed in to change notification settings - Fork 14.5k
/
default.nix
166 lines (147 loc) · 3.79 KB
/
default.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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
{
lib,
beamPackages,
buildNpmPackage,
rustPlatform,
fetchFromGitHub,
nodejs,
runCommand,
nixosTests,
npm-lockfile-fix,
brotli,
tailwindcss,
esbuild,
...
}:
let
pname = "plausible";
version = "2.1.4";
mixEnv = "ce";
src = fetchFromGitHub {
owner = "plausible";
repo = "analytics";
rev = "v${version}";
hash = "sha256-wV2zzRKJM5pQ06pF8vt1ieFqv6s3HvCzNT5Hed29Owk=";
postFetch = ''
${lib.getExe npm-lockfile-fix} $out/assets/package-lock.json
sed -ie '
/defp deps do/ {
n
/\[/ a\
\{:rustler, ">= 0.0.0", optional: true \},
}
' $out/mix.exs
cat >> $out/config/config.exs <<EOF
config :mjml, Mjml.Native,
crate: :mjml_nif,
skip_compilation?: true
EOF
'';
};
assets = buildNpmPackage {
pname = "${pname}-assets";
inherit version;
src = "${src}/assets";
npmDepsHash = "sha256-Rf1+G9F/CMK09KEh022vHe02FADJtARKX4QEVbmvSqk=";
dontNpmBuild = true;
installPhase = ''
runHook preInstall
cp -r . "$out"
runHook postInstall
'';
};
tracker = buildNpmPackage {
pname = "${pname}-tracker";
inherit version;
src = "${src}/tracker";
npmDepsHash = "sha256-ng0YpBZc0vcg5Bsr1LmgXtzNCtNV6hJIgLt3m3yRdh4=";
dontNpmBuild = true;
installPhase = ''
runHook preInstall
cp -r . "$out"
runHook postInstall
'';
};
mixFodDeps = beamPackages.fetchMixDeps {
inherit
pname
version
src
mixEnv
;
hash = "sha256-N6cYlYwNss2FPYcljANJYbXobmLFauZ64F7Sf/+7Ctg=";
};
mjmlNif = rustPlatform.buildRustPackage {
pname = "mjml-native";
version = "";
src = "${mixFodDeps}/mjml/native/mjml_nif";
cargoHash = "sha256-W4r8W+JGTE6j4gDogL5Yulr0mbaXjDbwDTwhzMbbDcQ=";
doCheck = false;
env = {
RUSTLER_PRECOMPILED_FORCE_BUILD_ALL = "true";
RUSTLER_PRECOMPILED_GLOBAL_CACHE_PATH = "unused-but-required";
};
};
patchedMixFodDeps = runCommand mixFodDeps.name { } ''
mkdir $out
cp -r --no-preserve=mode ${mixFodDeps}/. $out
mkdir -p $out/mjml/priv/native
for lib in ${mjmlNif}/lib/*
do
# normalies suffix to .so, otherswise build would fail on darwin
file=''${lib##*/}
base=''${file%.*}
ln -s "$lib" $out/mjml/priv/native/$base.so
done
'';
in
beamPackages.mixRelease rec {
inherit
pname
version
src
mixEnv
;
nativeBuildInputs = [
nodejs
brotli
];
mixFodDeps = patchedMixFodDeps;
passthru = {
tests = {
inherit (nixosTests) plausible;
};
updateScript = ./update.sh;
inherit assets tracker;
};
env = {
APP_VERSION = version;
RUSTLER_PRECOMPILED_FORCE_BUILD_ALL = "true";
RUSTLER_PRECOMPILED_GLOBAL_CACHE_PATH = "unused-but-required";
};
preBuild = ''
rm -r assets tracker
cp --no-preserve=mode -r ${assets} assets
cp -r ${tracker} tracker
cat >> config/config.exs <<EOF
config :tailwind, path: "${lib.getExe tailwindcss}"
config :esbuild, path: "${lib.getExe esbuild}"
EOF
'';
postBuild = ''
npm run deploy --prefix ./tracker
# for external task you need a workaround for the no deps check flag
# https://github.com/phoenixframework/phoenix/issues/2690
mix do deps.loadpaths --no-deps-check, assets.deploy
mix do deps.loadpaths --no-deps-check, phx.digest priv/static
'';
meta = with lib; {
license = licenses.agpl3Plus;
homepage = "https://plausible.io/";
changelog = "https://github.com/plausible/analytics/blob/${src.rev}/CHANGELOG.md";
description = " Simple, open-source, lightweight (< 1 KB) and privacy-friendly web analytics alternative to Google Analytics";
mainProgram = "plausible";
maintainers = teams.cyberus.members;
platforms = platforms.unix;
};
}