{
  description = "Development Nix flake for the kompress (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;
          };
          kompress = rustPlatform.buildRustPackage {
            pname = "kompress_eshop";
            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" "kompress-eshop-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
        {
          kompress = kompress;
          default = kompress;
        }
      );

      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
              # OpenSSL for crypto dependencies (loco-oauth2 -> oauth2/reqwest
              # use native-tls); .dev provides headers + pkg-config metadata.
              pkgs.openssl
              pkgs.openssl.dev
              pkgs.cmake
              pkgs.llvmPackages.clang
              pkgs.llvmPackages.libclang.lib
              # loco-rs CLI workflow helpers
              pkgs.sea-orm-cli
              # Logo/vector asset workflow helpers
              pkgs.potrace
            ];
            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++
            '';
          };
        }
      );
    };
}
