2021-12-26 22:47:16 +03:00
|
|
|
{
|
2023-09-18 23:37:51 +03:00
|
|
|
description = "A Nix library for building cargo projects. Never build twice thanks to incremental artifact caching.";
|
|
|
|
|
2023-10-19 03:57:24 +03:00
|
|
|
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
|
2021-12-26 22:47:16 +03:00
|
|
|
|
2023-06-19 02:16:45 +03:00
|
|
|
nixConfig = {
|
|
|
|
extra-substituters = [ "https://crane.cachix.org" ];
|
|
|
|
extra-trusted-public-keys = [ "crane.cachix.org-1:8Scfpmn9w+hGdXH/Q9tTLiYAE/2dnJYRJP7kl80GuRk=" ];
|
|
|
|
};
|
|
|
|
|
2023-10-19 03:57:24 +03:00
|
|
|
outputs = { nixpkgs, ... }:
|
2021-12-26 22:47:16 +03:00
|
|
|
let
|
2024-06-03 05:48:19 +03:00
|
|
|
mkLib = pkgs: import ./default.nix {
|
|
|
|
inherit pkgs;
|
2022-01-16 07:21:02 +03:00
|
|
|
};
|
2023-10-19 03:57:24 +03:00
|
|
|
nodes = (builtins.fromJSON (builtins.readFile ./test/flake.lock)).nodes;
|
|
|
|
inputFromLock = name:
|
|
|
|
let
|
|
|
|
locked = nodes.${name}.locked;
|
|
|
|
in
|
|
|
|
fetchTarball {
|
|
|
|
url = "https://github.com/${locked.owner}/${locked.repo}/archive/${locked.rev}.tar.gz";
|
|
|
|
sha256 = locked.narHash;
|
|
|
|
};
|
|
|
|
|
|
|
|
eachSystem = systems: f:
|
|
|
|
let
|
|
|
|
# Merge together the outputs for all systems.
|
|
|
|
op = attrs: system:
|
|
|
|
let
|
|
|
|
ret = f system;
|
|
|
|
op = attrs: key: attrs //
|
|
|
|
{
|
|
|
|
${key} = (attrs.${key} or { })
|
|
|
|
// { ${system} = ret.${key}; };
|
|
|
|
}
|
|
|
|
;
|
|
|
|
in
|
|
|
|
builtins.foldl' op attrs (builtins.attrNames ret);
|
|
|
|
in
|
|
|
|
builtins.foldl' op { } systems;
|
|
|
|
|
|
|
|
eachDefaultSystem = eachSystem [
|
|
|
|
"aarch64-linux"
|
|
|
|
"aarch64-darwin"
|
|
|
|
"x86_64-darwin"
|
|
|
|
"x86_64-linux"
|
|
|
|
];
|
2021-12-26 22:47:16 +03:00
|
|
|
in
|
|
|
|
{
|
2022-01-16 07:21:02 +03:00
|
|
|
inherit mkLib;
|
|
|
|
|
2022-10-24 02:20:22 +03:00
|
|
|
overlays.default = _final: _prev: { };
|
2022-01-17 01:25:41 +03:00
|
|
|
|
2022-06-02 03:09:29 +03:00
|
|
|
templates = rec {
|
2022-02-16 05:43:49 +03:00
|
|
|
alt-registry = {
|
|
|
|
description = "Build a cargo project with alternative crate registries";
|
|
|
|
path = ./examples/alt-registry;
|
|
|
|
};
|
|
|
|
|
2024-07-15 18:49:38 +03:00
|
|
|
build-std = {
|
|
|
|
description = "Build a cargo project while also compiling the standard library";
|
|
|
|
path = ./examples/build-std;
|
|
|
|
};
|
|
|
|
|
2022-02-17 07:50:59 +03:00
|
|
|
cross-musl = {
|
|
|
|
description = "Building static binaries with musl";
|
2022-05-12 00:37:47 +03:00
|
|
|
path = ./examples/cross-musl;
|
2022-02-17 07:50:59 +03:00
|
|
|
};
|
|
|
|
|
2022-02-16 05:42:59 +03:00
|
|
|
cross-rust-overlay = {
|
|
|
|
description = "Cross compiling a rust program using rust-overlay";
|
|
|
|
path = ./examples/cross-rust-overlay;
|
|
|
|
};
|
|
|
|
|
2023-01-07 04:11:42 +03:00
|
|
|
cross-windows = {
|
|
|
|
description = "Cross compiling a rust program for windows";
|
|
|
|
path = ./examples/cross-windows;
|
|
|
|
};
|
|
|
|
|
2022-01-17 03:11:11 +03:00
|
|
|
custom-toolchain = {
|
|
|
|
description = "Build a cargo project with a custom toolchain";
|
|
|
|
path = ./examples/custom-toolchain;
|
|
|
|
};
|
|
|
|
|
2023-10-13 04:59:36 +03:00
|
|
|
end-to-end-testing = {
|
|
|
|
description = "Run End-to-End tests for a webapp";
|
|
|
|
path = ./examples/end-to-end-testing;
|
|
|
|
};
|
|
|
|
|
2022-06-02 03:09:29 +03:00
|
|
|
default = quick-start;
|
2022-01-17 03:54:55 +03:00
|
|
|
quick-start = {
|
2022-01-17 03:11:11 +03:00
|
|
|
description = "Build a cargo project";
|
2022-01-17 03:54:55 +03:00
|
|
|
path = ./examples/quick-start;
|
|
|
|
};
|
|
|
|
|
|
|
|
quick-start-simple = {
|
|
|
|
description = "Build a cargo project without extra checks";
|
|
|
|
path = ./examples/quick-start-simple;
|
2022-01-17 03:11:11 +03:00
|
|
|
};
|
2023-04-29 22:34:39 +03:00
|
|
|
|
2024-07-15 18:49:38 +03:00
|
|
|
quick-start-workspace = {
|
|
|
|
description = "Build a cargo workspace with hakari";
|
|
|
|
path = ./examples/quick-start-workspace;
|
|
|
|
};
|
|
|
|
|
2023-11-29 04:08:21 +03:00
|
|
|
sqlx = {
|
|
|
|
description = "Build a cargo project which uses SQLx";
|
|
|
|
path = ./examples/sqlx;
|
|
|
|
};
|
|
|
|
|
2023-04-29 22:34:39 +03:00
|
|
|
trunk = {
|
|
|
|
description = "Build a trunk project";
|
|
|
|
path = ./examples/trunk;
|
|
|
|
};
|
|
|
|
|
|
|
|
trunk-workspace = {
|
|
|
|
description = "Build a workspace with a trunk member";
|
|
|
|
path = ./examples/trunk-workspace;
|
|
|
|
};
|
2022-01-17 03:11:11 +03:00
|
|
|
};
|
2023-10-19 03:57:24 +03:00
|
|
|
} // eachDefaultSystem (system:
|
2021-12-27 02:32:57 +03:00
|
|
|
let
|
2023-11-26 21:37:43 +03:00
|
|
|
pkgs = nixpkgs.legacyPackages.${system};
|
2022-12-27 01:27:13 +03:00
|
|
|
|
2024-02-08 06:38:28 +03:00
|
|
|
# To override do: lib.overrideScope (self: super: { ... });
|
2024-05-19 04:07:07 +03:00
|
|
|
lib = pkgs.lib.warn
|
|
|
|
"`crane.lib.\${system}` is deprecated. please use `(crane.mkLib nixpkgs.legacyPackages.\${system})` instead"
|
|
|
|
(mkLib pkgs);
|
2023-01-22 03:46:32 +03:00
|
|
|
|
2022-10-19 05:13:38 +03:00
|
|
|
checks =
|
|
|
|
let
|
|
|
|
pkgsChecks = import nixpkgs {
|
|
|
|
inherit system;
|
2023-03-20 02:44:14 +03:00
|
|
|
overlays = [
|
2023-10-19 03:57:24 +03:00
|
|
|
(import (inputFromLock "rust-overlay"))
|
2023-03-20 02:44:14 +03:00
|
|
|
];
|
2022-10-19 05:13:38 +03:00
|
|
|
};
|
|
|
|
in
|
|
|
|
pkgsChecks.callPackages ./checks {
|
|
|
|
pkgs = pkgsChecks;
|
|
|
|
myLib = mkLib pkgsChecks;
|
2024-01-28 22:08:44 +03:00
|
|
|
myLibCross = mkLib (import nixpkgs {
|
|
|
|
localSystem = system;
|
|
|
|
crossSystem = "wasm32-wasi";
|
|
|
|
});
|
2022-10-19 05:13:38 +03:00
|
|
|
};
|
2021-12-27 02:32:57 +03:00
|
|
|
in
|
|
|
|
{
|
2024-01-28 22:08:44 +03:00
|
|
|
inherit checks lib;
|
|
|
|
|
|
|
|
packages = import ./pkgs {
|
|
|
|
inherit pkgs;
|
|
|
|
myLib = lib;
|
|
|
|
};
|
2021-12-27 02:32:57 +03:00
|
|
|
|
2022-10-19 05:13:38 +03:00
|
|
|
formatter = pkgs.nixpkgs-fmt;
|
2022-11-21 03:28:49 +03:00
|
|
|
|
2022-06-02 03:09:29 +03:00
|
|
|
devShells.default = pkgs.mkShell {
|
2022-01-04 23:55:36 +03:00
|
|
|
nativeBuildInputs = with pkgs; [
|
2022-05-29 23:26:42 +03:00
|
|
|
jq
|
2022-12-27 01:27:13 +03:00
|
|
|
mdbook
|
2023-10-15 23:07:14 +03:00
|
|
|
nix-eval-jobs
|
2022-01-04 23:55:36 +03:00
|
|
|
nixpkgs-fmt
|
|
|
|
];
|
2021-12-27 02:32:57 +03:00
|
|
|
};
|
|
|
|
});
|
2021-12-26 22:47:16 +03:00
|
|
|
}
|