commit e6ba5306cddc2e0bf000f108cbb86cc4ef351631 Author: Doloro1978 Date: Tue Mar 24 17:33:09 2026 +0000 init (with flake) diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..3550a30 --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +use flake diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6abfe1b --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/target +/.direnv diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..ce72e5b --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,7 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "bot" +version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..beb4a42 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,9 @@ +[workspace] +resolver = "3" +members = ["./crates/bot"] + +[workspace.package] +version = "0.1.0" + +[workspace.metadata.crane] +name = "discord-server-telemetry" diff --git a/crates/bot/Cargo.toml b/crates/bot/Cargo.toml new file mode 100644 index 0000000..3e67d04 --- /dev/null +++ b/crates/bot/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "bot" +version = "0.1.0" +edition = "2024" + +[dependencies] diff --git a/crates/bot/src/main.rs b/crates/bot/src/main.rs new file mode 100644 index 0000000..e7a11a9 --- /dev/null +++ b/crates/bot/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..d3ca0b1 --- /dev/null +++ b/flake.lock @@ -0,0 +1,94 @@ +{ + "nodes": { + "advisory-db": { + "flake": false, + "locked": { + "lastModified": 1774340549, + "narHash": "sha256-aiZvFdq0q6f4107oRjOvFOPiJFNLWAM1UrTuU35iL6Q=", + "owner": "rustsec", + "repo": "advisory-db", + "rev": "b1c90cfd1044fe70a5711bc03f2139bb2304b8de", + "type": "github" + }, + "original": { + "owner": "rustsec", + "repo": "advisory-db", + "type": "github" + } + }, + "crane": { + "locked": { + "lastModified": 1774313767, + "narHash": "sha256-hy0XTQND6avzGEUFrJtYBBpFa/POiiaGBr2vpU6Y9tY=", + "owner": "ipetkov", + "repo": "crane", + "rev": "3d9df76e29656c679c744968b17fbaf28f0e923d", + "type": "github" + }, + "original": { + "owner": "ipetkov", + "repo": "crane", + "type": "github" + } + }, + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1731533236, + "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1774273680, + "narHash": "sha256-a++tZ1RQsDb1I0NHrFwdGuRlR5TORvCEUksM459wKUA=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "fdc7b8f7b30fdbedec91b71ed82f36e1637483ed", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "advisory-db": "advisory-db", + "crane": "crane", + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs" + } + }, + "systems": { + "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..0dd2b78 --- /dev/null +++ b/flake.nix @@ -0,0 +1,201 @@ +{ + description = "Discord"; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; + + crane.url = "github:ipetkov/crane"; + + flake-utils.url = "github:numtide/flake-utils"; + + advisory-db = { + url = "github:rustsec/advisory-db"; + flake = false; + }; + }; + + outputs = + { + self, + nixpkgs, + crane, + flake-utils, + advisory-db, + ... + }: + flake-utils.lib.eachDefaultSystem ( + system: + let + pkgs = nixpkgs.legacyPackages.${system}; + + inherit (pkgs) lib; + + craneLib = crane.mkLib pkgs; + src = craneLib.cleanCargoSource ./.; + + # Common arguments can be set here to avoid repeating them later + commonArgs = { + inherit src; + strictDeps = true; + + buildInputs = [ + # Add additional build inputs here + ] + ++ 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"; + }; + + # 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; + + individualCrateArgs = commonArgs // { + inherit cargoArtifacts; + inherit (craneLib.crateNameFromCargoToml { inherit src; }) version; + # NB: we disable tests since we'll run them all via cargo-nextest + doCheck = false; + }; + + fileSetForCrate = + crate: + lib.fileset.toSource { + root = ./.; + fileset = lib.fileset.unions [ + ./Cargo.toml + ./Cargo.lock + (craneLib.fileset.commonCargoSources ./crates/bot) + (craneLib.fileset.commonCargoSources crate) + ]; + }; + + # Build the top-level crates of the workspace as individual derivations. + # This allows consumers to only depend on (and build) only what they need. + # Though it is possible to build the entire workspace as a single derivation, + # so this is left up to you on how to organize things + # + # Note that the cargo workspace must define `workspace.members` using wildcards, + # otherwise, omitting a crate (like we do below) will result in errors since + # cargo won't be able to find the sources for all members. + bot = craneLib.buildPackage ( + individualCrateArgs + // { + pname = "bot"; + cargoExtraArgs = "--bin bot"; + src = fileSetForCrate ./crates/bot; + } + ); + in + { + checks = { + # Build the crates as part of `nix flake check` for convenience + inherit bot; + + # Run clippy (and deny all warnings) on the workspace source, + # again, reusing the dependency artifacts from above. + # + # Note that this is done as a separate derivation so that + # we can block the CI if there are issues here, but not + # prevent downstream consumers from building our crate by itself. + my-workspace-clippy = craneLib.cargoClippy ( + commonArgs + // { + inherit cargoArtifacts; + cargoClippyExtraArgs = "--all-targets -- --deny warnings"; + } + ); + + my-workspace-doc = craneLib.cargoDoc ( + commonArgs + // { + inherit cargoArtifacts; + # This can be commented out or tweaked as necessary, e.g. set to + # `--deny rustdoc::broken-intra-doc-links` to only enforce that lint + env.RUSTDOCFLAGS = "--deny warnings"; + } + ); + + # Check formatting + my-workspace-fmt = craneLib.cargoFmt { + inherit src; + }; + + my-workspace-toml-fmt = craneLib.taploFmt { + src = pkgs.lib.sources.sourceFilesBySuffices src [ ".toml" ]; + # taplo arguments can be further customized below as needed + # taploExtraArgs = "--config ./taplo.toml"; + }; + + # Audit dependencies + my-workspace-audit = craneLib.cargoAudit { + inherit src advisory-db; + }; + + # Audit licenses + my-workspace-deny = craneLib.cargoDeny { + inherit src; + }; + + # Run tests with cargo-nextest + # Consider setting `doCheck = false` on other crate derivations + # if you do not want the tests to run twice + my-workspace-nextest = craneLib.cargoNextest ( + commonArgs + // { + inherit cargoArtifacts; + partitions = 1; + partitionType = "count"; + cargoNextestPartitionsExtraArgs = "--no-tests=pass"; + } + ); + + # Ensure that cargo-hakari is up to date + my-workspace-hakari = craneLib.mkCargoDerivation { + inherit src; + pname = "my-workspace-hakari"; + cargoArtifacts = null; + doInstallCargoArtifacts = false; + + buildPhaseCargoCommand = '' + cargo hakari generate --diff # workspace-hack Cargo.toml is up-to-date + cargo hakari manage-deps --dry-run # all workspace crates depend on workspace-hack + cargo hakari verify + ''; + + nativeBuildInputs = [ + pkgs.cargo-hakari + ]; + }; + }; + + packages = { + inherit bot; + }; + + apps = { + bot = flake-utils.lib.mkApp { + drv = bot; + }; + }; + + devShells.default = craneLib.devShell { + # Inherit inputs from checks. + checks = self.checks.${system}; + + # 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.cargo-hakari + ]; + }; + } + ); +}