added nix flake to use the server in nixos

This commit is contained in:
2026-03-24 19:45:08 +01:00
parent e70eb68e38
commit a7ffaaeffb
4 changed files with 111 additions and 1 deletions

1
.gitignore vendored
View File

@@ -1 +1,2 @@
/target /target
/result

27
flake.lock generated Normal file
View File

@@ -0,0 +1,27 @@
{
"nodes": {
"nixpkgs": {
"locked": {
"lastModified": 1774106199,
"narHash": "sha256-US5Tda2sKmjrg2lNHQL3jRQ6p96cgfWh3J1QBliQ8Ws=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "6c9a78c09ff4d6c21d0319114873508a6ec01655",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixos-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"nixpkgs": "nixpkgs"
}
}
},
"root": "root",
"version": 7
}

82
flake.nix Normal file
View File

@@ -0,0 +1,82 @@
{
description = "Slimes Benchmark Server";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
};
outputs =
{ self, nixpkgs }:
let
supportedSystems = [
"x86_64-linux"
];
forAllSystems = nixpkgs.lib.genAttrs supportedSystems;
in
{
packages = forAllSystems (
system:
let
pkgs = import nixpkgs { inherit system; };
in
{
default = pkgs.rustPlatform.buildRustPackage {
pname = "slimes-server";
version = "0.1.0";
src = ./server;
cargoLock.lockFile = ./server/Cargo.lock;
nativeBuildInputs = [ pkgs.pkg-config ];
buildInputs = [ pkgs.sqlite ];
# doCheck = false;
};
}
);
nixosModules.default =
{
config,
lib,
pkgs,
...
}:
let
cfg = config.services.slimes-server;
in
{
options.services.slimes-server = {
enable = lib.mkEnableOption "Slimes Server";
port = lib.mkOption {
type = lib.types.port;
default = 9003;
};
databasePath = lib.mkOption {
type = lib.types.str;
default = "/var/lib/slimes-server/slimes.db";
};
};
config = lib.mkIf cfg.enable {
systemd.services.slimes-server = {
description = "Slimes Benchmark Server";
after = [ "network.target" ];
wantedBy = [ "multi-user.target" ];
serviceConfig = {
ExecStart = "${
self.packages.${pkgs.system}.default
}/bin/slimes-server --database-url ${cfg.databasePath} --port ${toString cfg.port}";
Restart = "on-failure";
StateDirectory = "slimes-server";
DynamicUser = true;
ProtectSystem = "strict";
ProtectHome = true;
NoNewPrivileges = true;
};
};
};
};
};
}

View File

@@ -1,5 +1,5 @@
[package] [package]
name = "server" name = "slimes-server"
version = "0.1.0" version = "0.1.0"
edition = "2024" edition = "2024"