diff --git a/modules/core/networking.nix b/modules/core/networking.nix index f1a194e..a8d832b 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 63f5fb1..f95dc12 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 ad6d363..5e527dd 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 ''