summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKjetil Orbekk <kjetil.orbekk@gmail.com>2020-02-13 05:32:15 -0500
committerKjetil Orbekk <kjetil.orbekk@gmail.com>2020-02-13 05:32:15 -0500
commit3c18ab894a56b9140548e90325a2f3ff91fe4004 (patch)
tree0e96d404af6bcb92bf7c6eca2f1a8143391dc650
parent0954d497556ae3eaba7e94455cb156898332d3ca (diff)
Add pjournal service
-rw-r--r--config/pjournal.nix59
1 files changed, 59 insertions, 0 deletions
diff --git a/config/pjournal.nix b/config/pjournal.nix
new file mode 100644
index 0000000..ab558da
--- /dev/null
+++ b/config/pjournal.nix
@@ -0,0 +1,59 @@
+{ config, lib, pkgs, ... }:
+with lib;
+let
+ cfg = config.services.pjournal;
+in
+{
+ options = {
+ services.pjournal = {
+ package = mkOption {
+ type = types.package;
+ default = pkgs.callPackage ../pkgs/pjournal/default.nix {};
+ };
+ };
+ };
+
+ config = {
+ environment.systemPackages = [
+ cfg.package
+ ];
+
+ services.postgresql = {
+ enable = true;
+ ensureDatabases = ["pjournal" "pjournal_test"];
+ ensureUsers = [
+ {
+ name = "pjournal";
+ ensurePermissions = {
+ "DATABASE pjournal" = "ALL PRIVILEGES";
+ };
+ }
+ {
+ name = "pjournal_test";
+ ensurePermissions = {
+ "DATABASE pjournal_test" = "ALL PRIVILEGES";
+ };
+ }
+ ];
+ };
+
+ systemd.services.pjournal-test = {
+ description = "pjournal test instance";
+ after = [ "multi-user.target" "postgresql.service" ];
+ wantedBy = ["multi-user.target"];
+ environment = {
+ RUST_BACKTRACE = "1";
+ };
+ serviceConfig = {
+ ExecStart = ''
+ # This will fail the first time. Run pjournal init to initialize
+ # the database.
+ ${cfg.package}/bin/pjournal \
+ --database_url postgres://pjournal_test@/pjournal_test
+ '';
+ User = "pjournal_test";
+ };
+ };
+
+ };
+}