Improve nix files

List available versions; refactor modules to reuse default values.
This commit is contained in:
Eike Kettner 2020-01-22 23:11:02 +01:00
parent ec29e44d3d
commit c0f39d6497
5 changed files with 129 additions and 119 deletions

View File

@ -20,7 +20,7 @@ in
let let
callPackage = pkgs.lib.callPackageWith(custom // pkgs); callPackage = pkgs.lib.callPackageWith(custom // pkgs);
custom = { custom = {
docspell = callPackage (docspell.pkg "0.2.0") {}; docspell = callPackage docspell.currentPkg {};
}; };
in custom; in custom;
}; };
@ -39,6 +39,8 @@ in
urls = ["http://localhost:7880/api/v1/open/upload/item/blabla"]; urls = ["http://localhost:7880/api/v1/open/upload/item/blabla"];
}; };
environment.systemPackages = [ pkgs.docspell.tools pkgs.jq ];
services.xserver = { services.xserver = {
enable = false; enable = false;
}; };

View File

@ -9,6 +9,54 @@ let
${builtins.toJSON cfg} ${builtins.toJSON cfg}
}} }}
''; '';
defaults = {
app-id = "joex1";
base-url = "http://localhost:7878";
bind = {
address = "localhost";
port = 7878;
};
jdbc = {
url = "jdbc:h2:///tmp/docspell-demo.db;MODE=PostgreSQL;DATABASE_TO_LOWER=TRUE;AUTO_SERVER=TRUE";
user = "sa";
password = "";
};
scheduler = {
pool-size = 2;
counting-scheme = "4,1";
retries = 5;
retry-delay = "1 minute";
log-buffer-size = 500;
wakeup-period = "30 minutes";
};
extraction = {
page-range = {
begin = 10;
};
ghostscript = {
working-dir = "/tmp/docspell-extraction";
command = {
program = "${pkgs.ghostscript}/bin/gs";
args = [ "-dNOPAUSE" "-dBATCH" "-dSAFER" "-sDEVICE=tiffscaled8" "-sOutputFile={{outfile}}" "{{infile}}" ];
timeout = "5 minutes";
};
};
unpaper = {
command = {
program = "${pkgs.unpaper}/bin/unpaper";
args = [ "{{infile}}" "{{outfile}}" ];
timeout = "5 minutes";
};
};
tesseract = {
command= {
program = "${pkgs.tesseract4}/bin/tesseract";
args = ["{{file}}" "stdout" "-l" "{{lang}}" ];
timeout = "5 minutes";
};
};
};
};
in { in {
## interface ## interface
@ -30,13 +78,13 @@ in {
app-id = mkOption { app-id = mkOption {
type = types.str; type = types.str;
default = "docspell-joex1"; default = defaults.app-id;
description = "The node id. Must be unique across all docspell nodes."; description = "The node id. Must be unique across all docspell nodes.";
}; };
base-url = mkOption { base-url = mkOption {
type = types.str; type = types.str;
default = "http://localhost:7878"; default = defaults.base-url;
description = "The base url where attentive is deployed."; description = "The base url where attentive is deployed.";
}; };
@ -45,20 +93,17 @@ in {
options = { options = {
address = mkOption { address = mkOption {
type = types.str; type = types.str;
default = "localhost"; default = defaults.bind.address;
description = "The address to bind the REST server to."; description = "The address to bind the REST server to.";
}; };
port = mkOption { port = mkOption {
type = types.int; type = types.int;
default = 7878; default = defaults.bind.port;
description = "The port to bind the REST server"; description = "The port to bind the REST server";
}; };
}; };
}); });
default = { default = defaults.bind;
address = "localhost";
port = 7878;
};
description = "Address and port bind the rest server."; description = "Address and port bind the rest server.";
}; };
@ -67,7 +112,7 @@ in {
options = { options = {
url = mkOption { url = mkOption {
type = types.str; type = types.str;
default = "jdbc:h2:///tmp/docspell-demo.db;MODE=PostgreSQL;DATABASE_TO_LOWER=TRUE;AUTO_SERVER=TRUE"; default = defaults.jdbc.url;
description = '' description = ''
The URL to the database. By default a file-based database is The URL to the database. By default a file-based database is
used. It should also work with mariadb and postgresql. used. It should also work with mariadb and postgresql.
@ -81,21 +126,17 @@ in {
}; };
user = mkOption { user = mkOption {
type = types.str; type = types.str;
default = "sa"; default = defaults.jdbc.user;
description = "The user name to connect to the database."; description = "The user name to connect to the database.";
}; };
password = mkOption { password = mkOption {
type = types.str; type = types.str;
default = ""; default = defaults.jdbc.password;
description = "The password to connect to the database."; description = "The password to connect to the database.";
}; };
}; };
}); });
default = { default = defaults.jdbc;
url = "jdbc:h2:///tmp/docspell-demo.db;MODE=PostgreSQL;DATABASE_TO_LOWER=TRUE;AUTO_SERVER=TRUE";
user = "sa";
password = "";
};
description = "Database connection settings"; description = "Database connection settings";
}; };
@ -104,12 +145,12 @@ in {
options = { options = {
pool-size = mkOption { pool-size = mkOption {
type = types.int; type = types.int;
default = 2; default = defaults.scheduler.pool-size;
description = "Number of processing allowed in parallel."; description = "Number of processing allowed in parallel.";
}; };
counting-scheme = mkOption { counting-scheme = mkOption {
type = types.str; type = types.str;
default = "4,1"; default = defaults.scheduler.counting-scheme;
description = '' description = ''
A counting scheme determines the ratio of how high- and low-prio A counting scheme determines the ratio of how high- and low-prio
jobs are run. For example: 4,1 means run 4 high prio jobs, then jobs are run. For example: 4,1 means run 4 high prio jobs, then
@ -118,7 +159,7 @@ in {
}; };
retries = mkOption { retries = mkOption {
type = types.int; type = types.int;
default = 5; default = defaults.scheduler.retries;
description = '' description = ''
How often a failed job should be retried until it enters failed How often a failed job should be retried until it enters failed
state. If a job fails, it becomes "stuck" and will be retried state. If a job fails, it becomes "stuck" and will be retried
@ -127,7 +168,7 @@ in {
}; };
retry-delay = mkOption { retry-delay = mkOption {
type = types.str; type = types.str;
default = "1 minute"; default = defaults.scheduler.retry-delay;
description = '' description = ''
The delay until the next try is performed for a failed job. This The delay until the next try is performed for a failed job. This
delay is increased exponentially with the number of retries. delay is increased exponentially with the number of retries.
@ -135,14 +176,14 @@ in {
}; };
log-buffer-size = mkOption { log-buffer-size = mkOption {
type = types.int; type = types.int;
default = 500; default = defaults.scheduler.log-buffer-size;
description = '' description = ''
The queue size of log statements from a job. The queue size of log statements from a job.
''; '';
}; };
wakeup-period = mkOption { wakeup-period = mkOption {
type = types.str; type = types.str;
default = "30 minutes"; default = defaults.scheduler.wakeup-period;
description = '' description = ''
If no job is left in the queue, the scheduler will wait until a If no job is left in the queue, the scheduler will wait until a
notify is requested (using the REST interface). To also retry notify is requested (using the REST interface). To also retry
@ -151,36 +192,11 @@ in {
}; };
}; };
}); });
default = { default = defaults.scheduler;
pool-size = 2;
counting-scheme = "4,1";
retries = 5;
retry-delay = "1 minute";
log-buffer-size = 500;
wakeup-period = "30 minutes";
};
description = "Settings for the scheduler"; description = "Settings for the scheduler";
}; };
extraction = extraction = mkOption {
let
gsdefaults = {
program = "${pkgs.ghostscript}/bin/gs";
args = [ "-dNOPAUSE" "-dBATCH" "-dSAFER" "-sDEVICE=tiffscaled8" "-sOutputFile={{outfile}}" "{{infile}}" ];
timeout = "5 minutes";
};
unpaperdefaults = {
program = "${pkgs.unpaper}/bin/unpaper";
args = [ "{{infile}}" "{{outfile}}" ];
timeout = "5 minutes";
};
tesseractdefaults = {
program = "${pkgs.tesseract4}/bin/tesseract";
args = ["{{file}}" "stdout" "-l" "{{lang}}" ];
timeout = "5 minutes";
};
in
mkOption {
type = types.submodule({ type = types.submodule({
options = { options = {
page-range = mkOption { page-range = mkOption {
@ -188,14 +204,12 @@ in {
options = { options = {
begin = mkOption { begin = mkOption {
type = types.int; type = types.int;
default = 10; default = defaults.extraction.page-range.begin;
description = "Specifies the first N pages of a file to process."; description = "Specifies the first N pages of a file to process.";
}; };
}; };
}); });
default = { default = defaults.extraction.page-range;
begin = 10;
};
description = '' description = ''
Defines what pages to process. If a PDF with 600 pages is Defines what pages to process. If a PDF with 600 pages is
submitted, it is probably not necessary to scan through all of submitted, it is probably not necessary to scan through all of
@ -215,7 +229,7 @@ in {
options = { options = {
working-dir = mkOption { working-dir = mkOption {
type = types.str; type = types.str;
default = "/tmp/docspell-extraction"; default = defaults.extraction.ghostscript.working-dir;
description = "Directory where the extraction processes can put their temp files"; description = "Directory where the extraction processes can put their temp files";
}; };
command = mkOption { command = mkOption {
@ -223,30 +237,27 @@ in {
options = { options = {
program = mkOption { program = mkOption {
type = types.str; type = types.str;
default = gsdefaults.program; default = defaults.extraction.ghostscript.command.program;
description = "The path to the executable."; description = "The path to the executable.";
}; };
args = mkOption { args = mkOption {
type = types.listOf types.str; type = types.listOf types.str;
default = gsdefaults.args; default = defaults.extraction.ghostscript.command.args;
description = "The arguments to the program"; description = "The arguments to the program";
}; };
timeout = mkOption { timeout = mkOption {
type = types.str; type = types.str;
default = gsdefaults.timeout; default = defaults.extraction.ghostscript.command.timeout;
description = "The timeout when executing the command"; description = "The timeout when executing the command";
}; };
}; };
}); });
default = gsdefaults; default = defaults.extraction.ghostscript.command;
description = "The system command"; description = "The system command";
}; };
}; };
}); });
default = { default = defaults.extraction.ghostscript;
command = gsdefaults;
working-dir = "/tmp/docspell-extraction";
};
description = "The ghostscript command."; description = "The ghostscript command.";
}; };
unpaper = mkOption { unpaper = mkOption {
@ -257,29 +268,27 @@ in {
options = { options = {
program = mkOption { program = mkOption {
type = types.str; type = types.str;
default = unpaperdefaults.program; default = defaults.extraction.unpaper.command.program;
description = "The path to the executable."; description = "The path to the executable.";
}; };
args = mkOption { args = mkOption {
type = types.listOf types.str; type = types.listOf types.str;
default = unpaperdefaults.args; default = defaults.extraction.unpaper.command.args;
description = "The arguments to the program"; description = "The arguments to the program";
}; };
timeout = mkOption { timeout = mkOption {
type = types.str; type = types.str;
default = unpaperdefaults.timeout; default = defaults.extraction.unpaper.command.timeout;
description = "The timeout when executing the command"; description = "The timeout when executing the command";
}; };
}; };
}); });
default = unpaperdefaults; default = defaults.extraction.unpaper.command;
description = "The system command"; description = "The system command";
}; };
}; };
}); });
default = { default = defaults.extraction.unpaper;
command = unpaperdefaults;
};
description = "The unpaper command."; description = "The unpaper command.";
}; };
tesseract = mkOption { tesseract = mkOption {
@ -290,42 +299,32 @@ in {
options = { options = {
program = mkOption { program = mkOption {
type = types.str; type = types.str;
default = tesseractdefaults.program; default = defaults.extraction.tesseract.command.program;
description = "The path to the executable."; description = "The path to the executable.";
}; };
args = mkOption { args = mkOption {
type = types.listOf types.str; type = types.listOf types.str;
default = tesseractdefaults.args; default = defaults.extraction.tesseract.command.args;
description = "The arguments to the program"; description = "The arguments to the program";
}; };
timeout = mkOption { timeout = mkOption {
type = types.str; type = types.str;
default = tesseractdefaults.timeout; default = defaults.extraction.tesseract.command.timeout;
description = "The timeout when executing the command"; description = "The timeout when executing the command";
}; };
}; };
}); });
default = tesseractdefaults; default = defaults.extraction.tesseract.command;
description = "The system command"; description = "The system command";
}; };
}; };
}); });
default = { default = defaults.extraction.tesseract;
command = tesseractdefaults;
};
description = "The tesseract command."; description = "The tesseract command.";
}; };
}; };
}); });
default = { default = defaults.extraction;
page-range = {
begin = 10;
};
ghostscript = {
command = gsdefaults;
working-dir = "/tmp/docspell-extraction";
};
};
description = '' description = ''
Configuration of text extraction Configuration of text extraction

View File

@ -196,11 +196,7 @@ in {
}; };
}; };
}); });
default = { default = defaults.backend.signup;
mode = "closed";
newInvitePassword = "";
inviteTime = "3 days";
};
description = "Registration settings"; description = "Registration settings";
}; };
files = mkOption { files = mkOption {

View File

@ -1,6 +1,5 @@
version: {stdenv, fetchzip, file, curl, inotifyTools, fetchurl, jre8_headless, bash}: cfg: {stdenv, fetchzip, file, curl, inotifyTools, fetchurl, jre8_headless, bash}:
let let
# version = "0.2.0";
meta = with stdenv.lib; { meta = with stdenv.lib; {
description = "Docspell helps to organize and archive your paper documents."; description = "Docspell helps to organize and archive your paper documents.";
homepage = https://github.com/eikek/docspell; homepage = https://github.com/eikek/docspell;
@ -9,12 +8,9 @@ let
}; };
in in
{ server = stdenv.mkDerivation rec { { server = stdenv.mkDerivation rec {
name = "docspell-server-${version}"; name = "docspell-server-${cfg.version}";
src = fetchzip { src = fetchzip cfg.server;
url = "https://github.com/eikek/docspell/releases/download/v${version}/docspell-restserver-${version}.zip";
sha256 = "1mpyd66pcsd2q4wx9vszldqlamz9qgv6abrxh7xwzw23np61avy5";
};
buildInputs = [ jre8_headless ]; buildInputs = [ jre8_headless ];
@ -34,12 +30,9 @@ in
}; };
joex = stdenv.mkDerivation rec { joex = stdenv.mkDerivation rec {
name = "docspell-joex-${version}"; name = "docspell-joex-${cfg.version}";
src = fetchzip { src = fetchzip cfg.joex;
url = "https://github.com/eikek/docspell/releases/download/v${version}/docspell-joex-${version}.zip";
sha256 = "1ycfcfcv24vvkdbzvnahj500gb5l9vdls4bxq0jd1zn72p4z765f";
};
buildInputs = [ jre8_headless ]; buildInputs = [ jre8_headless ];
@ -58,13 +51,10 @@ in
inherit meta; inherit meta;
}; };
tools = stdenv.mkDerivation rec { tools = stdenv.mkDerivation {
name = "docspell-tools-${version}"; name = "docspell-tools-${cfg.version}";
src = fetchzip { src = fetchzip cfg.tools;
url = "https://github.com/eikek/docspell/releases/download/v${version}/docspell-tools-${version}.zip";
sha256 = "0hd93rlnnrq8xj7knp38x1jj2mv4y5lvbcv968bzk5f1az51qsvg";
};
buildPhase = "true"; buildPhase = "true";

View File

@ -1,15 +1,38 @@
let
currentVersion =
let
file = builtins.readFile ../version.sbt;
comps = builtins.split ":=" file;
last = builtins.head (builtins.tail (builtins.filter builtins.isString comps));
in
builtins.replaceStrings ["\"" "\n" " "] ["" "" ""] last;
in
rec { rec {
cfg = {
v0_2_0 = rec {
version = "0.2.0";
server = {
url = "https://github.com/eikek/docspell/releases/download/v${version}/docspell-restserver-${version}.zip";
sha256 = "1mpyd66pcsd2q4wx9vszldqlamz9qgv6abrxh7xwzw23np61avy5";
};
joex = {
url = "https://github.com/eikek/docspell/releases/download/v${version}/docspell-joex-${version}.zip";
sha256 = "1ycfcfcv24vvkdbzvnahj500gb5l9vdls4bxq0jd1zn72p4z765f";
};
tools = {
url = "https://github.com/eikek/docspell/releases/download/v${version}/docspell-tools-${version}.zip";
sha256 = "0hd93rlnnrq8xj7knp38x1jj2mv4y5lvbcv968bzk5f1az51qsvg";
};
};
v0_1_0 = rec {
version = "0.1.0";
server = {
url = "https://github.com/eikek/docspell/releases/download/v${version}/docspell-restserver-${version}.zip";
sha256 = "19bmvrk07s4gsw4dszbilfv7jns7bp20lfr0ia73xdmn5w8kdhq0";
};
joex = {
url = "https://github.com/eikek/docspell/releases/download/v${version}/docspell-joex-${version}.zip";
sha256 = "175yz0lxra0qv63xjl90hh32idm13c1k1aah2hqc0ncpx22scp5v";
};
tools = {
url = "https://github.com/eikek/docspell/releases/download/v${version}/docspell-tools-${version}.zip";
sha256 = "03w5cxylk2yfkah15qrx5cl21gfly0vwa0czglb1swsri3808rdb";
};
};
};
pkg = v: import ./pkg.nix v; pkg = v: import ./pkg.nix v;
currentPkg = pkg currentVersion; currentPkg = pkg cfg.v0_2_0;
module-joex = ./module-joex.nix; module-joex = ./module-joex.nix;
module-restserver = ./module-server.nix; module-restserver = ./module-server.nix;
module-consumedir = ./module-consumedir.nix; module-consumedir = ./module-consumedir.nix;