From 892aa2e4fab3e7b2ef17d62d2ec294a72fe2b356 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20B=C3=A4dorf?= Date: Tue, 7 Feb 2023 15:56:19 +0100 Subject: [PATCH] Update paperless module --- modules/core/networking.nix | 4 ++-- modules/paperless/default.nix | 30 ++++++++++++++++++++++++++++++ pkgs/scan2paperless.nix | 13 +++++++++++++ 3 files changed, 45 insertions(+), 2 deletions(-) diff --git a/modules/core/networking.nix b/modules/core/networking.nix index f1a194ed..a8d832b3 100644 --- a/modules/core/networking.nix +++ b/modules/core/networking.nix @@ -79,8 +79,8 @@ in { config.pub-solar.paperless.enable '' paperless.local:80 { - request_header Host localhost:28981 - reverse_proxy localhost:28981 + request_header Host localhost:${builtins.toString config.services.paperless.port} + reverse_proxy localhost:${builtins.toString config.services.paperless.port} } '') diff --git a/modules/paperless/default.nix b/modules/paperless/default.nix index 63f5fb13..f95dc125 100644 --- a/modules/paperless/default.nix +++ b/modules/paperless/default.nix @@ -23,6 +23,20 @@ in { example = "/var/lib/paperless/consume"; default = "/home/${psCfg.user.name}/Documents"; }; + scannerDefaultDevice = mkOption { + description = '' The scanner device. To find this, use `scanimage -L`. + + For example, your output might be the following: + + ``` + device `v4l:/dev/video3' is a Noname Logitech StreamCam virtual device + device `hp3900:libusb:005:002' is a Hewlett-Packard Scanjet G3010 flatbed scanner + ``` + + Here, the scannerDevice is `hp3900:libusb:005:002`. + ''; + type = types.str; + }; }; config = mkIf cfg.enable { @@ -30,10 +44,26 @@ in { enable = true; user = psCfg.user.name; consumptionDir = cfg.consumptionDir; + address = "paperless.local"; extraConfig = { PAPERLESS_OCR_LANGUAGE = cfg.ocrLanguage; PAPERLESS_ADMIN_USER = psCfg.user.name; PAPERLESS_AUTO_LOGIN_USERNAME = psCfg.user.name; + PAPERLESS_URL = "http://paperless.local"; + }; + }; + + home-manager = pkgs.lib.setAttrByPath ["users" psCfg.user.name] { + home.packages = with pkgs; [ + scan2paperless + ]; + home.sessionVariables = { + SCANNER_DEFAULT_DEVICE = cfg.scannerDefaultDevice; + SCANNER_OUTPUT_DIR = cfg.consumptionDir; + }; + systemd.user.sessionVariables = { + SCANNER_DEFAULT_DEVICE = cfg.scannerDefaultDevice; + SCANNER_OUTPUT_DIR = cfg.consumptionDir; }; }; }; diff --git a/pkgs/scan2paperless.nix b/pkgs/scan2paperless.nix index ad6d3635..5e527ddb 100644 --- a/pkgs/scan2paperless.nix +++ b/pkgs/scan2paperless.nix @@ -1,4 +1,17 @@ self: with self; '' export PATH=${lib.makeBinPath [pkgs.coreutils pkgs.sane-frontends pkgs.sane-backends pkgs.ghostscript pkgs.imagemagick]} + + while true; + do + read -p "Press Enter to continue or Ctrl+C to stop" < /dev/tty + + DATETIME=$(date -Iseconds) + scanimage \ + -d "''${SCANNER_DEFAULT_DEVICE}" \ + --format=jpeg \ + --resolution 300 \ + --progress \ + -o "''${SCANNER_OUTPUT_DIR}/''${DATETIME}.jpg" + done ''