{ lib, config, pkgs, masterModulesPath, ... }: with lib; let psCfg = config.pub-solar; cfg = config.pub-solar.paperless; xdg = config.home-manager.users."${psCfg.user.name}".xdg; in { imports = [ "${masterModulesPath}/services/misc/paperless.nix" ]; disabledModules = [ "services/misc/paperless.nix" ]; options.pub-solar.paperless = { enable = mkEnableOption "All you need to go paperless"; ocrLanguage = mkOption { description = "OCR language"; type = types.str; example = "eng+deu"; default = "eng"; }; dataDir = mkOption { description = "Directory to save data in"; type = types.str; example = "/home/pub_solar/Paperless"; default = "/home/${psCfg.user.name}/Paperless"; }; consumptionDir = mkOption { description = "Directory to be watched"; type = types.str; example = "/var/lib/paperless/consume"; default = "/var/lib/paperless/consume"; }; 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 { services.paperless = { enable = true; user = psCfg.user.name; consumptionDir = cfg.consumptionDir; dataDir = cfg.dataDir; 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; }; }; }; }