diff options
| author | Linnea Gräf <nea@nea.moe> | 2025-08-13 00:18:14 +0200 |
|---|---|---|
| committer | Linnea Gräf <nea@nea.moe> | 2025-08-13 00:18:14 +0200 |
| commit | 1eb8f8986f5784e59a1d9b87e3f82c80caa646ab (patch) | |
| tree | decefbcb9344dbd16f16eb29ff46ec3f23d367e4 | |
| parent | bb1c7ceeddf665e74ac26c0b7145190dba57c59f (diff) | |
| download | nix-infra-master.tar.gz nix-infra-master.tar.bz2 nix-infra-master.zip | |
| -rw-r--r-- | templates/default.nix | 15 | ||||
| -rw-r--r-- | templates/rust/.editorconfig | 12 | ||||
| -rw-r--r-- | templates/rust/.envrc | 3 | ||||
| -rw-r--r-- | templates/rust/.github/workflows/build.yml | 19 | ||||
| -rw-r--r-- | templates/rust/.github/workflows/publish.yml | 46 | ||||
| -rw-r--r-- | templates/rust/.gitignore | 3 | ||||
| -rw-r--r-- | templates/rust/Cargo.toml | 28 | ||||
| -rw-r--r-- | templates/rust/Dockerfile | 22 | ||||
| -rw-r--r-- | templates/rust/flake.nix | 61 | ||||
| -rw-r--r-- | templates/rust/rust-toolchain.toml | 3 | ||||
| -rw-r--r-- | templates/rust/rustfmt.toml | 1 |
11 files changed, 213 insertions, 0 deletions
diff --git a/templates/default.nix b/templates/default.nix index 11f3e86..496babe 100644 --- a/templates/default.nix +++ b/templates/default.nix @@ -1,4 +1,19 @@ { + rust = { + path = ./rust; + description = "Rust tempalte with .envrc and chef"; + welcomeText = '' + # Rust Template initialized + + Remember to replace the package name in + - flake.nix + - .github/workflows/publish.yml + + Also remember to update the toolchain you want in + - rust-toolchain.toml + - Dockerfile + ''; + }; basic = { path = ./basic; description = "Basic flake with flake-parts + .envrc"; diff --git a/templates/rust/.editorconfig b/templates/rust/.editorconfig new file mode 100644 index 0000000..0cd2f7e --- /dev/null +++ b/templates/rust/.editorconfig @@ -0,0 +1,12 @@ +root = true + +[*] +end_of_line = lf +insert_final_newline = true +charset = utf-8 +indent_style = tab +trim_trailing_whitespace = true + +[*.{yaml,yml}] +indent_size = 4 +indent_style = space diff --git a/templates/rust/.envrc b/templates/rust/.envrc new file mode 100644 index 0000000..c80ee3b --- /dev/null +++ b/templates/rust/.envrc @@ -0,0 +1,3 @@ +#!/usr/bin/env bash +watch_file -- flake-modules/*.nix +use flake . --show-trace diff --git a/templates/rust/.github/workflows/build.yml b/templates/rust/.github/workflows/build.yml new file mode 100644 index 0000000..86447dc --- /dev/null +++ b/templates/rust/.github/workflows/build.yml @@ -0,0 +1,19 @@ +name: Rust + +on: + push: + pull_request: + +env: + CARGO_TERM_COLOR: always + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + - name: Build + run: cargo build --verbose + - name: Run tests + run: cargo test --verbose diff --git a/templates/rust/.github/workflows/publish.yml b/templates/rust/.github/workflows/publish.yml new file mode 100644 index 0000000..1e81bb6 --- /dev/null +++ b/templates/rust/.github/workflows/publish.yml @@ -0,0 +1,46 @@ +name: Publish Docker Image + +on: + push: + branches: + - master + tags: + - "*" + workflow_dispatch: + +env: + REGISTRY: ghcr.io + IMAGE: my-orgname/my-packagename + +permissions: + contents: read + packages: write + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: docker/metadata-action@v5 + id: meta + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE }} + tags: | + type=ref,event=branch + type=semver,pattern={{version}} + type=semver,pattern={{major}}.{{minor}} + type=semver,pattern={{major}} + type=sha + - uses: docker/login-action@v3 + with: + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + registry: ${{ env.REGISTRY }} + + - uses: docker/setup-buildx-action@v3 + - uses: docker/build-push-action@v6 + with: + context: . + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} diff --git a/templates/rust/.gitignore b/templates/rust/.gitignore new file mode 100644 index 0000000..f568402 --- /dev/null +++ b/templates/rust/.gitignore @@ -0,0 +1,3 @@ +/target +.env +tags diff --git a/templates/rust/Cargo.toml b/templates/rust/Cargo.toml new file mode 100644 index 0000000..3527b73 --- /dev/null +++ b/templates/rust/Cargo.toml @@ -0,0 +1,28 @@ +[package] +name = "helios" +version = "0.1.0" +edition = "2024" + +[dependencies] +cached-path = "0.8.1" +chrono = "0.4.41" +chrono-tz = "0.10.4" +cow_hashmap = "0.1.13" +csv = "1.3.1" +dotenv = "0.15.0" +eyre = "0.6.12" +inventory = "0.3.20" +positioned-io = "0.3.4" +rc-zip-tokio = "4.2.6" +serde_json = "1.0.140" +tokio = { version = "1.45.1", features = ["fs", "macros", "rt-multi-thread"] } +tokio-scoped = "0.2.0" +tracing = "0.1.41" +tracing-subscriber = { version = "0.3.19", features = ["env-filter"] } + +twilight-cache-inmemory = "0.16.0" +twilight-gateway = "0.16.0" +twilight-http = "0.16.0" +twilight-model = "0.16.0" +unicase = "2.8.1" +urlencoding = "2.1.3" diff --git a/templates/rust/Dockerfile b/templates/rust/Dockerfile new file mode 100644 index 0000000..c1d3144 --- /dev/null +++ b/templates/rust/Dockerfile @@ -0,0 +1,22 @@ +FROM clux/muslrust:nightly-2025-04-18 AS chef +USER root +RUN cargo install cargo-chef +WORKDIR /app + +FROM chef AS planner +COPY . . +RUN rm rust-toolchain.toml +RUN cargo chef prepare --recipe-path recipe.json + +FROM chef AS builder +COPY --from=planner /app/recipe.json recipe.json +# Notice that we are specifying the --target flag! +RUN cargo chef cook --release --target x86_64-unknown-linux-musl --recipe-path recipe.json +COPY . . +RUN rm rust-toolchain.toml +RUN cargo build --release --target x86_64-unknown-linux-musl --bin helios + +FROM docker.io/alpine:3 AS runtime +WORKDIR /app +COPY --from=builder /app/target/x86_64-unknown-linux-musl/release/helios /usr/local/bin/ +CMD ["/usr/local/bin/helios"] diff --git a/templates/rust/flake.nix b/templates/rust/flake.nix new file mode 100644 index 0000000..be1a8df --- /dev/null +++ b/templates/rust/flake.nix @@ -0,0 +1,61 @@ +{ + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + rust-overlay.url = "github:oxalica/rust-overlay"; + flake-utils.url = "github:numtide/flake-utils"; + }; + + outputs = + { + self, + nixpkgs, + rust-overlay, + flake-utils, + ... + }: + flake-utils.lib.eachDefaultSystem ( + system: + let + overlays = [ (import rust-overlay) ]; + pkgs = import nixpkgs { inherit system overlays; }; + rustToolchain = pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml; + rustPlatform = pkgs.makeRustPlatform { + cargo = rustToolchain; + rustc = rustToolchain; + }; + rustWithSrc = rustToolchain.override { + extensions = [ + "rust-analyzer" + "rust-src" + ]; + }; + deps = [ pkgs.openssl.dev ]; + in + with pkgs; + { + defaultPackage = rustPlatform.buildRustPackage { + name = "introvert"; + src = ./.; + cargoLock = { + lockFileContents = builtins.readFile ./Cargo.lock; + }; + buildInputs = deps; + nativeBuildInputs = [ pkgs.pkg-config ]; + }; + devShells.default = mkShell { + buildInputs = [ + rustWithSrc + sccache + cargo-make + lldb + ] + ++ deps; + nativeBuildInputs = [ pkg-config ]; + shellHook = '' + export RUSTC_WRAPPER="${sccache}/bin/sccache" + ''; + }; + formatter = alejandra; + } + ); +} diff --git a/templates/rust/rust-toolchain.toml b/templates/rust/rust-toolchain.toml new file mode 100644 index 0000000..88c7d50 --- /dev/null +++ b/templates/rust/rust-toolchain.toml @@ -0,0 +1,3 @@ +[toolchain] +# Make sure this is always synced with Dockerfile +channel = "nightly-2025-04-18" diff --git a/templates/rust/rustfmt.toml b/templates/rust/rustfmt.toml new file mode 100644 index 0000000..218e203 --- /dev/null +++ b/templates/rust/rustfmt.toml @@ -0,0 +1 @@ +hard_tabs = true |
