diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..a0d2721 --- /dev/null +++ b/flake.lock @@ -0,0 +1,48 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1781074563, + "narHash": "sha256-md8WlXOlfnIeHeOScMTTHFyf2d6iaTwPl2apR5EQ3P4=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "9ae611a455b90cf061d8f332b977e387bda8e1ca", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs", + "rust-overlay": "rust-overlay" + } + }, + "rust-overlay": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1781580018, + "narHash": "sha256-BlTedbM77FmesD2ZqR73vhFy+y77UrhefV7IYw1pDsk=", + "owner": "oxalica", + "repo": "rust-overlay", + "rev": "8bceba21a1ebea535c27c4dc723a0d5a4db9e386", + "type": "github" + }, + "original": { + "owner": "oxalica", + "repo": "rust-overlay", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..dd420d3 --- /dev/null +++ b/flake.nix @@ -0,0 +1,107 @@ +{ + description = "Development Nix flake for the gitara_web (kompress_eshop) loco-rs app"; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + rust-overlay = { + url = "github:oxalica/rust-overlay"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + }; + + outputs = { self, nixpkgs, rust-overlay, ... }: + let + systems = [ + "x86_64-linux" + "aarch64-linux" + "x86_64-darwin" + "aarch64-darwin" + ]; + forAllSystems = f: nixpkgs.lib.genAttrs systems f; + + # Read the version from the root Cargo.toml (single source of truth). + cargoToml = builtins.fromTOML (builtins.readFile ./Cargo.toml); + cargoVersion = cargoToml.package.version; + + # On a release commit Cargo.toml carries the real version. Otherwise fall + # back to a dev version derived from the flake source revision. + version = + if cargoVersion != "0.0.0" + then cargoVersion + else "0.0.0-dev+${self.shortRev or "dirty"}"; + in + { + packages = forAllSystems (system: + let + pkgs = import nixpkgs { + inherit system; + overlays = [ rust-overlay.overlays.default ]; + }; + rustPlatform = pkgs.makeRustPlatform { + cargo = pkgs.rust-bin.stable.latest.minimal; + rustc = pkgs.rust-bin.stable.latest.minimal; + }; + gitara-web = rustPlatform.buildRustPackage { + pname = "gitara_web"; + inherit version; + src = ./.; + cargoLock.lockFile = ./Cargo.lock; + + nativeBuildInputs = [ + pkgs.pkg-config + pkgs.cmake + pkgs.llvmPackages.clang + ]; + buildInputs = [ + pkgs.openssl + ]; + + # Build only the application binary. + cargoBuildFlags = [ "--bin" "gitara_web-cli" ]; + # Tests need a database/runtime environment; skip during the build. + doCheck = false; + + PKG_CONFIG_PATH = "${pkgs.openssl.dev}/lib/pkgconfig"; + LIBCLANG_PATH = "${pkgs.llvmPackages.libclang.lib}/lib"; + }; + in + { + gitara-web = gitara-web; + default = gitara-web; + } + ); + + devShells = forAllSystems (system: + let + pkgs = import nixpkgs { + inherit system; + overlays = [ rust-overlay.overlays.default ]; + }; + rust = pkgs.rust-bin.stable.latest.default.override { + extensions = [ "rust-src" "rust-analyzer" ]; + }; + in + { + default = pkgs.mkShell { + buildInputs = [ + rust + pkgs.pkg-config + pkgs.openssl + pkgs.cmake + pkgs.llvmPackages.clang + pkgs.llvmPackages.libclang.lib + # loco-rs CLI workflow helpers + pkgs.sea-orm-cli + ]; + PKG_CONFIG_PATH = "${pkgs.openssl.dev}/lib/pkgconfig"; + LIBCLANG_PATH = "${pkgs.llvmPackages.libclang.lib}/lib"; + # Use clang for native C deps (avoids GCC 15 warnings-as-errors) + shellHook = '' + export CC=clang + export CXX=clang++ + ''; + }; + } + ); + }; +}