From e98aeccbedde9083a4734735ecb49faccddad172 Mon Sep 17 00:00:00 2001 From: Alois Date: Sun, 17 May 2026 13:44:19 +0200 Subject: [PATCH] [Add] nix dev shell --- flake.lock | 28 +++++++++++++++++++++++---- flake.nix | 57 ++++++++++++++++++++++++++++++++++++------------------ 2 files changed, 62 insertions(+), 23 deletions(-) diff --git a/flake.lock b/flake.lock index e742243..fb5bf79 100644 --- a/flake.lock +++ b/flake.lock @@ -20,11 +20,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1778443072, - "narHash": "sha256-zi7/fsqM/kFdNuED//4WOCUtezGtKKqRNORjMvfwjnA=", + "lastModified": 1778869304, + "narHash": "sha256-30sZNZoA1cqF5JNO9fVX+wgiQYjB7HJqqJ4ztCDeBZE=", "owner": "nixos", "repo": "nixpkgs", - "rev": "da5ad661ba4e5ef59ba743f0d112cbc30e474f32", + "rev": "d233902339c02a9c334e7e593de68855ad26c4cb", "type": "github" }, "original": { @@ -53,15 +53,35 @@ "inputs": { "flake-parts": "flake-parts", "nixpkgs": "nixpkgs", + "rust-overlay": "rust-overlay", "ttp": "ttp" } }, + "rust-overlay": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1778987862, + "narHash": "sha256-V3qGt9P1eJP/r/1ONablphfGiH0RP4agQhrRANpDYx8=", + "owner": "oxalica", + "repo": "rust-overlay", + "rev": "6f44d8874ac29806c8d5cae42bf8e19ebb5ce0d3", + "type": "github" + }, + "original": { + "owner": "oxalica", + "repo": "rust-overlay", + "type": "github" + } + }, "ttp": { "flake": false, "locked": { "lastModified": 1778948017, "narHash": "sha256-hqBYSZnPq7f/F2Z6nJK+6a8ITk6WRCcVBcNT0CR6SnM=", - "ref": "refs/heads/main", "rev": "7e5d1953df8592a1feba0f390d205d0ef61a3119", "revCount": 117, "type": "git", diff --git a/flake.nix b/flake.nix index 29f2373..97b1bcc 100644 --- a/flake.nix +++ b/flake.nix @@ -4,13 +4,17 @@ inputs = { nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable"; flake-parts.url = "github:hercules-ci/flake-parts"; + rust-overlay = { + url = "github:oxalica/rust-overlay"; + inputs.nixpkgs.follows = "nixpkgs"; + }; ttp = { url = "git+https://git.methanium.net/Tensamin/TTP.git?rev=7e5d1953df8592a1feba0f390d205d0ef61a3119"; flake = false; }; }; - outputs = inputs@{ self, nixpkgs, flake-parts, ttp, ... }: + outputs = inputs@{ self, nixpkgs, flake-parts, rust-overlay, ttp, ... }: flake-parts.lib.mkFlake { inherit inputs; } { systems = [ "x86_64-linux" @@ -19,28 +23,43 @@ "aarch64-darwin" ]; - perSystem = { self', pkgs, ... }: { - packages = { - default = self'.packages.omega; - omega = pkgs.rustPlatform.buildRustPackage { - pname = "omega"; - version = "0.1.0"; - src = ./.; - cargoLock = { - lockFile = ./Cargo.lock; - allowBuiltinFetchGit = true; + perSystem = { self', pkgs, system, ... }: + let + rustPkgs = import nixpkgs { + inherit system; + overlays = [ (import rust-overlay) ]; + }; + rustToolchain = rustPkgs.rust-bin.stable.latest.default.override { + extensions = [ "rust-src" "rust-analyzer" "clippy" "rustfmt" ]; + }; + in + { + packages = { + default = self'.packages.omega; + omega = pkgs.rustPlatform.buildRustPackage { + pname = "omega"; + version = "0.1.0"; + src = ./.; + cargoLock = { + lockFile = ./Cargo.lock; + allowBuiltinFetchGit = true; + }; + nativeBuildInputs = with pkgs; [ cmake perl pkg-config ]; + buildInputs = with pkgs; [ openssl libmysqlclient ]; + dontUseCmakeConfigure = true; + preConfigure = '' + if [ -d ../cargo-vendor-dir/ttp-core-0.1.0 ]; then + cp ${ttp}/ttp-codec.json ../cargo-vendor-dir/ttp-codec.json + fi + ''; }; - nativeBuildInputs = with pkgs; [ cmake perl pkg-config ]; + }; + + devShells.default = pkgs.mkShell { + nativeBuildInputs = with pkgs; [ rustToolchain git cmake perl pkg-config ]; buildInputs = with pkgs; [ openssl libmysqlclient ]; - dontUseCmakeConfigure = true; - preConfigure = '' - if [ -d ../cargo-vendor-dir/ttp-core-0.1.0 ]; then - cp ${ttp}/ttp-codec.json ../cargo-vendor-dir/ttp-codec.json - fi - ''; }; }; - }; flake = { nixosModules.default = { config, pkgs, lib, ... }: