2023-11-29 04:08:21 +03:00
|
|
|
{
|
|
|
|
description = "Build a cargo project which uses SQLx";
|
|
|
|
|
|
|
|
inputs = {
|
|
|
|
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
|
|
|
|
|
|
|
|
crane = {
|
|
|
|
url = "github:ipetkov/crane";
|
|
|
|
inputs.nixpkgs.follows = "nixpkgs";
|
|
|
|
};
|
|
|
|
|
|
|
|
flake-utils.url = "github:numtide/flake-utils";
|
|
|
|
};
|
|
|
|
|
|
|
|
outputs = { self, nixpkgs, crane, flake-utils, ... }:
|
|
|
|
flake-utils.lib.eachDefaultSystem (system:
|
|
|
|
let
|
|
|
|
pkgs = nixpkgs.legacyPackages.${system};
|
|
|
|
|
|
|
|
inherit (pkgs) lib;
|
|
|
|
|
|
|
|
craneLib = crane.lib.${system};
|
|
|
|
|
|
|
|
sqlFilter = path: _type: null != builtins.match ".*sql$" path;
|
|
|
|
sqlOrCargo = path: type: (sqlFilter path type) || (craneLib.filterCargoSources path type);
|
|
|
|
|
|
|
|
src = lib.cleanSourceWith {
|
|
|
|
src = craneLib.path ./.; # The original, unfiltered source
|
|
|
|
filter = sqlOrCargo;
|
|
|
|
};
|
|
|
|
|
|
|
|
# Common arguments can be set here to avoid repeating them later
|
|
|
|
commonArgs = {
|
|
|
|
inherit src;
|
|
|
|
strictDeps = true;
|
|
|
|
|
|
|
|
nativeBuildInputs = [
|
|
|
|
pkgs.pkg-config
|
|
|
|
];
|
|
|
|
|
|
|
|
buildInputs = [
|
|
|
|
# Add additional build inputs here
|
|
|
|
pkgs.openssl
|
|
|
|
] ++ lib.optionals pkgs.stdenv.isDarwin [
|
|
|
|
# Additional darwin specific inputs can be set here
|
|
|
|
pkgs.libiconv
|
2023-12-16 21:03:21 +03:00
|
|
|
pkgs.darwin.apple_sdk.frameworks.Security
|
2023-11-29 04:08:21 +03:00
|
|
|
];
|
|
|
|
|
|
|
|
# Additional environment variables can be set directly
|
|
|
|
# MY_CUSTOM_VAR = "some value";
|
|
|
|
};
|
|
|
|
|
|
|
|
# Build *just* the cargo dependencies, so we can reuse
|
|
|
|
# all of that work (e.g. via cachix) when running in CI
|
|
|
|
cargoArtifacts = craneLib.buildDepsOnly commonArgs;
|
|
|
|
|
|
|
|
# Build the actual crate itself, reusing the dependency
|
|
|
|
# artifacts from above.
|
|
|
|
my-crate = craneLib.buildPackage (commonArgs // {
|
|
|
|
inherit cargoArtifacts;
|
|
|
|
|
|
|
|
nativeBuildInputs = (commonArgs.nativeBuildInputs or [ ]) ++ [
|
2023-11-30 03:15:13 +03:00
|
|
|
pkgs.sqlx-cli
|
2023-11-29 04:08:21 +03:00
|
|
|
];
|
|
|
|
|
2023-11-30 03:15:13 +03:00
|
|
|
preBuild = ''
|
|
|
|
export DATABASE_URL=sqlite:./db.sqlite3
|
|
|
|
sqlx database create
|
|
|
|
sqlx migrate run
|
2023-11-29 04:08:21 +03:00
|
|
|
'';
|
|
|
|
});
|
|
|
|
in
|
|
|
|
{
|
|
|
|
checks = {
|
|
|
|
# Build the crate as part of `nix flake check` for convenience
|
|
|
|
inherit my-crate;
|
|
|
|
};
|
|
|
|
|
|
|
|
packages = {
|
|
|
|
default = my-crate;
|
|
|
|
inherit my-crate;
|
|
|
|
};
|
|
|
|
|
|
|
|
devShells.default = craneLib.devShell {
|
|
|
|
# Inherit inputs from checks.
|
|
|
|
checks = self.checks.${system};
|
|
|
|
|
|
|
|
# Additional dev-shell environment variables can be set directly
|
|
|
|
# MY_CUSTOM_DEVELOPMENT_VAR = "something else";
|
|
|
|
|
|
|
|
# Extra inputs can be added here; cargo and rustc are provided by default.
|
|
|
|
packages = [
|
|
|
|
pkgs.sqlx-cli
|
|
|
|
];
|
|
|
|
};
|
|
|
|
});
|
|
|
|
}
|