at master 2.1 kB view raw
1{ 2 lib, 3 pkgs, 4 config, 5 ... 6}: 7let 8 cfg = config.services.spoolman; 9in 10{ 11 12 options.services.spoolman = { 13 14 enable = lib.mkEnableOption "Spoolman, a filament spool inventory management system."; 15 16 environment = lib.mkOption { 17 type = lib.types.attrs; 18 default = { }; 19 example = { 20 SPOOLMAN_DB_TYPE = "sqlite"; 21 SPOOLMAN_LOGGING_LEVEL = "DEBUG"; 22 SPOOLMAN_AUTOMATIC_BACKUP = "TRUE"; 23 SPOOLMAN_BASE_PATH = "/spoolman"; 24 SPOOLMAN_METRICS_ENABLED = "TRUE"; 25 SPOOLMAN_CORS_ORIGIN = "source1.domain.com:p1, source2.domain.com:p2"; 26 }; 27 description = '' 28 Environment variables to be passed to the spoolman service. 29 Refer to https://github.com/Donkie/Spoolman/blob/master/.env.example for details on supported variables. 30 ''; 31 }; 32 33 openFirewall = lib.mkOption { 34 type = lib.types.bool; 35 default = false; 36 description = '' 37 Open the appropriate ports in the firewall for spoolman. 38 ''; 39 }; 40 41 listen = lib.mkOption { 42 type = lib.types.str; 43 default = "127.0.0.1"; 44 example = "0.0.0.0"; 45 description = "The IP address to bind the spoolman server to."; 46 }; 47 48 port = lib.mkOption { 49 type = lib.types.port; 50 default = 7912; 51 description = '' 52 TCP port where spoolman web-gui listens. 53 ''; 54 }; 55 56 }; 57 58 config = lib.mkIf cfg.enable { 59 60 systemd.services.spoolman = { 61 description = "A self-hosted filament spool inventory management system"; 62 wantedBy = [ "multi-user.target" ]; 63 environment = { 64 SPOOLMAN_DIR_DATA = "/var/lib/spoolman"; 65 } 66 // cfg.environment; 67 serviceConfig = lib.mkMerge [ 68 { 69 DynamicUser = true; 70 ExecStart = "${pkgs.spoolman}/bin/spoolman --host ${cfg.listen} --port ${toString cfg.port}"; 71 StateDirectory = "spoolman"; 72 } 73 ]; 74 }; 75 76 networking.firewall = lib.mkIf cfg.openFirewall { 77 allowedTCPPorts = lib.optional (cfg.listen != "127.0.0.1") cfg.port; 78 }; 79 80 }; 81 meta = { 82 maintainers = with lib.maintainers; [ MayNiklas ]; 83 }; 84}