graphql-engine/v3/nix/app.nix
Daniel Harvey 4ea88180d7 create Docker images with Nix (#507)
<!-- Thank you for submitting this PR! :) -->

## Description

In order to test things quicker, we'd like to be able to build custom
connector and friends in Nix, and then use the containers when running
tests. First step here is to be able to build Docker containers in Nix,
and add a CI job to ensure it still works.

Then we'll move onto publishing and using these images.

No-op build times:

<img width="336" alt="Screenshot 2024-04-25 at 15 53 56"
src="https://github.com/hasura/v3-engine/assets/4729125/47cbc0c5-6e54-4583-aa01-0528d4a21080">

Functional no-op.

V3_GIT_ORIGIN_REV_ID: 8f9d609e26cdd3b0801e61fd361c241ad504dcdf
2024-04-26 08:44:04 +00:00

57 lines
1.4 KiB
Nix

# This is a function that returns a derivation for the compiled Rust project.
{ craneLib
, lib
, version
, stdenv
, openssl
, libiconv
, pkg-config
, protobuf
, darwin
, pname
}:
let
buildArgs = {
inherit pname;
src =
let
isGraphqlFile = path: _type: builtins.match ".*graphql" path != null;
isHtmlFile = path: _type: builtins.match ".*html" path != null;
isJsonFile = path: _type: builtins.match ".*json" path != null;
isSourceFile = path: type:
isGraphqlFile path type
|| isHtmlFile path type
|| isJsonFile path type
|| craneLib.filterCargoSources path type;
in
lib.cleanSourceWith { src = craneLib.path ./..; filter = isSourceFile; };
buildInputs = [
openssl
] ++ lib.optionals stdenv.hostPlatform.isDarwin [
libiconv
darwin.apple_sdk.frameworks.Security
darwin.apple_sdk.frameworks.SystemConfiguration
];
nativeBuildInputs = [
pkg-config # required for non-static builds
protobuf # required by opentelemetry-proto, a dependency of axum-tracing-opentelemetry
];
};
# only build the binary we care about
cargoExtraArgs = "--bin ${buildArgs.pname}";
# Build the dependencies first.
cargoArtifacts = craneLib.buildDepsOnly buildArgs;
in
# Then build the crate.
craneLib.buildPackage
(buildArgs // {
inherit cargoArtifacts cargoExtraArgs;
doCheck = false;
RELEASE_VERSION = version;
})