Skip to content

Commit

Permalink
nix: implement flake
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
VTimofeenko committed Nov 29, 2022
1 parent 1d39b5c commit 562c482
Show file tree
Hide file tree
Showing 8 changed files with 2,887 additions and 0 deletions.
85 changes: 85 additions & 0 deletions nix/flake/checks/configuration-test.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
{ 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.docspell.server
pkgs.docspell.joex
pkgs.jq
pkgs.telnet
pkgs.htop
pkgs.openjdk
];


services.xserver = {
enable = false;
};

networking = {
hostName = "docspelltest";
firewall.allowedTCPPorts = [ 7880 ];
};

system.stateVersion = "21.05";

}
7 changes: 7 additions & 0 deletions nix/flake/checks/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{ ... }:
{
imports = [
./configuration-test.nix
./solr.nix
];
}
35 changes: 35 additions & 0 deletions nix/flake/checks/solr.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{ config, pkgs, ... }:

# This module sets up solr with one core. It is a bit tedious…. If you
# know a better solution, please let me know.
{

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.telnet}/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 changes: 3 additions & 0 deletions nix/flake/checks/testScript.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
with subtest("services are up"):
machine.wait_for_unit("docspell-restserver")
machine.wait_for_unit("docspell-joex")
25 changes: 25 additions & 0 deletions nix/flake/flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

127 changes: 127 additions & 0 deletions nix/flake/flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
{
description = "Docspell flake";

outputs = { self, nixpkgs }:
let
supportedSystems = [ "x86_64-linux" "aarch64-linux" ];
forAllSystems = nixpkgs.lib.genAttrs supportedSystems;
nixpkgsFor = forAllSystems (system: import nixpkgs { inherit system; });
# Version config
cfg = {
v0_39_0 = rec {
version = "0.39.0";
server = {
url = "https://github.com/eikek/docspell/releases/download/v${version}/docspell-restserver-${version}.zip";
sha256 = "sha256-YZzYOqJzp2J5ioTT8H7qpRA3mHDRjJYNA7fUOEQWSfY=";
};
joex = {
url = "https://github.com/eikek/docspell/releases/download/v${version}/docspell-joex-${version}.zip";
sha256 = "sha256-6Vcuk9+JDkNAdTQd+sRLARfE+y9cbtGE8hWTTcxZk3E=";
};
};
};
current_version = cfg.v0_39_0;
inherit (current_version) version;
in
rec
{
overlays.default = final: prev: {
docspell-server = with final; stdenv.mkDerivation {
inherit version;
pname = "docspell-server";

src = fetchzip current_version.server;
buildInputs = [ jdk11 ];
buildPhase = "true";

installPhase = ''
mkdir -p $out/{bin,docspell-restserver-${version}}
cp -R * $out/docspell-restserver-${version}/
cat > $out/bin/docspell-restserver <<-EOF
#!${bash}/bin/bash
$out/docspell-restserver-${version}/bin/docspell-restserver -java-home ${jdk11} "\$@"
EOF
chmod 755 $out/bin/docspell-restserver
'';
};
docspell-joex = with final; stdenv.mkDerivation rec {
inherit version;

pname = "docspell-joex";

src = fetchzip current_version.joex;

buildInputs = [ jdk11 ];

buildPhase = "true";

installPhase = ''
mkdir -p $out/{bin,docspell-joex-${version}}
cp -R * $out/docspell-joex-${version}/
cat > $out/bin/docspell-joex <<-EOF
#!${bash}/bin/bash
$out/docspell-joex-${version}/bin/docspell-joex -java-home ${jdk11} "\$@"
EOF
chmod 755 $out/bin/docspell-joex
'';
};

};

packages = forAllSystems (system:
{
default = (import nixpkgs {
inherit system;
overlays = [ self.overlays.default ];
}).docspell-server;
});

checks = forAllSystems
(system: {
build = self.packages.${system}.default;

test =
with import (nixpkgs + "/nixos/lib/testing-python.nix")
{
inherit system;
};

makeTest {
name = "docspell";
nodes = {
client = { ... }: {
imports = [
self.nixosModules.default
./checks
];
};
};

testScript =
''
start_all()
client.wait_for_unit("docspell-restserver")
'';
};
});

nixosModules = {
default = { ... }: {
imports = [
((import ./modules/server.nix) self.overlays.default)
((import ./modules/joex.nix) self.overlays.default)
];
};
server = ((import ./modules/server.nix) self.overlays.default);
joex = ((import ./modules/joex.nix) self.overlays.default);
};


# nixosModules = {
# # Default module imports both server and joex
# default = import ./modules;
# server = import ./modules/server.nix;
# joex = import ./modules/joex.nix;
# };
};
}
Loading

0 comments on commit 562c482

Please sign in to comment.