From 450c629288f3aa46d5d6c038ae916de3c72fec47 Mon Sep 17 00:00:00 2001 From: Seongmin Lee Date: Tue, 16 Dec 2025 06:03:55 +0000 Subject: [PATCH] nix,spindle: use `DATA_DIR` for db & other spindle data This single persistent directory can be used for storing general spindle data like db, motd file and upcoming sparse-clone git repos. db path will be `${DATA_DIR}/spindle.db` Signed-off-by: Seongmin Lee --- nix/modules/spindle.nix | 8 ++++---- nix/vm.nix | 2 +- spindle/config/config.go | 7 ++++++- 3 file(s) changed, 11 insertion(s)(+), 6 deletion(s)(-) diff --git a/nix/modules/spindle.nix b/nix/modules/spindle.nix --- a/nix/modules/spindle.nix +++ b/nix/modules/spindle.nix @@ -25,10 +25,10 @@ default = "0.0.0.0:6555"; description = "Address to listen on"; }; - dbPath = mkOption { + stateDir = mkOption { type = types.path; - default = "/var/lib/spindle/spindle.db"; - description = "Path to the database file"; + default = "/var/lib/spindle"; + description = "Tangled spindle data directory"; }; hostname = mkOption { @@ -137,7 +137,7 @@ LogsDirectory = "spindle"; StateDirectory = "spindle"; Environment = [ "SPINDLE_SERVER_LISTEN_ADDR=${cfg.server.listenAddr}" - "SPINDLE_SERVER_DB_PATH=${cfg.server.dbPath}" + "SPINDLE_SERVER_DATA_DIR=${cfg.server.stateDir}" "SPINDLE_SERVER_HOSTNAME=${cfg.server.hostname}" "SPINDLE_SERVER_PLC_URL=${cfg.server.plcUrl}" "SPINDLE_SERVER_RELAY_URL=${cfg.server.relayUrl}" diff --git a/nix/vm.nix b/nix/vm.nix --- a/nix/vm.nix +++ b/nix/vm.nix @@ -140,7 +140,7 @@ serviceConfig.PermissionsStartOnly = true; }; in { knot = mkDataSyncScripts "/mnt/knot-data" config.services.tangled.knot.stateDir; - spindle = mkDataSyncScripts "/mnt/spindle-data" (builtins.dirOf config.services.tangled.spindle.server.dbPath); + spindle = mkDataSyncScripts "/mnt/spindle-data" config.services.tangled.spindle.server.stateDir; }; }) ]; diff --git a/spindle/config/config.go b/spindle/config/config.go --- a/spindle/config/config.go +++ b/spindle/config/config.go @@ -3,6 +3,7 @@ import ( "context" "fmt" + "path/filepath" "github.com/bluesky-social/indigo/atproto/syntax" "github.com/sethvargo/go-envconfig" @@ -10,7 +11,6 @@ ) type Server struct { ListenAddr string `env:"LISTEN_ADDR, default=0.0.0.0:6555"` - DBPath string `env:"DB_PATH, default=spindle.db"` Hostname string `env:"HOSTNAME, required"` TapDBUrl string `env:"TAP_DB_URL, default=sqlite://./spindle-tap.db"` TapPort string `env:"TAP_PORT, default=6480"` @@ -20,12 +20,17 @@ Dev bool `env:"DEV, default=false"` Owner syntax.DID `env:"OWNER, required"` Secrets Secrets `env:",prefix=SECRETS_"` LogDir string `env:"LOG_DIR, default=/var/log/spindle"` + DataDir string `env:"DATA_DIR, default=/var/lib/spindle"` QueueSize int `env:"QUEUE_SIZE, default=100"` MaxJobCount int `env:"MAX_JOB_COUNT, default=2"` // max number of jobs that run at a time } func (s Server) Did() syntax.DID { return syntax.DID(fmt.Sprintf("did:web:%s", s.Hostname)) +} + +func (s Server) DBPath() string { + return filepath.Join(s.DataDir, "spindle.db") } type Secrets struct { -- tangled.sh