From 67561673e438acc5ba1f8b5734705350aa6a8fd0 Mon Sep 17 00:00:00 2001 From: Jonni Liljamo Date: Mon, 13 Jan 2025 20:10:49 +0200 Subject: [PATCH] feat: init --- .cargo/config.toml | 3 + .envrc | 1 + .gitignore | 3 + Cargo.lock | 15 +++++ Cargo.toml | 3 + README.md | 55 ++++++++++++++++++ felu-common/Cargo.toml | 6 ++ felu-common/src/lib.rs | 14 +++++ felu-mgmt/Cargo.toml | 6 ++ felu-mgmt/src/main.rs | 3 + felu-ns/Cargo.toml | 6 ++ felu-ns/src/main.rs | 3 + flake.lock | 129 +++++++++++++++++++++++++++++++++++++++++ flake.nix | 99 +++++++++++++++++++++++++++++++ rust-toolchain.toml | 2 + 15 files changed, 348 insertions(+) create mode 100644 .cargo/config.toml create mode 100644 .envrc create mode 100644 .gitignore create mode 100644 Cargo.lock create mode 100644 Cargo.toml create mode 100644 README.md create mode 100644 felu-common/Cargo.toml create mode 100644 felu-common/src/lib.rs create mode 100644 felu-mgmt/Cargo.toml create mode 100644 felu-mgmt/src/main.rs create mode 100644 felu-ns/Cargo.toml create mode 100644 felu-ns/src/main.rs create mode 100644 flake.lock create mode 100644 flake.nix create mode 100644 rust-toolchain.toml diff --git a/.cargo/config.toml b/.cargo/config.toml new file mode 100644 index 0000000..d29d6c3 --- /dev/null +++ b/.cargo/config.toml @@ -0,0 +1,3 @@ +[target.x86_64-unknown-linux-gnu] +linker = "clang" +rustflags = ["-C", "link-arg=-fuse-ld=mold"] diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..c4b17d7 --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +use_flake diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..91d998e --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +/.direnv/ +/.pre-commit-config.yaml +/target/ diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..342c71b --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,15 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "felu-common" +version = "0.1.0" + +[[package]] +name = "felu-mgmt" +version = "0.1.0" + +[[package]] +name = "felu-ns" +version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..afa171a --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,3 @@ +[workspace] +resolver = "2" +members = ["felu-mgmt", "felu-ns", "felu-common"] diff --git a/README.md b/README.md new file mode 100644 index 0000000..15a4021 --- /dev/null +++ b/README.md @@ -0,0 +1,55 @@ +# felu + +WIP, ignore for now. + +## Crates +### bin +#### felu-mgmt +UI for management. + +Leptos, not sure about SSR or CSR yet, CSR might be easier. +Local accounts to begin with, SSO via OIDC *maybe*. + +Connects to configured felu-ns servers. Health checked connections and retry +connections if dropped. + +* [Leptos](https://github.com/leptos-rs/leptos) for UI +* [axum](https://github.com/tokio-rs/axum) as web framework +* [tower-sessions](https://github.com/maxcountryman/tower-sessions) as session store for axum +* [sqlx](https://github.com/launchbadge/sqlx) for PostgreSQL + +#### felu-ns +Nameserver. + +Many, hosted as ns1, ns2, nsN, ns9. + +Requires a static public IPv4, which is used as the DNS (At least Do53 (Port 53 +over UDP and TCP). Possibly DoT, DoH and DoQ in the future) interface. + +Optionally the same interface used for DNS can be used as the interface that +felu-mgmt connects to for management. +Though ideally management is done via a VPN connection (e.g. Tailscale) and not +via a public interface. + +Completely stateless, receives configuration from felu-mgmt and stores it in +memory. Stores nothing to disk. + +Built-in HTTP server for things like Prometheus metrics at /metrics. + +* [hickory-dns](https://github.com/hickory-dns/hickory-dns) as the DNS library, should support everything needed +* [hyper](https://github.com/hyperium/hyper) for HTTP server + +### lib +#### felu-common +Protobuf definitions and other shared structures. + +## Initial notes: +### Communication +Certs! + +Protobufs over gRPC or just TCP? +Which is easier when we need a stream? + +One-way stream? Mgmt sends data to ns, and ns can respond Results to received +messages, but not send messages to mgmt. + diff --git a/felu-common/Cargo.toml b/felu-common/Cargo.toml new file mode 100644 index 0000000..b3074ec --- /dev/null +++ b/felu-common/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "felu-common" +version = "0.1.0" +edition = "2021" + +[dependencies] diff --git a/felu-common/src/lib.rs b/felu-common/src/lib.rs new file mode 100644 index 0000000..b93cf3f --- /dev/null +++ b/felu-common/src/lib.rs @@ -0,0 +1,14 @@ +pub fn add(left: u64, right: u64) -> u64 { + left + right +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn it_works() { + let result = add(2, 2); + assert_eq!(result, 4); + } +} diff --git a/felu-mgmt/Cargo.toml b/felu-mgmt/Cargo.toml new file mode 100644 index 0000000..1a84c27 --- /dev/null +++ b/felu-mgmt/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "felu-mgmt" +version = "0.1.0" +edition = "2021" + +[dependencies] diff --git a/felu-mgmt/src/main.rs b/felu-mgmt/src/main.rs new file mode 100644 index 0000000..e7a11a9 --- /dev/null +++ b/felu-mgmt/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + println!("Hello, world!"); +} diff --git a/felu-ns/Cargo.toml b/felu-ns/Cargo.toml new file mode 100644 index 0000000..8822c87 --- /dev/null +++ b/felu-ns/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "felu-ns" +version = "0.1.0" +edition = "2021" + +[dependencies] diff --git a/felu-ns/src/main.rs b/felu-ns/src/main.rs new file mode 100644 index 0000000..e7a11a9 --- /dev/null +++ b/felu-ns/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + println!("Hello, world!"); +} diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..5ecd18f --- /dev/null +++ b/flake.lock @@ -0,0 +1,129 @@ +{ + "nodes": { + "flake-compat": { + "flake": false, + "locked": { + "lastModified": 1696426674, + "narHash": "sha256-kvjfFW7WAETZlt09AgDn1MrtKzP7t90Vf7vypd3OL1U=", + "owner": "edolstra", + "repo": "flake-compat", + "rev": "0f9255e01c2351cc7d116c072cb317785dd33b33", + "type": "github" + }, + "original": { + "owner": "edolstra", + "repo": "flake-compat", + "type": "github" + } + }, + "flake-parts": { + "inputs": { + "nixpkgs-lib": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1736143030, + "narHash": "sha256-+hu54pAoLDEZT9pjHlqL9DNzWz0NbUn8NEAHP7PQPzU=", + "owner": "hercules-ci", + "repo": "flake-parts", + "rev": "b905f6fc23a9051a6e1b741e1438dbfc0634c6de", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "flake-parts", + "type": "github" + } + }, + "gitignore": { + "inputs": { + "nixpkgs": [ + "pre-commit-hooks", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1709087332, + "narHash": "sha256-HG2cCnktfHsKV0s4XW83gU3F57gaTljL9KNSuG6bnQs=", + "owner": "hercules-ci", + "repo": "gitignore.nix", + "rev": "637db329424fd7e46cf4185293b9cc8c88c95394", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "gitignore.nix", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1736755442, + "narHash": "sha256-a3MMEY7i/wdF0gb7WFNTn6onzaiMOvwj7OerRVenA8o=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "ef56e777fedaa4da8c66a150081523c5de1e0171", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "pre-commit-hooks": { + "inputs": { + "flake-compat": "flake-compat", + "gitignore": "gitignore", + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1735882644, + "narHash": "sha256-3FZAG+pGt3OElQjesCAWeMkQ7C/nB1oTHLRQ8ceP110=", + "owner": "cachix", + "repo": "git-hooks.nix", + "rev": "a5a961387e75ae44cc20f0a57ae463da5e959656", + "type": "github" + }, + "original": { + "owner": "cachix", + "repo": "git-hooks.nix", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-parts": "flake-parts", + "nixpkgs": "nixpkgs", + "pre-commit-hooks": "pre-commit-hooks", + "rust-overlay": "rust-overlay" + } + }, + "rust-overlay": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1736735482, + "narHash": "sha256-QOA4jCDyyUM9Y2Vba+HSZ/5LdtCMGaTE/7NkkUzBr50=", + "owner": "oxalica", + "repo": "rust-overlay", + "rev": "cf960a1938ee91200fe0d2f7b2582fde2429d562", + "type": "github" + }, + "original": { + "owner": "oxalica", + "repo": "rust-overlay", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..ed4b4a9 --- /dev/null +++ b/flake.nix @@ -0,0 +1,99 @@ +{ + inputs = { + nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable"; + flake-parts = { + url = "github:hercules-ci/flake-parts"; + inputs.nixpkgs-lib.follows = "nixpkgs"; + }; + + pre-commit-hooks = { + url = "github:cachix/git-hooks.nix"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + + rust-overlay = { + url = "github:oxalica/rust-overlay"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + }; + + outputs = inputs @ { + self, + nixpkgs, + flake-parts, + pre-commit-hooks, + rust-overlay, + ... + }: + flake-parts.lib.mkFlake {inherit inputs;} { + systems = ["x86_64-linux"]; + perSystem = { + config, + lib, + pkgs, + system, + ... + }: let + toolchain = pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml; + libs = []; + in { + _module.args.pkgs = import inputs.nixpkgs { + inherit system; + overlays = [inputs.rust-overlay.overlays.default]; + }; + + checks.pre-commit-check = pre-commit-hooks.lib.${system}.run { + src = ./.; + hooks = { + # Nix formatting + alejandra.enable = true; + + # Toml formatting + taplo.enable = true; + + # Rust formatting and linting + rustfmt = { + enable = true; + packageOverrides = { + cargo = toolchain; + rustfmt = toolchain; + }; + }; + clippy = { + enable = true; + packageOverrides = { + cargo = toolchain; + clippy = toolchain; + }; + settings = { + denyWarnings = true; + }; + }; + + # Spell checking + typos.enable = true; + }; + }; + + devShells.default = pkgs.mkShell { + buildInputs = with pkgs; + [ + mold + + clang + + dig + ] + ++ libs + ++ [ + toolchain + self.checks.${system}.pre-commit-check.enabledPackages + ]; + LD_LIBRARY_PATH = lib.makeLibraryPath libs; + shellHook = '' + ${self.checks.${system}.pre-commit-check.shellHook} + ''; + }; + }; + }; +} diff --git a/rust-toolchain.toml b/rust-toolchain.toml new file mode 100644 index 0000000..efd9dc3 --- /dev/null +++ b/rust-toolchain.toml @@ -0,0 +1,2 @@ +[toolchain] +channel = "1.84.0" -- 2.44.1