Modernise CI (#9)
Co-authored-by: Smaug123 <3138005+Smaug123@users.noreply.github.com> Reviewed-on: #9
This commit is contained in:
180
flake.nix
180
flake.nix
@@ -3,109 +3,111 @@
|
||||
|
||||
inputs = {
|
||||
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
|
||||
utils.url = "github:numtide/flake-utils";
|
||||
rust-overlay.url = "github:oxalica/rust-overlay";
|
||||
crate2nix = {
|
||||
url = "github:kolloch/crate2nix";
|
||||
flake = false;
|
||||
flake-utils.url = "github:numtide/flake-utils";
|
||||
rust-overlay = {
|
||||
url = "github:oxalica/rust-overlay";
|
||||
inputs.nixpkgs.follows = "nixpkgs";
|
||||
};
|
||||
flake-compat = {
|
||||
url = "github:edolstra/flake-compat";
|
||||
flake = false;
|
||||
crane = {
|
||||
url = "github:ipetkov/crane";
|
||||
};
|
||||
};
|
||||
|
||||
outputs = {
|
||||
self,
|
||||
nixpkgs,
|
||||
utils,
|
||||
rust-overlay,
|
||||
crate2nix,
|
||||
...
|
||||
}: let
|
||||
name = "little_learner_app";
|
||||
in
|
||||
utils.lib.eachDefaultSystem
|
||||
(
|
||||
system: let
|
||||
# Imports
|
||||
outputs = { self, nixpkgs, flake-utils, rust-overlay, crane }:
|
||||
flake-utils.lib.eachDefaultSystem (system:
|
||||
let
|
||||
pkgs = import nixpkgs {
|
||||
inherit system;
|
||||
overlays = [
|
||||
rust-overlay.overlays.default
|
||||
(self: super: {
|
||||
# Because rust-overlay bundles multiple rust packages into one
|
||||
# derivation, specify that mega-bundle here, so that crate2nix
|
||||
# will use them automatically.
|
||||
rustc = self.rust-bin.nightly.latest.default;
|
||||
cargo = self.rust-bin.nightly.latest.default;
|
||||
})
|
||||
overlays = [ (import rust-overlay) ];
|
||||
};
|
||||
|
||||
rustToolchain = pkgs.rust-bin.nightly.latest.default;
|
||||
|
||||
craneLib = (crane.mkLib pkgs).overrideToolchain rustToolchain;
|
||||
|
||||
# Common build inputs for all derivations
|
||||
commonArgs = {
|
||||
src = pkgs.lib.cleanSourceWith {
|
||||
src = ./.;
|
||||
name = "source";
|
||||
filter = path: type: (builtins.match ".*csv$" path != null || craneLib.filterCargoSources path type);
|
||||
};
|
||||
strictDeps = true;
|
||||
|
||||
buildInputs = with pkgs; [
|
||||
openssl
|
||||
];
|
||||
|
||||
nativeBuildInputs = with pkgs; [
|
||||
pkg-config
|
||||
];
|
||||
};
|
||||
inherit
|
||||
(import "${crate2nix}/tools.nix" {inherit pkgs;})
|
||||
generatedCargoNix
|
||||
;
|
||||
|
||||
# Create the cargo2nix project
|
||||
project =
|
||||
pkgs.callPackage
|
||||
(generatedCargoNix {
|
||||
inherit name;
|
||||
src = ./.;
|
||||
})
|
||||
{
|
||||
# Individual crate overrides go here
|
||||
# Example: https://github.com/balsoft/simple-osd-daemons/blob/6f85144934c0c1382c7a4d3a2bbb80106776e270/flake.nix#L28-L50
|
||||
defaultCrateOverrides =
|
||||
pkgs.defaultCrateOverrides
|
||||
// {
|
||||
# The app crate itself is overriden here. Typically we
|
||||
# configure non-Rust dependencies (see below) here.
|
||||
${name} = oldAttrs:
|
||||
{
|
||||
inherit buildInputs nativeBuildInputs;
|
||||
}
|
||||
// buildEnvVars;
|
||||
};
|
||||
# Build just the cargo dependencies
|
||||
cargoArtifacts = craneLib.buildDepsOnly commonArgs;
|
||||
|
||||
# Build the actual package
|
||||
little_learner_app = craneLib.buildPackage (commonArgs // {
|
||||
inherit cargoArtifacts;
|
||||
});
|
||||
in
|
||||
{
|
||||
packages = {
|
||||
default = little_learner_app;
|
||||
little_learner_app = little_learner_app;
|
||||
};
|
||||
|
||||
apps.default = flake-utils.lib.mkApp {
|
||||
drv = little_learner_app;
|
||||
exePath = "/bin/little_learner_app";
|
||||
};
|
||||
|
||||
devShells = {
|
||||
default = craneLib.devShell {
|
||||
# Inherit the build inputs from commonArgs
|
||||
buildInputs = commonArgs.buildInputs;
|
||||
nativeBuildInputs = commonArgs.nativeBuildInputs;
|
||||
|
||||
# Additional dev tools
|
||||
packages = [
|
||||
rustToolchain
|
||||
pkgs.rust-analyzer
|
||||
];
|
||||
|
||||
RUST_SRC_PATH = "${rustToolchain}/lib/rustlib/src/rust/library";
|
||||
};
|
||||
|
||||
# Configuration for the non-Rust dependencies
|
||||
buildInputs = with pkgs; [openssl.dev];
|
||||
nativeBuildInputs = with pkgs; [rustc cargo pkgconfig];
|
||||
buildEnvVars = {
|
||||
PKG_CONFIG_PATH = "${pkgs.openssl.dev}/lib/pkgconfig";
|
||||
};
|
||||
in rec {
|
||||
packages.${name} = project.workspaceMembers.${name}.build;
|
||||
ci = pkgs.mkShell {
|
||||
buildInputs = commonArgs.buildInputs ++ [
|
||||
pkgs.nodePackages.markdown-link-check
|
||||
pkgs.nixpkgs-fmt
|
||||
rustToolchain
|
||||
];
|
||||
|
||||
# `nix build`
|
||||
defaultPackage = packages.${name};
|
||||
nativeBuildInputs = commonArgs.nativeBuildInputs;
|
||||
|
||||
# `nix run`
|
||||
apps.${name} = utils.lib.mkApp {
|
||||
inherit name;
|
||||
drv = packages.${name};
|
||||
RUST_SRC_PATH = "${rustToolchain}/lib/rustlib/src/rust/library";
|
||||
};
|
||||
};
|
||||
defaultApp = apps.${name};
|
||||
|
||||
# `nix develop`
|
||||
devShells = {
|
||||
ci =
|
||||
pkgs.mkShell {
|
||||
inherit nativeBuildInputs;
|
||||
buildInputs = [pkgs.nodePackages.markdown-link-check pkgs.alejandra] ++ buildInputs;
|
||||
RUST_SRC_PATH = "${pkgs.rust.packages.stable.rustPlatform.rustLibSrc}";
|
||||
}
|
||||
// buildEnvVars;
|
||||
default =
|
||||
pkgs.mkShell
|
||||
{
|
||||
inherit buildInputs nativeBuildInputs;
|
||||
RUST_SRC_PATH = "${pkgs.rust.packages.stable.rustPlatform.rustLibSrc}";
|
||||
}
|
||||
// buildEnvVars;
|
||||
checks = {
|
||||
inherit little_learner_app;
|
||||
|
||||
# Run cargo fmt check
|
||||
fmt = craneLib.cargoFmt {
|
||||
inherit (commonArgs) src;
|
||||
};
|
||||
|
||||
# Run clippy
|
||||
clippy = craneLib.cargoClippy (commonArgs // {
|
||||
inherit cargoArtifacts;
|
||||
cargoClippyExtraArgs = "--all-targets -- --deny warnings";
|
||||
});
|
||||
|
||||
# Run tests
|
||||
tests = craneLib.cargoTest (commonArgs // {
|
||||
inherit cargoArtifacts;
|
||||
});
|
||||
};
|
||||
}
|
||||
);
|
||||
});
|
||||
}
|
||||
|
Reference in New Issue
Block a user