From 1e8a76aca3b522f025998d609a0fefd0398fd5b9 Mon Sep 17 00:00:00 2001 From: Adrian Gunnar Lauterer Date: Sun, 24 Mar 2024 03:34:59 +0100 Subject: [PATCH] added build and module options to flake Co-authored-by: oysteikt --- .devenv/profile | 1 + .gitignore | 2 + Cargo.lock | 170 ++++++++++++++++++++++++++++++++++++++++++++---- Cargo.toml | 1 + default.nix | 0 flake.nix | 62 +++++++++++++++++- src/main.rs | 21 +++++- 7 files changed, 241 insertions(+), 16 deletions(-) create mode 120000 .devenv/profile create mode 100644 default.nix diff --git a/.devenv/profile b/.devenv/profile new file mode 120000 index 0000000..3d7067d --- /dev/null +++ b/.devenv/profile @@ -0,0 +1 @@ +/nix/store/9dql8fkg1cf434x95wccky3g34jkz49l-devenv-profile \ No newline at end of file diff --git a/.gitignore b/.gitignore index ea8c4bf..4cd488d 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ /target + +/results diff --git a/Cargo.lock b/Cargo.lock index c628731..b2fcfdd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -26,6 +26,15 @@ dependencies = [ "memchr", ] +[[package]] +name = "ansi_term" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d52a9bb7ec0cf484c551830a7ce27bd20d67eac647e1befb56b0be4ee39a55d2" +dependencies = [ + "winapi", +] + [[package]] name = "async-stream" version = "0.3.5" @@ -45,7 +54,7 @@ checksum = "16e62a023e7c117e27523144c5d2459f4397fcc3cab0085af8e2224f643a0193" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.48", ] [[package]] @@ -56,7 +65,7 @@ checksum = "c980ee35e870bd1a4d2c8294d4c04d0499e67bca1e4b5cefcc693c2fa00caea9" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.48", ] [[package]] @@ -74,6 +83,17 @@ dependencies = [ "bytemuck", ] +[[package]] +name = "atty" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" +dependencies = [ + "hermit-abi 0.1.19", + "libc", + "winapi", +] + [[package]] name = "autocfg" version = "1.1.0" @@ -140,6 +160,21 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "clap" +version = "2.34.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a0610544180c38b88101fecf2dd634b174a62eef6946f84dfc6a7127512b381c" +dependencies = [ + "ansi_term", + "atty", + "bitflags 1.3.2", + "strsim", + "textwrap", + "unicode-width", + "vec_map", +] + [[package]] name = "cookie" version = "0.18.0" @@ -190,7 +225,7 @@ dependencies = [ "proc-macro2", "proc-macro2-diagnostics", "quote", - "syn", + "syn 2.0.48", ] [[package]] @@ -376,6 +411,24 @@ version = "0.14.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604" +[[package]] +name = "heck" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d621efb26863f0e9924c6ac577e8275e5e6b77455db64ffa6c65c904e9e132c" +dependencies = [ + "unicode-segmentation", +] + +[[package]] +name = "hermit-abi" +version = "0.1.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" +dependencies = [ + "libc", +] + [[package]] name = "hermit-abi" version = "0.3.4" @@ -463,7 +516,7 @@ version = "0.4.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0bad00257d07be169d870ab665980b06cdb366d792ad690bf2e76876dc503455" dependencies = [ - "hermit-abi", + "hermit-abi 0.3.4", "rustix", "windows-sys 0.52.0", ] @@ -600,7 +653,7 @@ version = "1.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" dependencies = [ - "hermit-abi", + "hermit-abi 0.3.4", "libc", ] @@ -633,6 +686,7 @@ dependencies = [ "rocket", "serde", "serde_json", + "structopt", "uuid", ] @@ -679,7 +733,7 @@ dependencies = [ "proc-macro2", "proc-macro2-diagnostics", "quote", - "syn", + "syn 2.0.48", ] [[package]] @@ -712,6 +766,30 @@ version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" +[[package]] +name = "proc-macro-error" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c" +dependencies = [ + "proc-macro-error-attr", + "proc-macro2", + "quote", + "syn 1.0.109", + "version_check", +] + +[[package]] +name = "proc-macro-error-attr" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" +dependencies = [ + "proc-macro2", + "quote", + "version_check", +] + [[package]] name = "proc-macro2" version = "1.0.78" @@ -729,7 +807,7 @@ checksum = "af066a9c399a26e020ada66a034357a868728e72cd426f3adcd35f80d88d88c8" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.48", "version_check", "yansi", ] @@ -799,7 +877,7 @@ checksum = "5fddb4f8d99b0a2ebafc65a87a69a7b9875e4b1ae1f00db265d300ef7f28bccc" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.48", ] [[package]] @@ -897,7 +975,7 @@ dependencies = [ "proc-macro2", "quote", "rocket_http", - "syn", + "syn 2.0.48", "unicode-xid", "version_check", ] @@ -990,7 +1068,7 @@ checksum = "33c85360c95e7d137454dc81d9a4ed2b8efd8fbe19cee57357b32b9771fccb67" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.48", ] [[package]] @@ -1080,6 +1158,47 @@ dependencies = [ "loom", ] +[[package]] +name = "strsim" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" + +[[package]] +name = "structopt" +version = "0.3.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c6b5c64445ba8094a6ab0c3cd2ad323e07171012d9c98b0b15651daf1787a10" +dependencies = [ + "clap", + "lazy_static", + "structopt-derive", +] + +[[package]] +name = "structopt-derive" +version = "0.4.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dcb5ae327f9cc13b68763b5749770cb9e048a99bd9dfdfa58d0cf05d5f64afe0" +dependencies = [ + "heck", + "proc-macro-error", + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "syn" +version = "1.0.109" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + [[package]] name = "syn" version = "2.0.48" @@ -1104,6 +1223,15 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "textwrap" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060" +dependencies = [ + "unicode-width", +] + [[package]] name = "thread_local" version = "1.1.7" @@ -1169,7 +1297,7 @@ checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.48", ] [[package]] @@ -1256,7 +1384,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.48", ] [[package]] @@ -1329,6 +1457,18 @@ version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" +[[package]] +name = "unicode-segmentation" +version = "1.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d4c87d22b6e3f4a18d4d40ef354e97c90fcb14dd91d7dc0aa9d8a1172ebf7202" + +[[package]] +name = "unicode-width" +version = "0.1.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e51733f11c9c4f72aa0c160008246859e340b00807569a0da0e7a1079b27ba85" + [[package]] name = "unicode-xid" version = "0.2.4" @@ -1351,6 +1491,12 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" +[[package]] +name = "vec_map" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191" + [[package]] name = "version_check" version = "0.9.4" diff --git a/Cargo.toml b/Cargo.toml index 898b613..a0c8ef9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,6 +8,7 @@ edition = "2021" [dependencies] rocket = { version = "0.5.0", features = ["json", "uuid"] } serde = "1.0.196" +structopt = "0.3" rand = "0.8.5" serde_json = "1.0.113" diff --git a/default.nix b/default.nix new file mode 100644 index 0000000..e69de29 diff --git a/flake.nix b/flake.nix index 2761a7a..4f31328 100644 --- a/flake.nix +++ b/flake.nix @@ -2,16 +2,18 @@ inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; devenv.url = "github:cachix/devenv"; - fenix.url = "github:nix-community/fenix"; fenix.inputs.nixpkgs.follows = "nixpkgs"; }; - outputs = { self, nixpkgs, devenv, ... }@inputs: + outputs = { self, fenix, nixpkgs, devenv, ... }@inputs: let + toolchain = fenix.packages.x86_64-linux.minimal.toolchain; pkgs = import nixpkgs { system = "x86_64-linux"; }; + lib = pkgs.lib; + types = lib.types; in { devShell.x86_64-linux = devenv.lib.mkShell { inherit inputs pkgs; @@ -24,5 +26,59 @@ } ]; }; + + packages.x86_64-linux.default = (pkgs.makeRustPlatform { + cargo = toolchain; + rustc = toolchain; + }).buildRustPackage { + pname = "ozai"; + version = "0.1.0"; + src = ./.; + cargoLock.lockFile = ./Cargo.lock; + }; + + nixosModules = { + ozai = { config, pkgs, ... }: { + options.services.ozai = { + enable = lib.mkEnableOption "Ozai Azul server"; + host = lib.mkOption { + type = types.str; + default = "127.0.0.1"; + description = "The host to run the server on"; + }; + port = lib.mkOption { + type = types.int; + default = 8000; + description = "The port to run the server on"; + }; + }; + config = lib.mkIf config.services.ozai.enable { + systemd.services.ozai = { + description = "Ozai Azul server"; + after = [ "network.target" ]; + wantedBy = [ "multi-user.target" ]; + serviceConfig = { + ExecStart = "${self.packages.x86_64-linux.default}/bin/ozai --port ${toString config.services.ozai.port} --host '${config.services.ozai.host}'"; + Restart = "always"; + }; + }; + }; + }; + }; + + nixosConfigurations = { + ozai = nixpkgs.lib.nixosSystem { + system = "x86_64-linux"; + modules = [ + self.nixosModules.ozai + { + system.stateVersion = "23.11"; + boot.isContainer = true; + services.ozai.enable = true; + } + ]; + }; + }; + }; -} +} \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index c021f48..7f0ad73 100644 --- a/src/main.rs +++ b/src/main.rs @@ -83,10 +83,29 @@ enum NewGameOptions { Premade { game: azul::GameState }, } +use structopt::StructOpt; + +#[derive(StructOpt)] +struct Cli { + #[structopt(long = "host", default_value = "127.0.0.1")] + host: String, + #[structopt(long = "port", default_value = "8000")] + port: u16, +} + #[launch] fn rocket() -> _ { + let args = Cli::from_args(); + let host = args.host; + let port = args.port; + rocket::build() + .configure(rocket::Config { + address: host.parse().unwrap(), + port, + ..Default::default() + }) .manage(SharedState::default()) .mount("/", routes![index]) .mount("/api/", routes![get_game, new_game, make_move]) -} +} \ No newline at end of file