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
167
168
169
170
|
{ stdenv
, lib
, nixosTests
, fetchFromGitHub
, fetchYarnDeps
, applyPatches
, bundlerEnv
, defaultGemConfig
, callPackage
, writeText
, procps
, ruby
, postgresql
, imlib2
, jq
, moreutils
, nodejs
, yarn
, yarn2nix-moretea
, v8
, cacert
, redis
}:
let
pname = "zammad";
version = "6.2.0";
src = applyPatches {
src = fetchFromGitHub (lib.importJSON ./source.json);
patches = [
./0001-nulldb.patch
./fix-sendmail-location.diff
];
postPatch = ''
sed -i -e "s|ruby '3.1.[0-9]\+'|ruby '${ruby.version}'|" Gemfile
sed -i -e "s|ruby 3.1.[0-9]\+p[0-9]\+|ruby ${ruby.version}|" Gemfile.lock
sed -i -e "s|3.1.[0-9]\+|${ruby.version}|" .ruby-version
${jq}/bin/jq '. += {name: "Zammad", version: "${version}"}' package.json | ${moreutils}/bin/sponge package.json
'';
};
databaseConfig = writeText "database.yml" ''
production:
url: <%= ENV['DATABASE_URL'] %>
'';
secretsConfig = writeText "secrets.yml" ''
production:
secret_key_base: <%= ENV['SECRET_KEY_BASE'] %>
'';
rubyEnv = bundlerEnv {
name = "${pname}-gems-${version}";
inherit version;
# Which ruby version to select:
# https://docs.zammad.org/en/latest/prerequisites/software.html#ruby-programming-language
inherit ruby;
gemdir = src;
gemset = ./gemset.nix;
groups = [
"assets"
"unicorn" # server
"nulldb"
"test"
"mysql"
"puma"
"development"
"postgres" # database
];
gemConfig = defaultGemConfig // {
pg = attrs: {
buildFlags = [ "--with-pg-config=${postgresql}/bin/pg_config" ];
};
rszr = attrs: {
buildInputs = [ imlib2 imlib2.dev ];
buildFlags = [ "--without-imlib2-config" ];
};
mini_racer = attrs: {
buildFlags = [
"--with-v8-dir=\"${v8}\""
];
dontBuild = false;
postPatch = ''
substituteInPlace ext/mini_racer_extension/extconf.rb \
--replace Libv8.configure_makefile '$CPPFLAGS += " -x c++"; Libv8.configure_makefile'
'';
};
};
};
yarnEnv = yarn2nix-moretea.mkYarnPackage {
pname = "${pname}-node-modules";
inherit version src;
packageJSON = ./package.json;
offlineCache = fetchYarnDeps {
yarnLock = "${src}/yarn.lock";
hash = "sha256-u72ZTpcUvFa1gaWi4lzTQa+JsI85jU4n8r1JhqFnCj4=";
};
yarnPreBuild = ''
mkdir -p deps/Zammad
cp -r ${src}/.eslint-plugin-zammad deps/Zammad/.eslint-plugin-zammad
chmod -R +w deps/Zammad/.eslint-plugin-zammad
'';
};
in
stdenv.mkDerivation {
inherit pname version src;
buildInputs = [
rubyEnv
rubyEnv.wrappedRuby
rubyEnv.bundler
yarn
nodejs
procps
cacert
];
nativeBuildInputs = [
redis
];
RAILS_ENV = "production";
buildPhase = ''
node_modules=${yarnEnv}/libexec/Zammad/node_modules
${yarn2nix-moretea.linkNodeModulesHook}
mkdir redis-work
pushd redis-work
redis-server &
REDIS_PID=$!
popd
rake DATABASE_URL="nulldb://user:pass@127.0.0.1/dbname" assets:precompile
kill $REDIS_PID
rm -r redis-work
'';
installPhase = ''
cp -R . $out
cp ${databaseConfig} $out/config/database.yml
cp ${secretsConfig} $out/config/secrets.yml
sed -i -e "s|info|debug|" $out/config/environments/production.rb
'';
passthru = {
inherit rubyEnv yarnEnv;
updateScript = [ "${callPackage ./update.nix {}}/bin/update.sh" pname (toString ./.) ];
tests = { inherit (nixosTests) zammad; };
};
meta = with lib; {
description = "Zammad, a web-based, open source user support/ticketing solution.";
homepage = "https://zammad.org";
license = licenses.agpl3Plus;
platforms = [ "x86_64-linux" "aarch64-linux" ];
maintainers = with maintainers; [ n0emis taeer netali ];
};
}
|