opentelemetry-detector-ecs 0.2.0

An OpenTelemetry resource detector for Amazon ECS.
Documentation
{
  description = "An OpenTelemetry resource detector for Amazon ECS";

  inputs = {
    nixpkgs.url = "https://flakehub.com/f/DeterminateSystems/nixpkgs-weekly/*";

    fenix.url = "https://flakehub.com/f/nix-community/fenix/*";
    fenix.inputs.nixpkgs.follows = "nixpkgs";
  };

  outputs =
    { nixpkgs, fenix, ... }:
    let
      inherit (nixpkgs) lib;

      systems = [
        "aarch64-darwin"
        "aarch64-linux"
        "x86_64-linux"
      ];

      forEachSystem =
        f:
        lib.genAttrs systems (
          system:
          let
            pkgs = nixpkgs.legacyPackages.${system};

            toolchain =
              with fenix.packages.${system};
              combine [
                stable.cargo
                stable.clippy
                stable.rust-src
                stable.rustc
                stable.rustfmt
              ];
          in
          f { inherit pkgs toolchain; }
        );
    in
    {
      devShells = forEachSystem (
        { pkgs, toolchain }:
        {
          # A clang stdenv because that is what aws-lc-fips-sys's build, behind
          # the `fips` feature, is tested against.
          default = pkgs.mkShell.override { stdenv = pkgs.clangStdenv; } {
            name = "opentelemetry-detector-ecs";

            packages = [
              toolchain

              # The `fips` feature builds AWS-LC's FIPS module from source.
              pkgs.cmake
              pkgs.go
              pkgs.perl

              pkgs.cargo-audit
              pkgs.cargo-machete
              pkgs.cargo-outdated
              pkgs.eclint
              pkgs.jq
              pkgs.just
              pkgs.nixfmt
              pkgs.rust-analyzer
              pkgs.typos
            ];

            env.RUST_SRC_PATH = "${toolchain}/lib/rustlib/src/rust/library";
          };
        }
      );

      # Build the crate and run its tests on FIPS-validated crypto, so
      # `nix build .#checks.x86_64-linux.fips` (or aarch64-linux) exercises
      # a Linux build from any machine with a Linux builder. Only the Linux
      # systems: AWS-LC supports its static FIPS build nowhere else, and the
      # macOS shared build wants a codesign the sandbox lacks. A macOS
      # working copy still runs `just test-fips` in the dev shell.
      checks = lib.genAttrs (lib.filter (lib.hasSuffix "-linux") systems) (
        system:
        let
          pkgs = nixpkgs.legacyPackages.${system};
        in
        {
          fips = pkgs.rustPlatform.buildRustPackage.override { stdenv = pkgs.clangStdenv; } {
            pname = "opentelemetry-detector-ecs-fips";
            version = (lib.importTOML ./Cargo.toml).package.version;

            src = lib.fileset.toSource {
              root = ./.;
              fileset = lib.fileset.unions [
                ./Cargo.toml
                ./Cargo.lock
                ./src
                ./tests
              ];
            };

            cargoLock.lockFile = ./Cargo.lock;

            buildFeatures = [ "fips" ];

            # The static library, so the tests need no shared-object path.
            AWS_LC_FIPS_SYS_STATIC = "1";

            # nixpkgs' cargo hooks export HOST_CC/HOST_CXX naming the build
            # platform's gcc, and on a native build AWS-LC's build script
            # prefers those over the clang stdenv's CC. Its x86_64 delocator
            # accepts only clang's assembly, so name clang through the
            # crate-specific variables that outrank the hooks'.
            AWS_LC_FIPS_SYS_HOST_CC = "clang";
            AWS_LC_FIPS_SYS_HOST_CXX = "clang++";

            nativeBuildInputs = [
              # aws-lc-fips-sys builds AWS-LC's FIPS module from source.
              pkgs.cmake
              pkgs.go
              pkgs.perl
            ];

            # cmake is above only for aws-lc-fips-sys's build script; the
            # crate itself configures with cargo.
            dontUseCmakeConfigure = true;
          };
        }
      );

      formatter = forEachSystem ({ pkgs, ... }: pkgs.nixfmt);
    };
}