nixpkgs/pkgs/applications/networking/misc/zammad/default.nix

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

178 lines
4.1 KiB
Nix
Raw Normal View History

{ stdenv
, lib
2023-05-13 10:38:05 +00:00
, nixosTests
, fetchFromGitHub
2023-09-06 04:44:24 +00:00
, fetchYarnDeps
2022-02-08 14:46:18 +00:00
, applyPatches
, bundlerEnv
, defaultGemConfig
, callPackage
, writeText
, procps
2023-05-12 17:43:48 +00:00
, ruby
, postgresql
, imlib2
2022-03-21 09:27:10 +00:00
, jq
, moreutils
, nodejs
, yarn
, yarn2nix-moretea
, cacert
2023-11-23 15:56:39 +00:00
, redis
}:
let
pname = "zammad";
version = "6.3.1";
2022-02-16 21:58:20 +00:00
src = applyPatches {
2022-02-08 14:46:18 +00:00
2022-02-22 12:38:01 +00:00
src = fetchFromGitHub (lib.importJSON ./source.json);
2022-02-08 14:46:18 +00:00
2023-06-10 11:42:42 +00:00
patches = [
./fix-sendmail-location.diff
];
2022-02-08 14:46:18 +00:00
postPatch = ''
sed -i -e "s|ruby '3.2.[0-9]\+'|ruby '${ruby.version}'|" Gemfile
sed -i -e "s|ruby 3.2.[0-9]\+p[0-9]\+|ruby ${ruby.version}|" Gemfile.lock
sed -i -e "s|3.2.[0-9]\+|${ruby.version}|" .ruby-version
2022-03-21 09:27:10 +00:00
${jq}/bin/jq '. += {name: "Zammad", version: "${version}"}' package.json | ${moreutils}/bin/sponge package.json
2022-02-08 14:46:18 +00:00
'';
};
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
2023-05-12 17:43:48 +00:00
inherit ruby;
2022-02-23 03:50:33 +00:00
gemdir = src;
gemset = ./gemset.nix;
groups = [
"assets"
2022-02-16 21:50:22 +00:00
"unicorn" # server
"test"
"mysql"
"puma"
"development"
2022-02-16 21:50:22 +00:00
"postgres" # database
];
gemConfig = defaultGemConfig // {
pg = attrs: {
buildFlags = [ "--with-pg-config=${lib.getDev postgresql}/bin/pg_config" ];
};
rszr = attrs: {
buildInputs = [ imlib2 imlib2.dev ];
2022-03-21 09:27:10 +00:00
buildFlags = [ "--without-imlib2-config" ];
};
mini_racer = attrs: {
buildFlags = [
2024-05-30 09:52:53 +00:00
"--with-v8-dir=\"${nodejs.libv8}\""
];
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";
2022-02-16 21:58:20 +00:00
inherit version src;
2022-02-23 03:50:33 +00:00
packageJSON = ./package.json;
2023-05-12 17:43:48 +00:00
2023-09-06 04:44:24 +00:00
offlineCache = fetchYarnDeps {
yarnLock = "${src}/yarn.lock";
hash = "sha256-3DuTirYd6lAQd5PRbdOa/6QaMknIqNMTVnxEESF0N/c=";
2023-09-06 04:44:24 +00:00
};
packageResolutions.minimatch = "9.0.3";
2023-05-12 17:43:48 +00:00
yarnPreBuild = ''
mkdir -p deps/Zammad
cp -r ${src}/.eslint-plugin-zammad deps/Zammad/.eslint-plugin-zammad
chmod -R +w deps/Zammad/.eslint-plugin-zammad
'';
};
2022-02-16 21:50:22 +00:00
in
stdenv.mkDerivation {
2022-02-16 21:58:20 +00:00
inherit pname version src;
buildInputs = [
rubyEnv
rubyEnv.wrappedRuby
rubyEnv.bundler
yarn
nodejs
procps
cacert
];
2023-11-23 15:56:39 +00:00
nativeBuildInputs = [
redis
postgresql
2023-11-23 15:56:39 +00:00
];
RAILS_ENV = "production";
buildPhase = ''
node_modules=${yarnEnv}/libexec/Zammad/node_modules
${yarn2nix-moretea.linkNodeModulesHook}
2023-11-23 15:56:39 +00:00
mkdir redis-work
pushd redis-work
redis-server &
REDIS_PID=$!
popd
mkdir postgres-work
initdb -D postgres-work --encoding=utf8
pg_ctl start -D postgres-work -o "-k $PWD/postgres-work -h '''"
createuser -h $PWD/postgres-work zammad -R -S
createdb -h $PWD/postgres-work --encoding=utf8 --owner=zammad zammad
rake DATABASE_URL="postgresql:///zammad?host=$PWD/postgres-work" assets:precompile
2023-11-23 15:56:39 +00:00
kill $REDIS_PID
pg_ctl stop -D postgres-work -m immediate
rm -r redis-work postgres-work
'';
installPhase = ''
2022-02-22 10:37:03 +00:00
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 ./.) ];
2023-05-13 10:38:05 +00:00
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;
2023-05-17 14:12:23 +00:00
platforms = [ "x86_64-linux" "aarch64-linux" ];
2023-11-23 15:56:39 +00:00
maintainers = with maintainers; [ n0emis taeer netali ];
};
}