DEVELOPMENT ENVIRONMENT

~liljamo/felu-ng

67561673e438acc5ba1f8b5734705350aa6a8fd0 — Jonni Liljamo 4 days ago
feat: init
A  => .cargo/config.toml +3 -0
@@ 1,3 @@
[target.x86_64-unknown-linux-gnu]
linker = "clang"
rustflags = ["-C", "link-arg=-fuse-ld=mold"]

A  => .envrc +1 -0
@@ 1,1 @@
use_flake

A  => .gitignore +3 -0
@@ 1,3 @@
/.direnv/
/.pre-commit-config.yaml
/target/

A  => Cargo.lock +15 -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"

A  => Cargo.toml +3 -0
@@ 1,3 @@
[workspace]
resolver = "2"
members = ["felu-mgmt", "felu-ns", "felu-common"]

A  => README.md +55 -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.


A  => felu-common/Cargo.toml +6 -0
@@ 1,6 @@
[package]
name = "felu-common"
version = "0.1.0"
edition = "2021"

[dependencies]

A  => felu-common/src/lib.rs +14 -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);
    }
}

A  => felu-mgmt/Cargo.toml +6 -0
@@ 1,6 @@
[package]
name = "felu-mgmt"
version = "0.1.0"
edition = "2021"

[dependencies]

A  => felu-mgmt/src/main.rs +3 -0
@@ 1,3 @@
fn main() {
    println!("Hello, world!");
}

A  => felu-ns/Cargo.toml +6 -0
@@ 1,6 @@
[package]
name = "felu-ns"
version = "0.1.0"
edition = "2021"

[dependencies]

A  => felu-ns/src/main.rs +3 -0
@@ 1,3 @@
fn main() {
    println!("Hello, world!");
}

A  => flake.lock +129 -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
}

A  => flake.nix +99 -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}
          '';
        };
      };
    };
}

A  => rust-toolchain.toml +2 -0
@@ 1,2 @@
[toolchain]
channel = "1.84.0"