summaryrefslogtreecommitdiff
path: root/custom/bar-service.nix
diff options
context:
space:
mode:
Diffstat (limited to 'custom/bar-service.nix')
-rw-r--r--custom/bar-service.nix99
1 files changed, 99 insertions, 0 deletions
diff --git a/custom/bar-service.nix b/custom/bar-service.nix
new file mode 100644
index 00000000..2a492ce1
--- /dev/null
+++ b/custom/bar-service.nix
@@ -0,0 +1,99 @@
1{ config, lib, pkgs, ... }:
2
3with lib;
4
5let
6 cfg = config.services.bar;
7in {
8 options.services.bar = {
9 enable = mkEnableOption "the Bar Inventory System";
10
11 user = mkOption {
12 type = types.str;
13 default = "bar";
14 description = "User to execute the daemon under";
15 };
16
17 group = mkOption {
18 type = types.str;
19 default = "bar";
20 description = "Group to execute the daemon under";
21 };
22
23 stateDir = mkOption {
24 type = types.path;
25 default = "/var/lib/bar";
26 description = "Directory for the daemon to store semi-transient state (encryption keys etc.)";
27 };
28
29 port = mkOption {
30 type = types.int;
31 default = 8080;
32 description = "Port for the daemon to listen on";
33 };
34
35 host = mkOption {
36 type = types.str;
37 default = "localhost";
38 description = "Host to bind to";
39 };
40
41 approot = mkOption {
42 type = types.str;
43 default = "/";
44 description = "Subdirectory of the daemon-managed site relative to HTTP /; only useful when using a reverse proxy";
45 };
46
47 thermoprintBaseURL = mkOption {
48 type = with types; nullOr types.str;
49 default = null;
50 example = "http://localhost:80/thermoprint/api";
51 description = "Thermoprint base url";
52 };
53 };
54
55 config = mkIf cfg.enable {
56 assertions = [
57 { assertion = config.services.postgresql.enable;
58 message = "bar requires PostgreSQL";
59 }
60 ];
61
62 users.users."${cfg.user}" = {
63 group = cfg.group;
64 description = "User for the Bar Inventory System";
65 isSystemUser = true;
66 home = cfg.stateDir;
67 createHome = true;
68 };
69
70 users.groups."${cfg.group}" = {};
71
72 nixpkgs.overlays = [(self: super: {
73 bar = self.callPackage ./bar { inherit (self) haskellPackages; };
74 })];
75
76 systemd.services."bar" = {
77 environment = {
78 PORT = cfg.port;
79 HOST = cfg.host;
80 APPROOT = cfg.approot;
81 IP_FROM_HEADER = cfg.ipFromHeader;
82 TPRINT_BASEURL = mkIf (cfg.thermoprintBaseURL != null) cfg.thermoprintBaseURL;
83 };
84
85 bindsTo = [ "postgresql.service" ];
86 after = [ "postgresql.service" ];
87 wantedBy = [ "default.target" ];
88
89 serviceConfig = {
90 Type = "notify";
91 User = cfg.user;
92 Group = cfg.group;
93 WorkingDirectory = cfg.stateDir;
94
95 ExecStart = with pkgs; "${bar}/bin/bar";
96 };
97 };
98 };
99}