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
cfg = config.services.slimes-server;
cfg = config.services.quick-rust-website;
in
{
options.services.slimes-server = {
options.services.quick-rust-website = {
enable = lib.mkEnableOption "Quick rust website template";
port = lib.mkOption {
type = lib.types.port;
@@ -92,14 +92,14 @@
};
config = lib.mkIf cfg.enable {
systemd.services.slimes-server = {
systemd.services.quick-rust-website = {
description = "Quick rust website template";
after = [ "network.target" ];
wantedBy = [ "multi-user.target" ];
serviceConfig = {
ExecStart = "${
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";
StateDirectory = "quick-rust-website";
DynamicUser = true;

View File

@@ -1,4 +1,5 @@
use axum::{Router, routing::get};
use clap::Parser;
use lazy_static::lazy_static;
use std::sync::Arc;
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 {
app_name: String,
}
#[tokio::main]
async fn main() -> anyhow::Result<()> {
let cli = Cli::parse();
tracing_subscriber::fmt()
.with_max_level(tracing::Level::INFO)
.init();
@@ -39,12 +58,10 @@ async fn main() -> anyhow::Result<()> {
.route("/showcase", get(showcase_handler))
.with_state(shared_state);
let host = false;
let port = "8000";
let addr = if host {
format!("0.0.0.0:{}", port)
let addr = if cli.host {
format!("0.0.0.0:{}", cli.port)
} else {
format!("127.0.0.1:{}", port)
format!("127.0.0.1:{}", cli.port)
};
let listener = tokio::net::TcpListener::bind(&addr).await?;