added clap to configure port and interfaces, and fixed nixos module

This commit is contained in:
2026-03-26 19:33:30 +01:00
parent 81686d6fb8
commit 26b12e9dca
2 changed files with 132 additions and 115 deletions

View File

@@ -76,10 +76,10 @@
... ...
}: }:
let let
cfg = config.services.slimes-server; cfg = config.services.quick-rust-website;
in in
{ {
options.services.slimes-server = { options.services.quick-rust-website = {
enable = lib.mkEnableOption "Quick rust website template"; enable = lib.mkEnableOption "Quick rust website template";
port = lib.mkOption { port = lib.mkOption {
type = lib.types.port; type = lib.types.port;
@@ -92,14 +92,14 @@
}; };
config = lib.mkIf cfg.enable { config = lib.mkIf cfg.enable {
systemd.services.slimes-server = { systemd.services.quick-rust-website = {
description = "Quick rust website template"; description = "Quick rust website template";
after = [ "network.target" ]; after = [ "network.target" ];
wantedBy = [ "multi-user.target" ]; wantedBy = [ "multi-user.target" ];
serviceConfig = { serviceConfig = {
ExecStart = "${ ExecStart = "${
self.packages.${pkgs.system}.default self.packages.${pkgs.system}.default
}/bin/quick-rust-website --database-url ${cfg.databasePath} --port ${toString cfg.port}"; }/bin/quick-rust-website --port ${toString cfg.port} --host";
Restart = "on-failure"; Restart = "on-failure";
StateDirectory = "quick-rust-website"; StateDirectory = "quick-rust-website";
DynamicUser = true; DynamicUser = true;

View File

@@ -1,4 +1,5 @@
use axum::{Router, routing::get}; use axum::{Router, routing::get};
use clap::Parser;
use lazy_static::lazy_static; use lazy_static::lazy_static;
use std::sync::Arc; use std::sync::Arc;
use tera::Tera; use tera::Tera;
@@ -20,12 +21,30 @@ lazy_static! {
}; };
} }
#[derive(clap::Parser, Debug)]
#[command(author, version, about, long_about = None)]
pub struct Cli {
/// Port to serve on
#[arg(short, long, default_value = "8000")]
port: String,
/// Whether to listen on 0.0.0.0
#[arg(short, long)]
host: bool,
/// Verbose mode
#[arg(short, long)]
verbose: bool,
}
struct AppState { struct AppState {
app_name: String, app_name: String,
} }
#[tokio::main] #[tokio::main]
async fn main() -> anyhow::Result<()> { async fn main() -> anyhow::Result<()> {
let cli = Cli::parse();
tracing_subscriber::fmt() tracing_subscriber::fmt()
.with_max_level(tracing::Level::INFO) .with_max_level(tracing::Level::INFO)
.init(); .init();
@@ -39,12 +58,10 @@ async fn main() -> anyhow::Result<()> {
.route("/showcase", get(showcase_handler)) .route("/showcase", get(showcase_handler))
.with_state(shared_state); .with_state(shared_state);
let host = false; let addr = if cli.host {
let port = "8000"; format!("0.0.0.0:{}", cli.port)
let addr = if host {
format!("0.0.0.0:{}", port)
} else { } else {
format!("127.0.0.1:{}", port) format!("127.0.0.1:{}", cli.port)
}; };
let listener = tokio::net::TcpListener::bind(&addr).await?; let listener = tokio::net::TcpListener::bind(&addr).await?;