Files
tamerye/flake.nix
T
oysteikt 6ba07d6f0b
Build and test / check (push) Successful in 44s
Build and test / build-static-library (push) Successful in 48s
Build and test / build-dynamic-library (push) Successful in 50s
Build and test / test (push) Successful in 58s
flake.nix: use crane's toolchains for crane builds
2026-05-07 01:40:05 +09:00

142 lines
3.5 KiB
Nix

{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
rust-overlay.url = "github:oxalica/rust-overlay";
rust-overlay.inputs.nixpkgs.follows = "nixpkgs";
crane.url = "github:ipetkov/crane";
};
outputs = { self, nixpkgs, rust-overlay, crane }:
let
inherit (nixpkgs) lib;
systems = [
"x86_64-linux"
"aarch64-linux"
"x86_64-darwin"
"aarch64-darwin"
];
forAllSystems = f: lib.genAttrs systems (system: let
pkgs = import nixpkgs {
inherit system;
overlays = [
(import rust-overlay)
];
};
rust-bin = rust-overlay.lib.mkRustBin { } pkgs.buildPackages;
toolchain = rust-bin.stable.latest.default.override {
extensions = [ "rust-src" "rust-analyzer" "rust-std" ];
};
in f system pkgs toolchain);
in {
devShells = forAllSystems (system: pkgs: toolchain: {
default = pkgs.mkShell {
nativeBuildInputs = with pkgs; [
toolchain
cargo-edit
pkg-config
sqlite-interactive
];
buildInputs = with pkgs; [
sqlite
];
RUST_SRC_PATH = "${toolchain}/lib/rustlib/src/rust/library";
};
});
packages = let
src = builtins.filterSource (path: type: let
baseName = baseNameOf (toString path);
in !(lib.any (b: b) [
(!(lib.cleanSourceFilter path type))
(baseName == ".gitea" && type == "directory")
(baseName == ".envrc" && type == "regular")
(baseName == "flake.lock" && type == "regular")
(baseName == "flake.nix" && type == "regular")
])) ./.;
cargoToml = builtins.fromTOML (builtins.readFile ./Cargo.toml);
in forAllSystems (system: pkgs: _: let
craneLib = (crane.mkLib pkgs).overrideToolchain (p: p.rust-bin.stable.latest.default);
in {
default = self.packages.${system}.tamerye-shared-lib-crane;
tamerye-shared-lib-crane = craneLib.buildPackage {
pname = "tamerye-shared-lib";
version = cargoToml.package.version;
inherit src;
strictDeps = true;
doCheck = false;
cargoArtifacts = craneLib.buildDepsOnly {
inherit src;
strictDeps = true;
};
};
tamerye-static-lib-crane = craneLib.buildPackage {
pname = "tamerye-static-lib";
version = cargoToml.package.version;
inherit src;
strictDeps = true;
doCheck = false;
postPatch = ''
'${lib.getExe pkgs.yq-go}' '.lib.crate-type = [ "staticlib" ]' --inplace Cargo.toml
'';
buildInputs = with pkgs; [
sqlite
];
cargoArtifacts = craneLib.buildDepsOnly {
inherit src;
strictDeps = true;
buildInputs = with pkgs; [
sqlite
];
};
cargoExtraArgs = lib.escapeShellArgs [ "--features" "static" ];
};
tamerye-tests-crane = craneLib.cargoNextest {
pname = "tamerye-tests";
version = cargoToml.package.version;
inherit src;
strictDeps = true;
buildInputs = with pkgs; [
sqlite
];
cargoArtifacts = craneLib.buildDepsOnly {
inherit src;
strictDeps = true;
buildInputs = with pkgs; [
sqlite
];
};
cargoExtraArgs = lib.escapeShellArgs [ "--features" "static" ];
partitions = 1;
partitionType = "count";
cargoNextestPartitionsExtraArgs = "--no-tests=pass";
};
});
};
}