Add and enable flakes as default.

Add Redis/Valkey database to database.nix
This commit is contained in:
Root User 2026-03-21 12:22:53 +01:00
parent 3a51a068e4
commit ad91f87af6
Signed by: root
GPG key ID: 087F0A95E5766D72
2 changed files with 45 additions and 1 deletions

View file

@ -109,5 +109,5 @@
]; ];
# Enable experimental features for nix command and flakes # Enable experimental features for nix command and flakes
nix.settings.experimental-features = [ "nix-command" "flakes" ]; nix.settings.experimental-features = ["nix-command" "flakes"];
} }

View file

@ -59,10 +59,12 @@ in {
networking.firewall.allowedTCPPorts = [ networking.firewall.allowedTCPPorts = [
5432 # PostgreSQL 5432 # PostgreSQL
3306 # MariaDB/MySQL 3306 # MariaDB/MySQL
6379 # Valkey
]; ];
networking.firewall.allowedUDPPorts = [ networking.firewall.allowedUDPPorts = [
5432 # PostgreSQL 5432 # PostgreSQL
3306 # MariaDB/MySQL 3306 # MariaDB/MySQL
6379 # Valkey
]; ];
# Bootloader. # Bootloader.
@ -111,6 +113,48 @@ in {
python3Packages.wheel python3Packages.wheel
python3Packages.cryptography python3Packages.cryptography
google-cloud-sdk 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"; system.stateVersion = "25.11";