smo-server/flake.nix

123 lines
3.7 KiB
Nix
Raw Normal View History

2024-12-16 02:28:13 -05:00
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
fenix = {
url = "github:nix-community/fenix";
inputs.nixpkgs.follows = "nixpkgs";
};
2024-12-21 06:35:44 -05:00
crane = {
url = "github:ipetkov/crane";
};
2024-12-16 02:28:13 -05:00
};
2024-12-20 21:35:43 -05:00
outputs = {
self,
nixpkgs,
flake-utils,
fenix,
2024-12-22 00:37:16 -05:00
crane,
2024-12-20 21:35:43 -05:00
}:
2024-12-16 02:28:13 -05:00
flake-utils.lib.eachDefaultSystem
2024-12-20 21:35:43 -05:00
(
system: let
overlays = [fenix.overlays.default];
pkgs = import nixpkgs {
inherit system overlays;
};
2024-12-21 06:35:44 -05:00
craneLib = crane.mkLib pkgs;
commonArgs = {
src = craneLib.cleanCargoSource ./.;
strictDeps = true;
nativeBuildInputs = with pkgs; [pkg-config cmake];
2024-12-22 00:37:16 -05:00
buildInputs = with pkgs;
[
openssl
zlib-ng
]
++ lib.optionals stdenv.isDarwin [
libiconv
];
2024-12-21 06:35:44 -05:00
};
2024-12-20 21:35:43 -05:00
in
with pkgs; {
2024-12-16 02:28:13 -05:00
devShells.default = mkShell {
buildInputs = [
pkgs.fenix.stable.completeToolchain
pkg-config
openssl
];
};
2024-12-22 00:37:16 -05:00
packages.default = craneLib.buildPackage (commonArgs
// {
cargoArtifacts = craneLib.buildDepsOnly commonArgs;
});
2024-12-22 01:31:20 -05:00
formatter = alejandra;
}
)
2024-12-22 02:09:26 -05:00
// flake-utils.lib.eachDefaultSystemPassThrough (system: {
nixosModules.default = {
config,
lib,
pkgs,
...
}: {
options.services.smo-server = {
enable = lib.mkEnableOption "a game server for Super Mario Odyssey Online";
user = lib.mkOption {
type = lib.types.string;
description = "The user to start the server with";
};
enableFaker = lib.mkOption {
type = lib.types.bool;
default = false;
example = true;
description = "Whether to enable the test bot for solo development.";
};
tcpPort = lib.mkOption {
type = lib.types.port;
default = 1027;
2024-12-22 02:09:26 -05:00
description = "The TCP port to host the server on";
};
udpPort = lib.mkOption {
type = lib.types.port;
default = 1027;
2024-12-22 02:09:26 -05:00
description = "The UDP port to host the server on";
};
proximity = {
type = lib.types.attrs;
port = lib.mkOption {
2024-12-22 01:31:20 -05:00
type = lib.types.port;
example = 4433;
2024-12-22 02:09:26 -05:00
description = "The UDP port to host the proximity chat server on";
2024-12-22 01:31:20 -05:00
};
2024-12-22 02:09:26 -05:00
certPath = lib.mkOption {
type = lib.types.path;
example = "cert.pem";
description = "The certificate used for encrypting the WebTransport stream";
2024-12-22 01:31:20 -05:00
};
2024-12-22 02:09:26 -05:00
keyPath = lib.mkOption {
type = lib.types.path;
example = "cert.pem";
description = "The certificate used for encrypting the WebTransport stream";
2024-12-22 00:37:16 -05:00
};
2024-12-22 01:31:20 -05:00
};
2024-12-22 02:09:26 -05:00
};
config = lib.mkIf config.services.smo-server.enable {
systemd.services.smo-server = with config.services.smo-server; {
wantedBy = ["multi-user.target"];
after = ["network.target"];
description = "Start smo-server";
serviceConfig = {
WorkingDirectory = "${self.packages.${system}.default}";
Type = "simple";
ExecStart = let
proxRes = 5;
in ''${self.packages.${system}.default}/bin/smo-server -t ${toString tcpPort} -u ${toString udpPort}'';
2024-12-22 00:37:16 -05:00
};
2024-12-22 01:38:05 -05:00
};
2024-12-22 01:31:20 -05:00
};
2024-12-22 02:09:26 -05:00
};
});
2024-12-16 02:28:13 -05:00
}