diff --git a/flake.lock b/flake.lock index 394e00a0..2a23de4a 100644 --- a/flake.lock +++ b/flake.lock @@ -35,13 +35,13 @@ "htmx-ws-src": { "flake": false, "locked": { - "narHash": "sha256-XbUFiv94ZPB6VVULoTWOsje5Gq1I+IT72lMc4CpUYrY=", + "narHash": "sha256-2fg6KyEJoO24q0fQqbz9RMaYNPQrMwpZh29tkSqdqGY=", "type": "file", - "url": "https://unpkg.com/htmx.org@2.0.4/dist/ext/ws.js" + "url": "https://cdn.jsdelivr.net/npm/htmx-ext-ws@2.0.2" }, "original": { "type": "file", - "url": "https://unpkg.com/htmx.org@2.0.4/dist/ext/ws.js" + "url": "https://cdn.jsdelivr.net/npm/htmx-ext-ws@2.0.2" } }, "ibm-plex-mono-src": { diff --git a/flake.nix b/flake.nix index b3a99161..7f53156f 100644 --- a/flake.nix +++ b/flake.nix @@ -12,7 +12,9 @@ flake = false; }; htmx-ws-src = { - url = "https://unpkg.com/htmx.org@2.0.4/dist/ext/ws.js"; + # strange errors in consle that i can't really make out + # url = "https://unpkg.com/htmx.org@2.0.4/dist/ext/ws.js"; + url = "https://cdn.jsdelivr.net/npm/htmx-ext-ws@2.0.2"; flake = false; }; lucide-src = { @@ -66,10 +68,14 @@ knotDeps = { inherit goModHash gitignoreSource; }; + spindleDeps = { + inherit goModHash gitignoreSource; + }; mkPackageSet = pkgs: { lexgen = pkgs.callPackage ./nix/pkgs/lexgen.nix {inherit indigo;}; appview = pkgs.callPackage ./nix/pkgs/appview.nix appviewDeps; knot = pkgs.callPackage ./nix/pkgs/knot.nix {}; + spindle = pkgs.callPackage ./nix/pkgs/spindle.nix spindleDeps; knot-unwrapped = pkgs.callPackage ./nix/pkgs/knot-unwrapped.nix knotDeps; sqlite-lib = pkgs.callPackage ./nix/pkgs/sqlite-lib.nix { inherit (pkgs) gcc; @@ -89,17 +95,20 @@ lexgen = pkgs.lexgen; knot = pkgs.knot; knot-unwrapped = pkgs.knot-unwrapped; + spindle = pkgs.spindle; genjwks = pkgs.genjwks; sqlite-lib = pkgs.sqlite-lib; pkgsStatic-appview = staticPkgs.appview; pkgsStatic-knot = staticPkgs.knot; pkgsStatic-knot-unwrapped = staticPkgs.knot-unwrapped; + pkgsStatic-spindle = staticPkgs.spindle; pkgsStatic-sqlite-lib = staticPkgs.sqlite-lib; pkgsCross-gnu64-pkgsStatic-appview = crossPkgs.appview; pkgsCross-gnu64-pkgsStatic-knot = crossPkgs.knot; pkgsCross-gnu64-pkgsStatic-knot-unwrapped = crossPkgs.knot-unwrapped; + pkgsCross-gnu64-pkgsStatic-spindle = crossPkgs.spindle; }); defaultPackage = forAllSystems (system: nixpkgsFor.${system}.appview); formatter = forAllSystems (system: nixpkgsFor."${system}".alejandra); @@ -167,6 +176,7 @@ nixosModules.appview = import ./nix/modules/appview.nix {inherit self;}; nixosModules.knot = import ./nix/modules/knot.nix {inherit self;}; - nixosConfigurations.knotVM = import ./nix/vm.nix {inherit self nixpkgs;}; + nixosModules.spindle = import ./nix/modules/spindle.nix {inherit self;}; + nixosConfigurations.vm = import ./nix/vm.nix {inherit self nixpkgs;}; }; } diff --git a/nix/modules/knot.nix b/nix/modules/knot.nix index 7fa5c40b..62adf56b 100644 --- a/nix/modules/knot.nix +++ b/nix/modules/knot.nix @@ -101,8 +101,7 @@ in system.activationScripts.gitConfig = '' mkdir -p "${cfg.repo.scanPath}" - chown -R ${cfg.gitUser}:${cfg.gitUser} \ - "${cfg.repo.scanPath}" + chown -R ${cfg.gitUser}:${cfg.gitUser} "${cfg.repo.scanPath}" mkdir -p "${cfg.stateDir}/.config/git" cat > "${cfg.stateDir}/.config/git/config" << EOF @@ -110,8 +109,7 @@ in name = Git User email = git@example.com EOF - chown -R ${cfg.gitUser}:${cfg.gitUser} \ - "${cfg.stateDir}" + chown -R ${cfg.gitUser}:${cfg.gitUser} "${cfg.stateDir}" ''; users.users.${cfg.gitUser} = { diff --git a/nix/modules/spindle.nix b/nix/modules/spindle.nix new file mode 100644 index 00000000..fa557fae --- /dev/null +++ b/nix/modules/spindle.nix @@ -0,0 +1,99 @@ +{self}: { + config, + pkgs, + lib, + ... +}: let + cfg = config.services.tangled-spindle; +in + with lib; { + options = { + services.tangled-spindle = { + enable = mkOption { + type = types.bool; + default = false; + description = "Enable a tangled spindle"; + }; + + server = { + listenAddr = mkOption { + type = types.str; + default = "0.0.0.0:6555"; + description = "Address to listen on"; + }; + + dbPath = mkOption { + type = types.path; + default = "/var/lib/spindle/spindle.db"; + description = "Path to the database file"; + }; + + hostname = mkOption { + type = types.str; + example = "spindle.tangled.sh"; + description = "Hostname for the server (required)"; + }; + + jetstreamEndpoint = mkOption { + type = types.str; + default = "wss://jetstream1.us-west.bsky.network/subscribe"; + description = "Jetstream endpoint to subscribe to"; + }; + + dev = mkOption { + type = types.bool; + default = false; + description = "Enable development mode (disables signature verification)"; + }; + + owner = mkOption { + type = types.str; + example = "did:plc:qfpnj4og54vl56wngdriaxug"; + description = "DID of owner (required)"; + }; + }; + + pipelines = { + nixery = mkOption { + type = types.str; + default = "nixery.tangled.sh"; + description = "Nixery instance to use"; + }; + + stepTimeout = mkOption { + type = types.str; + default = "5m"; + description = "Timeout for each step of a pipeline"; + }; + }; + }; + }; + + config = mkIf cfg.enable { + virtualisation.docker.enable = true; + + systemd.services.spindle = { + description = "spindle service"; + after = ["network.target" "docker.service"]; + wantedBy = ["multi-user.target"]; + serviceConfig = { + LogsDirectory = "spindle"; + StateDirectory = "spindle"; + Environment = [ + "SPINDLE_SERVER_LISTEN_ADDR=${cfg.server.listenAddr}" + "SPINDLE_SERVER_DB_PATH=${cfg.server.dbPath}" + "SPINDLE_SERVER_HOSTNAME=${cfg.server.hostname}" + "SPINDLE_SERVER_JETSTREAM=${cfg.server.jetstreamEndpoint}" + "SPINDLE_SERVER_DEV=${lib.boolToString cfg.server.dev}" + "SPINDLE_SERVER_OWNER=${cfg.server.owner}" + "SPINDLE_PIPELINES_NIXERY=${cfg.pipelines.nixery}" + "SPINDLE_PIPELINES_STEP_TIMEOUT=${cfg.pipelines.stepTimeout}" + ]; + ExecStart = "${self.packages.${pkgs.system}.spindle}/bin/spindle"; + Restart = "always"; + }; + }; + + networking.firewall.allowedTCPPorts = mkIf cfg.openFirewall [22]; + }; + } diff --git a/nix/pkgs/spindle.nix b/nix/pkgs/spindle.nix new file mode 100644 index 00000000..424a0544 --- /dev/null +++ b/nix/pkgs/spindle.nix @@ -0,0 +1,22 @@ +{ + buildGoModule, + stdenv, + sqlite-lib, + goModHash, + gitignoreSource, +}: +buildGoModule { + pname = "spindle"; + version = "0.1.0"; + src = gitignoreSource ../..; + + doCheck = false; + + subPackages = ["cmd/spindle"]; + vendorHash = goModHash; + tags = "libsqlite3"; + + env.CGO_CFLAGS = "-I ${sqlite-lib}/include "; + env.CGO_LDFLAGS = "-L ${sqlite-lib}/lib"; + env.CGO_ENABLED = 1; +} diff --git a/nix/vm.nix b/nix/vm.nix index c0b1a475..7cee2c00 100644 --- a/nix/vm.nix +++ b/nix/vm.nix @@ -6,14 +6,37 @@ nixpkgs.lib.nixosSystem { system = "x86_64-linux"; modules = [ self.nixosModules.knot + self.nixosModules.spindle ({ config, pkgs, ... }: { - virtualisation.memorySize = 2048; - virtualisation.diskSize = 10 * 1024; - virtualisation.cores = 2; + virtualisation = { + memorySize = 2048; + diskSize = 10 * 1024; + cores = 2; + forwardPorts = [ + # ssh + { + from = "host"; + host.port = 2222; + guest.port = 22; + } + # knot + { + from = "host"; + host.port = 6000; + guest.port = 6000; + } + # spindle + { + from = "host"; + host.port = 6555; + guest.port = 6555; + } + ]; + }; services.getty.autologinUser = "root"; environment.systemPackages = with pkgs; [curl vim git]; systemd.tmpfiles.rules = let @@ -31,6 +54,15 @@ nixpkgs.lib.nixosSystem { listenAddr = "0.0.0.0:6000"; }; }; + services.tangled-spindle = { + enable = true; + server = { + owner = "did:plc:qfpnj4og54vl56wngdriaxug"; + hostname = "localhost:6555"; + listenAddr = "0.0.0.0:6555"; + dev = true; + }; + }; }) ]; }