nix: implement flake

This commit introduces the ability to install Docspell from a Nix flake.
There are no major changes to the logic of the previous modules outside of
organizing them in a flake and adding a simple check script.
This commit is contained in:
Vladimir Timofeenko
2022-11-28 13:45:34 -08:00
parent 1d39b5c74e
commit ae8bd1d85b
13 changed files with 360 additions and 511 deletions

View File

@ -0,0 +1,83 @@
{ config, pkgs, ... }:
let
full-text-search = {
enabled = true;
solr.url = "http://localhost:${toString config.services.solr.port}/solr/docspell";
postgresql = {
pg-config = {
"german" = "my-germam";
};
};
};
in
{
i18n = {
defaultLocale = "en_US.UTF-8";
};
console.keyMap = "de";
users.users.root = {
password = "root";
};
services.docspell-joex = {
enable = true;
waitForTarget = "solr-init.target";
bind.address = "0.0.0.0";
base-url = "http://localhost:7878";
jvmArgs = [ "-J-Xmx1536M" ];
inherit full-text-search;
};
services.docspell-restserver = {
enable = true;
bind.address = "0.0.0.0";
backend = {
addons.enabled = true;
};
integration-endpoint = {
enabled = true;
http-header = {
enabled = true;
header-value = "test123";
};
};
openid = [
{
enabled = true;
display = "Local";
provider = {
provider-id = "local";
client-id = "cid1";
client-secret = "csecret-1";
authorize-url = "http://auth";
token-url = "http://token";
sign-key = "b64:uiaeuae";
};
}
];
inherit full-text-search;
};
environment.systemPackages =
[
pkgs.jq
pkgs.inetutils
pkgs.htop
pkgs.openjdk
];
services.xserver = {
enable = false;
};
networking = {
hostName = "docspelltest";
firewall.allowedTCPPorts = [ 7880 ];
};
system.stateVersion = "22.05";
}

7
nix/checks/default.nix Normal file
View File

@ -0,0 +1,7 @@
{ ... }:
{
imports = [
./configuration-test.nix
./solr.nix
];
}

43
nix/checks/solr.nix Normal file
View File

@ -0,0 +1,43 @@
{ config, pkgs, lib, ... }:
# This module sets up solr with one core. It is a bit tedious…. If you
# know a better solution, please let me know.
{
nixpkgs.config = {
permittedInsecurePackages = [
"solr-8.6.3"
# NOTE: Qtwebkit is a dep for wkhtmltopdf, this line is needed until #201765 is fixed in nixpkgs
"qtwebkit-5.212.0-alpha4"
];
};
services.solr = {
enable = true;
};
# This is needed to run solr script as user solr
users.users.solr.useDefaultShell = true;
systemd.services.solr-init =
let
solrPort = toString config.services.solr.port;
initSolr = ''
if [ ! -f ${config.services.solr.stateDir}/docspell_core ]; then
while ! echo "" | ${pkgs.inetutils}/bin/telnet localhost ${solrPort}
do
echo "Waiting for SOLR become ready..."
sleep 1.5
done
${pkgs.su}/bin/su -s ${pkgs.bash}/bin/sh solr -c "${pkgs.solr}/bin/solr create_core -c docspell -p ${solrPort}";
touch ${config.services.solr.stateDir}/docspell_core
fi
'';
in
{
script = initSolr;
after = [ "solr.target" ];
wantedBy = [ "multi-user.target" ];
requires = [ "solr.target" ];
description = "Create a core at solr";
};
}

3
nix/checks/testScript.py Normal file
View File

@ -0,0 +1,3 @@
with subtest("services are up"):
machine.wait_for_unit("docspell-restserver")
machine.wait_for_unit("docspell-joex")