diff --git a/nix-system-configs/modules/lix-default.nix b/nix-system-configs/modules/lix-default.nix index 5ff4a6f..ae38395 100644 --- a/nix-system-configs/modules/lix-default.nix +++ b/nix-system-configs/modules/lix-default.nix @@ -109,5 +109,5 @@ ]; # Enable experimental features for nix command and flakes - nix.settings.experimental-features = [ "nix-command" "flakes" ]; + nix.settings.experimental-features = ["nix-command" "flakes"]; } diff --git a/nix-system-configs/modules/system/database.nix b/nix-system-configs/modules/system/database.nix index 499e8bc..f56ecca 100644 --- a/nix-system-configs/modules/system/database.nix +++ b/nix-system-configs/modules/system/database.nix @@ -59,10 +59,12 @@ in { networking.firewall.allowedTCPPorts = [ 5432 # PostgreSQL 3306 # MariaDB/MySQL + 6379 # Valkey ]; networking.firewall.allowedUDPPorts = [ 5432 # PostgreSQL 3306 # MariaDB/MySQL + 6379 # Valkey ]; # Bootloader. @@ -111,6 +113,48 @@ in { python3Packages.wheel python3Packages.cryptography google-cloud-sdk + + # Valkey (as Redis alternative) + valkey + ]; + + # Systemd service for Valkey (port 6379). Creates config and directories via Nix-managed units. + systemd.services.valkey_6379 = { + description = "Valkey in-memory store (port 6379)"; + wants = ["network.target"]; + after = ["network.target"]; + wantedBy = ["multi-user.target"]; + serviceConfig = { + ExecStart = "${pkgs.valkey}/bin/valkey-server /etc/valkey/6379.conf"; + Restart = "always"; + User = "root"; + RuntimeDirectory = "valkey_6379"; # places runtime dir under /run + # Keep logs in a file (configured below) but also keep unit re-start behavior + }; + # Ensure the service is started at boot + wantedBy = ["multi-user.target"]; + }; + + # Provide the Valkey config file at /etc/valkey/6379.conf + environment.etc = lib.mkOverride 0 (lib.attrsets.union environment.etc { + "valkey/6379.conf" = { + text = '' + # Valkey configuration managed by NixOS + daemonize yes + pidfile /var/run/valkey_6379.pid + port 6379 + loglevel notice + logfile /var/log/valkey_6379.log + dir /var/valkey/6379 + ''; + }; + }); + + # Create data and log directories using systemd tmpfiles rules so paths exist on boot + systemd.tmpfiles.rules = lib.mkForce [ + "d /var/valkey 0755 root root - -" + "d /var/valkey/6379 0755 root root - -" + "f /var/log/valkey_6379.log 0644 root root - -" ]; system.stateVersion = "25.11";