about summary refs log tree commit diff
path: root/flake.nix
diff options
context:
space:
mode:
Diffstat (limited to 'flake.nix')
-rw-r--r--flake.nix62
1 files changed, 28 insertions, 34 deletions
diff --git a/flake.nix b/flake.nix
index c2d3b30..c879a7f 100644
--- a/flake.nix
+++ b/flake.nix
@@ -62,11 +62,22 @@
             example = "info";
             description = "Specify the server verbosity level. Uses RUST_LOG environment variable internally.";
           };
-          redisUri = mkOption {
-            type = types.nullOr types.str;
-            default = null;
-            example = "redis://192.168.1.200:6379/";
-            description = "Set the Redis instance used as backing storage. If null, Redis will be configured on localhost. Use services.redis to change parameters.";
+          backendUri = mkOption {
+            type = types.str;
+            default = "file:///var/lib/kittybox/data";
+            example = "redis://192.168.1.200:6379";
+            description = ''
+              Set the backend used for storing data. Available backends are:
+               - file:// - static folder backend (recommended)
+               - redis:// - Redis backend
+
+              Make sure that if you are using the file backend, the state
+              directory is accessible by Kittybox. By default, the unit config
+              uses DynamicUser=true, which prevents the unit from accessing
+              data outside of its directory. It is recommended to use a
+              bind-mount to /var/lib/private/kittybox if you require the state
+              directory to reside elsewhere.
+            '';
           };
           tokenEndpoint = mkOption {
             type = types.str;
@@ -124,7 +135,7 @@
 
           restartTriggers = [
             cfg.package
-            cfg.redisUri cfg.tokenEndpoint
+            cfg.backendUri cfg.tokenEndpoint
             cfg.authorizationEndpoint
             cfg.internalTokenFile
             cfg.bind cfg.port
@@ -137,7 +148,8 @@
             MEDIA_ENDPOINT = cfg.mediaEndpoint;
             MICROSUB_ENDPOINT = cfg.microsubServer;
             WEBMENTION_ENDPOINT = cfg.webmentionEndpoint;
-            REDIS_URI = if (cfg.redisUri == null) then "redis://127.0.0.1:6379/" else cfg.redisUri;
+            #REDIS_URI = if (cfg.redisUri == null) then "redis://127.0.0.1:6379/" else cfg.redisUri;
+            BACKEND_URI = cfg.backendUri;
             RUST_LOG = "${cfg.logLevel}";
           };
 
@@ -152,11 +164,9 @@
 
           serviceConfig = {
             DynamicUser = true;
+            StateDirectory = "kittybox";
           };
         };
-        services.redis = lib.mkIf (cfg.redisUri == null) {
-          enable = true;
-        };
       };
     };
   } // forAllSystems (system: let
@@ -195,7 +205,7 @@
     defaultPackage = self.packages.${system}.kittybox;
 
     checks = {
-      nixos-test = pkgs.nixosTest ({ lib }: {
+      nixos-test = (pkgs.nixosTest ({ lib }: {
         name = "nixos-kittybox";
 
         nodes = {
@@ -209,6 +219,7 @@
               #       make an e2e test for common workflows (e.g. making a post)
               tokenEndpoint = "https://example.com";
               authorizationEndpoint = "https://example.com";
+              logLevel = "debug";
             };
 
             environment.systemPackages = with pkgs; [
@@ -218,38 +229,21 @@
         };
 
         testScript = ''
-          import json
-
           kittybox.start()
           kittybox.wait_for_unit("default.target")
           with subtest("Verify that Kittybox started correctly..."):
               kittybox.succeed("curl --silent http://localhost:8080/micropub")
 
           with subtest("Onboarding should correctly work..."):
-              onboarding_json = {
-                  "user": {
-                      "type": ["h-card"],
-                      "properties": {
-                          "name": ["Vika"],
-                          "pronoun": ["she/her"],
-                          "url": ["https://twitter.com/VikaNezrimaya"],
-                          "note": ["Just a simple girl. Do I even exist or am I a vestige of the past long gone?"]
-                      }
-                    },
-                    "first_post": {
-                        "type": ["h-entry"],
-                        "properties": {
-                            "content": ["Hello!"]
-                        }
-                    },
-                    "blog_name": "Test Hideout",
-                    "feeds": []
-              }
-              kittybox.succeed("echo '{}' | curl --silent http://localhost:8080/ -d@- -H 'Content-Type: application/json'".format(json.dumps(onboarding_json).replace("'", "'\''$")))
+              # Here we rely on a fact that the /nix/store is shared between the host and the VM
+              kittybox.succeed("curl -vvv http://localhost:8080/ -d${./onboarding.json}")
               # Testing for a known string is the easiest way to determine that the onboarding worked
               kittybox.succeed("curl --silent http://localhost:8080/ | grep 'vestige of the past long gone'")
         '';
-      });
+      }))
+      # This test is broken! For some reason the file locks don't seem to work and hang the executable instead.
+      #.overrideAttrs(o: { meta.broken = true; })
+      ;
     };
 
     devShell = pkgs.mkShell {