{ 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"; }; crane = { url = "github:ipetkov/crane"; }; }; outputs = { self, nixpkgs, flake-utils, fenix, crane, }: flake-utils.lib.eachDefaultSystem ( system: let overlays = [fenix.overlays.default]; pkgs = import nixpkgs { inherit system overlays; }; craneLib = crane.mkLib pkgs; commonArgs = { src = craneLib.cleanCargoSource ./.; strictDeps = true; nativeBuildInputs = with pkgs; [pkg-config cmake]; buildInputs = with pkgs; [ openssl zlib-ng ] ++ lib.optionals stdenv.isDarwin [ libiconv ]; }; in with pkgs; { devShells.default = mkShell { buildInputs = [ pkgs.fenix.stable.completeToolchain pkg-config openssl ]; }; formatter = pkgs.alejandra; packages.default = craneLib.buildPackage (commonArgs // { cargoArtifacts = craneLib.buildDepsOnly commonArgs; }); nixosModules.default = with lib; { config, ... }: { options.services.smo-server = { enable = mkEnableOption "a game server for Super Mario Odyssey Online"; user = mkOption { type = lib.types.string; description = "The user to start the server with"; }; enableFaker = mkOption { type = lib.types.bool; default = false; example = true; description = "Whether to enable the test bot for solo development."; }; tcpPort = mkOption { type = lib.types.port; default = 1027; description = "The TCP port to host the server on"; }; udpPort = mkOption { type = lib.types.port; default = 1027; description = "The UDP port to host the server on"; }; proximity = { type = lib.types.attrs; port = { type = lib.types.port; example = 4433; description = "The UDP port to host the proximity chat server on"; }; certPath = { type = lib.types.path; example = "cert.pem"; description = "The certificate used for encrypting the WebTransport stream"; }; keyPath = { type = lib.types.path; example = "cert.pem"; description = "The certificate used for encrypting the WebTransport stream"; }; }; }; config = mkIf config.services.smo-server.enable { systemd.services.smo-server = with services.smo-server; { wantedBy = ["multi-user.target"]; after = ["network.target"]; description = "Start smo-server"; serviceConfig = { WorkingDirectory = "${packages.default.outPath}"; Type = "simple"; ExecStart = let proxRes = 5; in ''${packages.default.outPath}/bin/smo-server -t ${tcpPort} -u ${udpPort} ${proxRes}''; }; }; }; }; } ); }