lol
1{ stdenv
2, lib
3, nixosTests
4, fetchFromGitHub
5, fetchYarnDeps
6, applyPatches
7, bundlerEnv
8, defaultGemConfig
9, callPackage
10, writeText
11, procps
12, ruby
13, postgresql
14, imlib2
15, jq
16, moreutils
17, nodejs
18, yarn
19, yarn2nix-moretea
20, v8
21, cacert
22}:
23
24let
25 pname = "zammad";
26 version = "5.4.1";
27
28 src = applyPatches {
29
30 src = fetchFromGitHub (lib.importJSON ./source.json);
31
32 patches = [
33 ./0001-nulldb.patch
34 ./fix-sendmail-location.diff
35 ];
36
37 postPatch = ''
38 sed -i -e "s|ruby '3.1.[0-9]\+'|ruby '${ruby.version}'|" Gemfile
39 sed -i -e "s|ruby 3.1.[0-9]\+p[0-9]\+|ruby ${ruby.version}|" Gemfile.lock
40 sed -i -e "s|3.1.[0-9]\+|${ruby.version}|" .ruby-version
41 ${jq}/bin/jq '. += {name: "Zammad", version: "${version}"}' package.json | ${moreutils}/bin/sponge package.json
42 '';
43 };
44
45 databaseConfig = writeText "database.yml" ''
46 production:
47 url: <%= ENV['DATABASE_URL'] %>
48 '';
49
50 secretsConfig = writeText "secrets.yml" ''
51 production:
52 secret_key_base: <%= ENV['SECRET_KEY_BASE'] %>
53 '';
54
55 rubyEnv = bundlerEnv {
56 name = "${pname}-gems-${version}";
57 inherit version;
58
59 # Which ruby version to select:
60 # https://docs.zammad.org/en/latest/prerequisites/software.html#ruby-programming-language
61 inherit ruby;
62
63 gemdir = src;
64 gemset = ./gemset.nix;
65 groups = [
66 "assets"
67 "unicorn" # server
68 "nulldb"
69 "test"
70 "mysql"
71 "puma"
72 "development"
73 "postgres" # database
74 ];
75 gemConfig = defaultGemConfig // {
76 pg = attrs: {
77 buildFlags = [ "--with-pg-config=${postgresql}/bin/pg_config" ];
78 };
79 rszr = attrs: {
80 buildInputs = [ imlib2 imlib2.dev ];
81 buildFlags = [ "--without-imlib2-config" ];
82 };
83 mini_racer = attrs: {
84 buildFlags = [
85 "--with-v8-dir=\"${v8}\""
86 ];
87 dontBuild = false;
88 postPatch = ''
89 substituteInPlace ext/mini_racer_extension/extconf.rb \
90 --replace Libv8.configure_makefile '$CPPFLAGS += " -x c++"; Libv8.configure_makefile'
91 '';
92 };
93 };
94 };
95
96 yarnEnv = yarn2nix-moretea.mkYarnPackage {
97 pname = "${pname}-node-modules";
98 inherit version src;
99 packageJSON = ./package.json;
100
101 offlineCache = fetchYarnDeps {
102 yarnLock = "${src}/yarn.lock";
103 hash = "sha256-HI4RR4/ll/zNBNtDCb8OvEsG/BMVYacM0CcYqbkNHEY=";
104 };
105
106 yarnPreBuild = ''
107 mkdir -p deps/Zammad
108 cp -r ${src}/.eslint-plugin-zammad deps/Zammad/.eslint-plugin-zammad
109 chmod -R +w deps/Zammad/.eslint-plugin-zammad
110 '';
111 };
112
113in
114stdenv.mkDerivation {
115 inherit pname version src;
116
117 buildInputs = [
118 rubyEnv
119 rubyEnv.wrappedRuby
120 rubyEnv.bundler
121 yarn
122 nodejs
123 procps
124 cacert
125 ];
126
127 RAILS_ENV = "production";
128
129 buildPhase = ''
130 node_modules=${yarnEnv}/libexec/Zammad/node_modules
131 ${yarn2nix-moretea.linkNodeModulesHook}
132
133 rake DATABASE_URL="nulldb://user:pass@127.0.0.1/dbname" assets:precompile
134 '';
135
136 installPhase = ''
137 cp -R . $out
138 cp ${databaseConfig} $out/config/database.yml
139 cp ${secretsConfig} $out/config/secrets.yml
140 sed -i -e "s|info|debug|" $out/config/environments/production.rb
141 '';
142
143 passthru = {
144 inherit rubyEnv yarnEnv;
145 updateScript = [ "${callPackage ./update.nix {}}/bin/update.sh" pname (toString ./.) ];
146 tests = { inherit (nixosTests) zammad; };
147 };
148
149 meta = with lib; {
150 description = "Zammad, a web-based, open source user support/ticketing solution.";
151 homepage = "https://zammad.org";
152 license = licenses.agpl3Plus;
153 platforms = [ "x86_64-linux" "aarch64-linux" ];
154 maintainers = with maintainers; [ n0emis garbas taeer ];
155 };
156}