iocaine 2.5.1

The deadliest poison known to AI
Documentation
# SPDX-FileCopyrightText: 2025 Gergely Nagy
# SPDX-FileContributor: Gergely Nagy
#
# SPDX-License-Identifier: MIT
{
  description = "The deadliest poison known to AI";

  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-25.05";

    pre-commit-hooks = {
      url = "github:cachix/pre-commit-hooks.nix";
      inputs.nixpkgs.follows = "nixpkgs";
    };
    treefmt-nix = {
      url = "github:numtide/treefmt-nix";
      inputs.nixpkgs.follows = "nixpkgs";
    };
  };

  outputs =
    {
      self,
      nixpkgs,
      systems,
      treefmt-nix,
      ...
    }@inputs:
    let
      inherit (nixpkgs) lib;

      forEachSystem =
        f:
        nixpkgs.lib.genAttrs (import systems) (
          system:
          let
            pkgs = import nixpkgs {
              inherit system;

              overlays = [ self.overlays.default ];
            };
          in
          f pkgs
        );

      treefmtEval = forEachSystem (pkgs: treefmt-nix.lib.evalModule pkgs ./nix/treefmt.nix);
      treefmtWrapper = pkgs: treefmtEval.${pkgs.system}.config.build.wrapper;
    in
    {
      overlays.default = import ./nix/overlay.nix { inherit self lib; };
      formatter = forEachSystem treefmtWrapper;
      checks = forEachSystem (pkgs: {
        formatting = treefmtEval.${pkgs.system}.config.build.check self;
        pre-commit-check = inputs.pre-commit-hooks.lib.${pkgs.system}.run {
          src = ./.;
          hooks = import ./nix/pre-commit-check.nix {
            inherit pkgs;
            treefmt = treefmtWrapper pkgs;
          };
        };
      });
      packages = forEachSystem (
        pkgs:
        (self.overlays.default pkgs pkgs)
        // {
          iocaine-cross =
            builtins.mapAttrs (
              _: spkgs:
              spkgs.callPackage ./nix/iocaine.nix { }
              // {
                static = spkgs.pkgsStatic.callPackage ./nix/iocaine.nix { doCheck = false; };
              }
            ) pkgs.pkgsCross
            // {
              "${pkgs.hostPlatform.system}" = self.packages.${pkgs.hostPlatform.system}.iocaine // {
                static = self.packages.${pkgs.hostPlatform.system}.iocaine-static;
              };
            };
        }
        // {
          default = self.packages.${pkgs.hostPlatform.system}.iocaine;
          container-image =
            let
              makeContainer = import ./nix/makeContainer.nix {
                inherit self pkgs;
              };
            in
            lib.attrsets.genAttrs [ "amd64" "arm64" ] makeContainer;
        }
      );

      apps = forEachSystem (pkgs: {
        iocaine = {
          type = "app";
          program = "${pkgs.lib.getExe pkgs.iocaine}";
        };
      });

      devShells = forEachSystem (pkgs: {
        default = pkgs.mkShell {
          packages = with pkgs; [
            cargo
            clippy
            just
            reuse
            rustc
            rust-analyzer
            zstd
          ];
          inputsFrom = [
            treefmtEval.${pkgs.system}.config.build.devShell
          ];
          shellHook = ''
            export RUSTFLAGS="--cfg tokio_unstable"
          ''
          + self.checks.${pkgs.system}.pre-commit-check.shellHook;
        };
      });
    };
}