From 1c9f5ec7ed496f0b1d083d0d1d4f6e45aa80b523 Mon Sep 17 00:00:00 2001 From: mawalu Date: Mon, 17 Jul 2023 22:05:21 +0200 Subject: [PATCH] Nixify --- flake.lock | 130 ++++++++++++++++++++++++++++++++++++++++++++++++++++ flake.nix | 56 ++++++++++++++++++++++ result | 1 + src/main.rs | 2 +- src/smtp.rs | 2 +- 5 files changed, 189 insertions(+), 2 deletions(-) create mode 100644 flake.lock create mode 100644 flake.nix create mode 120000 result diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..af124f5 --- /dev/null +++ b/flake.lock @@ -0,0 +1,130 @@ +{ + "nodes": { + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1689068808, + "narHash": "sha256-6ixXo3wt24N/melDWjq70UuHQLxGV8jZvooRanIHXw0=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "919d646de7be200f3bf08cb76ae1f09402b6f9b4", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "flake-utils_2": { + "inputs": { + "systems": "systems_2" + }, + "locked": { + "lastModified": 1681202837, + "narHash": "sha256-H+Rh19JDwRtpVPAWp64F+rlEtxUWBAQW28eAi3SRSzg=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "cfacdce06f30d2b68473a46042957675eebb3401", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1689534811, + "narHash": "sha256-jnSUdzD/414d94plCyNlvTJJtiTogTep6t7ZgIKIHiE=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "6cee3b5893090b0f5f0a06b4cf42ca4e60e5d222", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1681358109, + "narHash": "sha256-eKyxW4OohHQx9Urxi7TQlFBTDWII+F+x2hklDOQPB50=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "96ba1c52e54e74c3197f4d43026b3f3d92e83ff9", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs", + "rust-overlay": "rust-overlay" + } + }, + "rust-overlay": { + "inputs": { + "flake-utils": "flake-utils_2", + "nixpkgs": "nixpkgs_2" + }, + "locked": { + "lastModified": 1689561325, + "narHash": "sha256-+UABrHUXtWJSc9mM7oEKPIYQEhTzUVVNy2IPG9Lfrj0=", + "owner": "oxalica", + "repo": "rust-overlay", + "rev": "d8a38aea13c67dc2ce10cff93eb274dcf455753f", + "type": "github" + }, + "original": { + "owner": "oxalica", + "repo": "rust-overlay", + "type": "github" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, + "systems_2": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..0712cbb --- /dev/null +++ b/flake.nix @@ -0,0 +1,56 @@ +{ + inputs = { + nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; + flake-utils.url = "github:numtide/flake-utils"; + rust-overlay.url = "github:oxalica/rust-overlay"; + }; + + outputs = { self, nixpkgs, flake-utils, rust-overlay, ... }: + flake-utils.lib.eachDefaultSystem (system: + let + overlays = [ (import rust-overlay) ]; + pkgs = import nixpkgs { inherit system overlays; }; + rustVersion = pkgs.rust-bin.stable.latest.default; + rustPlatform = pkgs.makeRustPlatform { + cargo = rustVersion; + rustc = rustVersion; + }; + myRustBuild = rustPlatform.buildRustPackage { + pname = "tmpmail"; + version = "0.1.0"; + src = ./.; + cargoLock.lockFile = ./Cargo.lock; + }; + in { + defaultPackage = myRustBuild; + devShell = pkgs.mkShell { + buildInputs = + [ (rustVersion.override { extensions = [ "rust-src" ]; }) ]; + }; + nixosModules.default = { config, lib, pkgs, ... }: + with lib; + let cfg = config.mawalu.services.norbert; + in + { + options.mawalu.services.rail = { + enable = mkEnableOption "Enable the rail tmpmail server"; + }; + + config = mkIf cfg.enable { + systemd.services.rail = { + wantedBy = [ "multi-user.target" ]; + + serviceConfig = let pkg = self.packages.${pkgs.system}.default; + in { + Restart = "on-failure"; + ExecStart = "${pkg}/bin/tmpmail"; + DynamicUser = "yes"; + AmbientCapabilities = ["CAP_NET_BIND_SERVICE"]; + }; + }; + }; + }; + + } + ); +} \ No newline at end of file diff --git a/result b/result new file mode 120000 index 0000000..a8b373f --- /dev/null +++ b/result @@ -0,0 +1 @@ +/nix/store/8d9xq25wj423gw523039k5x6i3kaqrdc-tmpmail-0.1.0 \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index a4296d9..1792e4b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -16,7 +16,7 @@ fn main() { let http_state = Arc::clone(&state); let http_thread = thread::spawn(move || { - rouille::start_server("localhost:8005", move |request| { + rouille::start_server("127.0.0.1:8005", move |request| { http::http_handler(request, &http_state) }) }); diff --git a/src/smtp.rs b/src/smtp.rs index 21bb29b..c59b0cc 100644 --- a/src/smtp.rs +++ b/src/smtp.rs @@ -5,7 +5,7 @@ use mailparse::{parse_mail, MailHeaderMap, ParsedMail}; use std::net::{TcpListener, TcpStream}; pub fn start_server(state: State) { - let listener = TcpListener::bind("localhost:8025").unwrap(); + let listener = TcpListener::bind("127.0.0.1:25").unwrap(); for stream in listener.incoming() { match stream {