feat: init

This commit is contained in:
steveej 2024-12-23 11:55:36 +01:00
commit c839eeded1
16 changed files with 3772 additions and 0 deletions

5
flake.nix Normal file
View file

@ -0,0 +1,5 @@
{
outputs = _: {
templates.default.path = ./templates/default;
};
}

12
templates/default/.envrc Normal file
View file

@ -0,0 +1,12 @@
#!/usr/bin/env bash
# Used by https://direnv.net
# Automatically reload when this file changes
watch_file ./nix/devshells/default.nix
watch_file ./nix/*.nix
# Load `nix develop`
use flake .#rust
# Extend the environment with per-user overrides
source_env_if_exists .envrc.local

24
templates/default/.gitignore vendored Normal file
View file

@ -0,0 +1,24 @@
# direnv
.direnv/
.env
.envrc.local
# nix
result
result-*
# rust
target/
# nixago: ignore-linked-files
/treefmt.toml
# nats
rust/*/tmp
rust/*/jwt
rust/*/*/test_leaf_server.conf
rust/*/*/leaf_server.conf
rust/*/*/resolver.conf
leaf_server.conf
.local

18
templates/default/.vscode/settings.json vendored Normal file
View file

@ -0,0 +1,18 @@
{
"editor.defaultFormatter": "ibecker.treefmt-vscode",
"direnv.restart.automatic": true,
"[nix]": {
"editor.defaultFormatter": "jnoortheen.nix-ide",
"editor.formatOnSave": true
},
"nix.enableLanguageServer": true,
"nix.serverPath": "nil",
"nix.serverSettings": {
// settings for 'nil' LSP
"nil": {
"formatting": {
"command": ["treefmt-nix", "--stdin", "neverexists.nix"]
}
}
}
}

3062
templates/default/Cargo.lock generated Normal file

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,28 @@
[workspace]
resolver = "2"
package.version = "0.1.0"
metadata.crane.name = "blueprint-universe"
members = [
"rust/hpos-hal",
"rust/clients/host_agent",
"rust/services/workload",
"rust/util_libs",
]
[workspace.dependencies]
async-nats = { version = "0.38.0", features = ["service"] }
tokio = { version = "1", features = ["full"] }
futures = "0.3.31"
anyhow = "1.0"
serde = "1.0.215"
serde_json = "1.0.133"
dotenv = "0.15.0"
env_logger = "0.11.0"
log = "0.4.17"
[profile.dev]
opt-level = "z"
[profile.release]
opt-level = "z"

View file

@ -0,0 +1,25 @@
# rust workspace template
This is an experiment to contain the code for all components in a single repository, also known as a monorepository.
## Repository Layout
The code is grouped by language or framework name.
### Nix
```
/flake.nix
/flake.lock
/nix/ /* [blueprint](https://github.com/numtide/blueprint) set up underneath here. */
```
### Rust
```
/Cargo.toml
/Cargo.lock
/rust/ # all rust code lives here
/rust/common/Cargo.toml
/rust/common/src/lib.rs
```

335
templates/default/flake.lock generated Normal file
View file

@ -0,0 +1,335 @@
{
"nodes": {
"blueprint": {
"inputs": {
"nixpkgs": [
"nixpkgs"
],
"systems": "systems"
},
"locked": {
"lastModified": 1733562445,
"narHash": "sha256-gLmqbX40Qos+EeBvmlzvntWB3NrdiDaFxhr3VAmhrf4=",
"owner": "numtide",
"repo": "blueprint",
"rev": "97ef7fba3a6eec13e12a108ce4b3473602eb424f",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "blueprint",
"type": "github"
}
},
"crane": {
"locked": {
"lastModified": 1734808813,
"narHash": "sha256-3aH/0Y6ajIlfy7j52FGZ+s4icVX0oHhqBzRdlOeztqg=",
"owner": "ipetkov",
"repo": "crane",
"rev": "72e2d02dbac80c8c86bf6bf3e785536acf8ee926",
"type": "github"
},
"original": {
"owner": "ipetkov",
"repo": "crane",
"type": "github"
}
},
"flake-utils": {
"locked": {
"lastModified": 1653893745,
"narHash": "sha256-0jntwV3Z8//YwuOjzhV2sgJJPt+HY6KhU7VZUL0fKZQ=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "1ed9fb1935d260de5fe1c2f7ee0ebaae17ed2fa1",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"flake-utils_2": {
"locked": {
"lastModified": 1653893745,
"narHash": "sha256-0jntwV3Z8//YwuOjzhV2sgJJPt+HY6KhU7VZUL0fKZQ=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "1ed9fb1935d260de5fe1c2f7ee0ebaae17ed2fa1",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"flake-utils_3": {
"locked": {
"lastModified": 1653893745,
"narHash": "sha256-0jntwV3Z8//YwuOjzhV2sgJJPt+HY6KhU7VZUL0fKZQ=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "1ed9fb1935d260de5fe1c2f7ee0ebaae17ed2fa1",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"flake-utils_4": {
"locked": {
"lastModified": 1653893745,
"narHash": "sha256-0jntwV3Z8//YwuOjzhV2sgJJPt+HY6KhU7VZUL0fKZQ=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "1ed9fb1935d260de5fe1c2f7ee0ebaae17ed2fa1",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"flake-utils_5": {
"locked": {
"lastModified": 1653893745,
"narHash": "sha256-0jntwV3Z8//YwuOjzhV2sgJJPt+HY6KhU7VZUL0fKZQ=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "1ed9fb1935d260de5fe1c2f7ee0ebaae17ed2fa1",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"nixago": {
"inputs": {
"flake-utils": "flake-utils",
"nixago-exts": "nixago-exts",
"nixpkgs": [
"nixpkgs"
]
},
"locked": {
"lastModified": 1714086354,
"narHash": "sha256-yKVQMxL9p7zCWUhnGhDzRVT8sDgHoI3V595lBK0C2YA=",
"owner": "jmgilman",
"repo": "nixago",
"rev": "5133633e9fe6b144c8e00e3b212cdbd5a173b63d",
"type": "github"
},
"original": {
"owner": "jmgilman",
"repo": "nixago",
"type": "github"
}
},
"nixago-exts": {
"inputs": {
"flake-utils": "flake-utils_2",
"nixago": "nixago_2",
"nixpkgs": [
"nixago",
"nixpkgs"
]
},
"locked": {
"lastModified": 1676070308,
"narHash": "sha256-QaJ65oc2l8iwQIGWUJ0EKjCeSuuCM/LqR8RauxZUUkc=",
"owner": "nix-community",
"repo": "nixago-extensions",
"rev": "e5380cb0456f4ea3c86cf94e3039eb856bf07d0b",
"type": "github"
},
"original": {
"owner": "nix-community",
"repo": "nixago-extensions",
"type": "github"
}
},
"nixago-exts_2": {
"inputs": {
"flake-utils": "flake-utils_4",
"nixago": "nixago_3",
"nixpkgs": [
"nixago",
"nixago-exts",
"nixago",
"nixpkgs"
]
},
"locked": {
"lastModified": 1655508669,
"narHash": "sha256-BDDdo5dZQMmwNH/GNacy33nPBnCpSIydWFPZs0kkj/g=",
"owner": "nix-community",
"repo": "nixago-extensions",
"rev": "3022a932ce109258482ecc6568c163e8d0b426aa",
"type": "github"
},
"original": {
"owner": "nix-community",
"repo": "nixago-extensions",
"type": "github"
}
},
"nixago_2": {
"inputs": {
"flake-utils": "flake-utils_3",
"nixago-exts": "nixago-exts_2",
"nixpkgs": [
"nixago",
"nixago-exts",
"nixpkgs"
]
},
"locked": {
"lastModified": 1676070010,
"narHash": "sha256-iYzJIWptE1EUD8VINAg66AAMUajizg8JUYN3oBmb8no=",
"owner": "nix-community",
"repo": "nixago",
"rev": "d480ba6c0c16e2c5c0bd2122852d6a0c9ad1ed0e",
"type": "github"
},
"original": {
"owner": "nix-community",
"ref": "rename-config-data",
"repo": "nixago",
"type": "github"
}
},
"nixago_3": {
"inputs": {
"flake-utils": "flake-utils_5",
"nixpkgs": [
"nixago",
"nixago-exts",
"nixago",
"nixago-exts",
"nixpkgs"
]
},
"locked": {
"lastModified": 1655405483,
"narHash": "sha256-Crd49aZWNrpczlRTOwWGfwBMsTUoG9vlHDKQC7cx264=",
"owner": "nix-community",
"repo": "nixago",
"rev": "e6a9566c18063db5b120e69e048d3627414e327d",
"type": "github"
},
"original": {
"owner": "nix-community",
"repo": "nixago",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1734875076,
"narHash": "sha256-Pzyb+YNG5u3zP79zoi8HXYMs15Q5dfjDgwCdUI5B0nY=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "1807c2b91223227ad5599d7067a61665c52d1295",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixos-24.11",
"repo": "nixpkgs",
"type": "github"
}
},
"nixpkgs-unstable": {
"locked": {
"lastModified": 1734649271,
"narHash": "sha256-4EVBRhOjMDuGtMaofAIqzJbg4Ql7Ai0PSeuVZTHjyKQ=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "d70bd19e0a38ad4790d3913bf08fcbfc9eeca507",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixos-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"blueprint": "blueprint",
"crane": "crane",
"nixago": "nixago",
"nixpkgs": "nixpkgs",
"nixpkgs-unstable": "nixpkgs-unstable",
"rust-overlay": "rust-overlay",
"treefmt-nix": "treefmt-nix"
}
},
"rust-overlay": {
"inputs": {
"nixpkgs": [
"nixpkgs"
]
},
"locked": {
"lastModified": 1734834660,
"narHash": "sha256-bm8V+Cu8rWJA+vKQnc94mXTpSDgvedyoDKxTVi/uJfw=",
"owner": "oxalica",
"repo": "rust-overlay",
"rev": "b070e6030118680977bc2388868c4b3963872134",
"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"
}
},
"treefmt-nix": {
"inputs": {
"nixpkgs": [
"nixpkgs"
]
},
"locked": {
"lastModified": 1734704479,
"narHash": "sha256-MMi74+WckoyEWBRcg/oaGRvXC9BVVxDZNRMpL+72wBI=",
"owner": "numtide",
"repo": "treefmt-nix",
"rev": "65712f5af67234dad91a5a4baee986a8b62dbf8f",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "treefmt-nix",
"type": "github"
}
}
},
"root": "root",
"version": 7
}

View file

@ -0,0 +1,30 @@
{
description = "blueprint-universe";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs?ref=nixos-24.11";
nixpkgs-unstable.url = "github:NixOS/nixpkgs?ref=nixos-unstable";
blueprint.url = "github:numtide/blueprint";
blueprint.inputs.nixpkgs.follows = "nixpkgs";
treefmt-nix.url = "github:numtide/treefmt-nix";
treefmt-nix.inputs.nixpkgs.follows = "nixpkgs";
nixago.url = "github:jmgilman/nixago";
nixago.inputs.nixpkgs.follows = "nixpkgs";
crane.url = "github:ipetkov/crane";
rust-overlay = {
url = "github:oxalica/rust-overlay";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs =
inputs:
inputs.blueprint {
inherit inputs;
prefix = "nix/";
# change this if unfree software is required.
nixpkgs.config.allowUnfree = false;
};
}

View file

@ -0,0 +1,27 @@
{
pkgs,
flake,
system,
}:
pkgs.mkShell {
# Add build dependencies
packages = [
flake.formatter.${system}
pkgs.jq
];
# Add environment variables
env = { };
# Load custom bash code
shellHook =
# TODO(blocked/upstream): remove this once https://github.com/isbecker/treefmt-vscode/issues/3 is resolved
(flake.inputs.nixago.lib.${system}.make {
data = flake.formatter.${system}.settings;
output = "treefmt.toml";
format = "toml";
}).shellHook
+ ''
echo $(git rev-parse --show-toplevel)
'';
}

View file

@ -0,0 +1,34 @@
{
flake,
system,
pkgs,
...
}:
let
craneLib = flake.lib.mkCraneLib { inherit pkgs system; };
in
craneLib.devShell {
inputsFrom =
[
flake.devShells.${system}.default
]
# Inherit inputs from rust-workspace on the platforms it's available.
++ (pkgs.lib.lists.optionals
(pkgs.lib.meta.availableOn pkgs.stdenv.hostPlatform flake.packages.${system}.rust-workspace)
(
[
flake.packages.${system}.rust-workspace
]
++ (builtins.attrValues flake.packages.${system}.rust-workspace.passthru.tests)
)
);
# Additional dev-shell environment variables can be set directly
# MY_CUSTOM_DEVELOPMENT_VAR = "something else";
# Extra inputs can be added here; cargo and rustc are provided by default.
packages = [
pkgs.natscli
];
}

View file

@ -0,0 +1,70 @@
{
pkgs,
inputs,
perSystem,
...
}:
let
settingsNix = {
package = perSystem.nixpkgs.treefmt2;
projectRootFile = ".git/config";
programs = {
nixfmt.enable = true;
deadnix = {
enable = true;
no-underscore = true;
};
statix.enable = true;
rustfmt.enable = true;
gofmt.enable = true;
shfmt.enable = true;
prettier.enable = true;
} // pkgs.lib.optionalAttrs (pkgs.system != "riscv64-linux") { shellcheck.enable = true; };
settings = {
global.excludes = [
"LICENSE"
# unsupported extensions
"*.{gif,png,svg,tape,mts,lock,mod,sum,toml,env,envrc,gitignore}"
];
formatter = {
deadnix = {
priority = 1;
};
nixfmt = {
priority = 2;
};
statix = {
priority = 3;
};
prettier = {
options = [
"--tab-width"
"2"
];
includes = [ "*.{css,html,js,json,jsx,md,mdx,scss,ts,yaml}" ];
};
};
};
};
treefmtEval = inputs.treefmt-nix.lib.evalModule pkgs settingsNix;
in
treefmtEval.config.build.wrapper.overrideAttrs (_: {
passthru = {
inherit (treefmtEval.config) package settings;
inherit (treefmtEval) config;
inherit settingsNix;
};
})

View file

@ -0,0 +1,13 @@
{ inputs, flake, ... }:
{
mkCraneLib =
{ pkgs, system }:
let
craneLib = inputs.crane.mkLib pkgs;
toolchain = (inputs.rust-overlay.lib.mkRustBin { } pkgs).fromRustupToolchainFile (
flake + "/rust-toolchain.toml"
);
in
craneLib.overrideToolchain toolchain;
}

View file

@ -0,0 +1,83 @@
/*
This exposes all crates in the workspace as a single package attribute.
It also enforces various tests.
Losely following the tutorial at https://crane.dev/examples/quick-start-workspace.html
*/
{
flake,
pkgs,
system,
...
}:
let
craneLib = flake.lib.mkCraneLib { inherit pkgs system; };
src = craneLib.cleanCargoSource flake;
commonArgs = {
inherit src;
strictDeps = true;
buildInputs = pkgs.lib.optionals pkgs.stdenv.isDarwin [
# Additional darwin specific inputs can be set here
pkgs.libiconv
];
# Additional environment variables can be set directly
# MY_CUSTOM_VAR = "some value";
meta.platforms = pkgs.lib.platforms.linux;
};
# Build *just* the cargo dependencies (of the entire workspace),
# so we can reuse all of that work (e.g. via cachix) when running in CI
# It is *highly* recommended to use something like cargo-hakari to avoid
# cache misses when building individual top-level-crates
cargoArtifacts = craneLib.buildDepsOnly commonArgs;
in
craneLib.cargoBuild (
commonArgs
// {
inherit cargoArtifacts;
# NB: we disable tests since we'll run them all via cargo-nextest
doCheck = false;
passthru.tests = {
clippy = craneLib.cargoClippy (
commonArgs
// {
inherit cargoArtifacts;
cargoClippyExtraArgs = "--all-targets -- --deny warnings";
}
);
doc = craneLib.cargoDoc (
commonArgs
// {
inherit cargoArtifacts;
}
);
# Audit licenses
deny = craneLib.cargoDeny {
inherit src;
};
nextest = craneLib.cargoNextest (
commonArgs
// {
inherit cargoArtifacts;
nativeBuildInputs = [
# native test binaries go here
];
partitions = 1;
partitionType = "count";
}
);
};
}
)

View file

@ -0,0 +1,5 @@
[toolchain]
channel = "1.83.0"
components = [ "cargo","llvm-tools", "rustc", "clippy", "rust-src" ]
targets = [ ]
profile = "minimal"

View file

@ -0,0 +1 @@
/nix/store/2q0p32grc9y40gilz6z9ck5nmq5ypx4n-treefmt.toml