From de3e07a77caf65ceabd25b9e4054131f4516b352 Mon Sep 17 00:00:00 2001
From: Eike Kettner <eike.kettner@posteo.de>
Date: Sun, 1 Mar 2020 21:34:11 +0100
Subject: [PATCH] Nix modules: change docspell user to be a normal user

Seems that unoconv requires a shell.
---
 nix/buildvm.sh             | 10 ++++++++++
 nix/configuration-test.nix |  4 +++-
 nix/module-joex.nix        |  5 +++--
 nix/module-server.nix      |  4 +++-
 4 files changed, 19 insertions(+), 4 deletions(-)
 create mode 100755 nix/buildvm.sh

diff --git a/nix/buildvm.sh b/nix/buildvm.sh
new file mode 100755
index 00000000..6c240738
--- /dev/null
+++ b/nix/buildvm.sh
@@ -0,0 +1,10 @@
+#!/usr/bin/env bash
+
+if [ "$1" = "-f" ]; then
+    echo "Deleting current state image..."
+    rm *.qcow2
+fi
+
+nixos-rebuild build-vm \
+  -I nixos-config=./configuration-test.nix \
+  -I nixpkgs=https://github.com/NixOS/nixpkgs-channels/archive/nixos-19.09.tar.gz
diff --git a/nix/configuration-test.nix b/nix/configuration-test.nix
index 94dc70bd..5697dc5c 100644
--- a/nix/configuration-test.nix
+++ b/nix/configuration-test.nix
@@ -28,9 +28,11 @@ in
 
   services.docspell-joex = {
     enable = true;
-    base-url = "http://docspelltest:7878";
+    bind.address = "0.0.0.0";
+    base-url = "http://localhost:7878";
   };
   services.docspell-restserver = {
+    bind.address = "0.0.0.0";
     enable = true;
   };
   services.docspell-consumedir = {
diff --git a/nix/module-joex.nix b/nix/module-joex.nix
index 40d2fb1b..45399d73 100644
--- a/nix/module-joex.nix
+++ b/nix/module-joex.nix
@@ -600,7 +600,9 @@ in {
 
     users.users."${user}" = mkIf (cfg.runAs == null) {
       name = user;
-      isSystemUser = true;
+      isSystemUser = false;
+      createHome = true;
+      home = "/var/docspell";
       description = "Docspell user";
     };
 
@@ -613,7 +615,6 @@ in {
           description = "Unoconv Listener";
           after = [ "networking.target" ];
           wantedBy = [ "multi-user.target" ];
-          path = [ pkgs.unoconv ];
           serviceConfig = {
             Restart = "always";
           };
diff --git a/nix/module-server.nix b/nix/module-server.nix
index 0ac4922b..55f9941d 100644
--- a/nix/module-server.nix
+++ b/nix/module-server.nix
@@ -246,7 +246,9 @@ in {
 
     users.users."${user}" = mkIf (cfg.runAs == null) {
       name = user;
-      isSystemUser = true;
+      isSystemUser = false;
+      createHome = true;
+      home = "/var/docspell";
       description = "Docspell user";
     };