From 05e5d9410a3a803c770eb2be5e02f03901d915ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Moritz=20B=C3=B6hme?= Date: Sun, 23 Feb 2025 15:36:51 +0100 Subject: [PATCH] feat: init --- .envrc | 1 + .gitignore | 21 ++++++++++ flake.lock | 115 +++++++++++++++++++++++++++++++++++++++++++++++++++++ flake.nix | 58 +++++++++++++++++++++++++++ 4 files changed, 195 insertions(+) create mode 100644 .envrc create mode 100644 .gitignore create mode 100644 flake.lock create mode 100644 flake.nix 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..61a76d0 --- /dev/null +++ b/.gitignore @@ -0,0 +1,21 @@ +### direnv ### +.direnv + +### Rust ### +# Generated by Cargo +# will have compiled files and executables +debug/ +target/ + +# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries +# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html +Cargo.lock + +# These are backup files generated by rustfmt +**/*.rs.bk + +# MSVC Windows builds of rustc generate these, which store debugging information +*.pdb + +# Added by cargo +/target diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..3460792 --- /dev/null +++ b/flake.lock @@ -0,0 +1,115 @@ +{ + "nodes": { + "crane": { + "locked": { + "lastModified": 1736101677, + "narHash": "sha256-iKOPq86AOWCohuzxwFy/MtC8PcSVGnrxBOvxpjpzrAY=", + "owner": "ipetkov", + "repo": "crane", + "rev": "61ba163d85e5adeddc7b3a69bb174034965965b2", + "type": "github" + }, + "original": { + "owner": "ipetkov", + "repo": "crane", + "type": "github" + } + }, + "fenix": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ], + "rust-analyzer-src": "rust-analyzer-src" + }, + "locked": { + "lastModified": 1736318091, + "narHash": "sha256-RkRHXZaMgOMGgkW2YmEqxxDDYRiGFbfr1JuaI0VrCKo=", + "owner": "nix-community", + "repo": "fenix", + "rev": "9e13860d50cbfd42e79101a516e1939c7723f093", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "fenix", + "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": 1736344531, + "narHash": "sha256-8YVQ9ZbSfuUk2bUf2KRj60NRraLPKPS0Q4QFTbc+c2c=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "bffc22eb12172e6db3c5dde9e3e5628f8e3e7912", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "ref": "nixos-unstable", + "type": "indirect" + } + }, + "root": { + "inputs": { + "crane": "crane", + "fenix": "fenix", + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs" + } + }, + "rust-analyzer-src": { + "flake": false, + "locked": { + "lastModified": 1736266405, + "narHash": "sha256-V2FDSb8YjuquZduBRNp5niWYlWurja2yGN6Xzh5GPYk=", + "owner": "rust-lang", + "repo": "rust-analyzer", + "rev": "91fc0a239af4e56b84b1d3974ac0f34dcc99b895", + "type": "github" + }, + "original": { + "owner": "rust-lang", + "ref": "nightly", + "repo": "rust-analyzer", + "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" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..a54d6b0 --- /dev/null +++ b/flake.nix @@ -0,0 +1,58 @@ +{ + inputs = { + crane.url = "github:ipetkov/crane"; + fenix.url = "github:nix-community/fenix"; + fenix.inputs.nixpkgs.follows = "nixpkgs"; + flake-utils.url = "github:numtide/flake-utils"; + nixpkgs.url = "nixpkgs/nixos-unstable"; + }; + + outputs = { self, crane, flake-utils, nixpkgs, ... }@inputs: + flake-utils.lib.eachDefaultSystem (system: + let + inherit (pkgs) lib; + pkgs = import nixpkgs { inherit system; }; + fenix = inputs.fenix.packages.${system}; + craneLib = crane.lib.${system}.overrideToolchain toolchain.toolchain; + mkSrc = extraPaths: with lib.fileset; let + root = ./.; + rustFiles = fromSource (craneLib.cleanCargoSource root); + fileset = union rustFiles (unions extraPaths); + in + toSource { inherit root fileset; }; + + ## Customize here ## + toolchain = fenix.stable; # or fenix.complete; + stdenv = pkgs.stdenvAdapters.useMoldLinker pkgs.stdenv; + in + { + packages.default = craneLib.buildPackage { + inherit stdenv; + src = mkSrc [ ]; + 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"; + }; + + devShells.default = pkgs.mkShell.override { inherit stdenv; } + { + nativeBuildInputs = with pkgs; [ + # Add additional build inputs here + ] ++ (with toolchain; [ + cargo + clippy + rustfmt + rustc + fenix.rust-analyzer + ]); + RUST_SRC_PATH = "${toolchain.rust-src}/lib/rustlib/src/rust/library"; + }; + } + ); +}