cartographer/flake.nix

186 lines
5.1 KiB
Nix
Raw Normal View History

2024-09-11 01:34:47 -07:00
{
2024-12-02 03:05:18 -08:00
description = "A TUI for the Canvas LMS";
2024-09-11 01:34:47 -07:00
inputs = {
2024-12-02 03:05:18 -08:00
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
crane.url = "github:ipetkov/crane";
2024-09-12 01:26:38 -07:00
fenix = {
2024-12-02 03:05:18 -08:00
# url = "github:nix-community/fenix";
url = "github:Defelo/fenix/staging";
2024-09-12 01:26:38 -07:00
inputs.nixpkgs.follows = "nixpkgs";
2024-12-02 03:05:18 -08:00
inputs.rust-analyzer-src.follows = "";
2024-09-12 01:26:38 -07:00
};
2024-12-02 03:05:18 -08:00
flake-parts.url = "github:hercules-ci/flake-parts";
advisory-db = {
url = "github:rustsec/advisory-db";
flake = false;
};
devenv.url = "github:cachix/devenv";
2024-09-11 01:34:47 -07:00
};
outputs =
2024-10-29 21:30:17 -07:00
inputs@{
flake-parts,
2024-12-02 03:05:18 -08:00
crane,
2024-09-12 01:26:38 -07:00
fenix,
2024-12-02 03:05:18 -08:00
advisory-db,
2024-09-11 01:34:47 -07:00
...
}:
2024-10-29 21:30:17 -07:00
flake-parts.lib.mkFlake { inherit inputs; } {
2024-12-02 03:05:18 -08:00
imports = [
inputs.devenv.flakeModule
];
2024-10-29 21:30:17 -07:00
systems = [
"x86_64-linux"
2024-12-02 03:05:18 -08:00
"aarch64-linux"
2024-10-29 21:30:17 -07:00
"x86_64-darwin"
2024-12-02 03:05:18 -08:00
"aarch64-darwin"
2024-10-29 21:30:17 -07:00
];
perSystem =
2024-12-02 03:05:18 -08:00
{
config,
pkgs,
system,
...
}:
2024-10-29 21:30:17 -07:00
let
2024-12-02 03:05:18 -08:00
inherit (pkgs) lib;
2024-12-02 03:05:18 -08:00
craneLib = crane.mkLib pkgs;
src = craneLib.cleanCargoSource ./.;
2024-12-02 03:05:18 -08:00
# Common arguments can be set here to avoid repeating them later
commonArgs = {
inherit src;
strictDeps = true;
nativeBuildInputs = with pkgs; [
2024-10-29 21:30:17 -07:00
pkg-config
2024-12-02 03:05:18 -08:00
];
buildInputs = with pkgs; [
2024-10-29 21:30:17 -07:00
openssl
];
2024-12-02 03:05:18 -08:00
# Additional environment variables can be set directly
# MY_CUSTOM_VAR = "some value";
2024-10-29 21:30:17 -07:00
};
2024-12-02 03:05:18 -08:00
craneLibLLvmTools = craneLib.overrideToolchain (
fenix.packages.${system}.complete.withComponents [
"cargo"
"llvm-tools"
"rustc"
]
);
# 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.
cartographer = craneLib.buildPackage (
commonArgs
// {
inherit cargoArtifacts;
}
);
in
{
checks = {
# Build the crate as part of `nix flake check` for convenience
inherit cartographer;
# Run clippy (and deny all warnings) on the crate source,
# again, reusing the dependency artifacts from above.
#
# Note that this is done as a separate derivation so that
# we can block the CI if there are issues here, but not
# prevent downstream consumers from building our crate by itself.
cartographer-clippy = craneLib.cargoClippy (
commonArgs
// {
inherit cargoArtifacts;
cargoClippyExtraArgs = "--all-targets -- --deny warnings";
}
);
cartographer-doc = craneLib.cargoDoc (
commonArgs
2024-10-29 21:30:17 -07:00
// {
2024-12-02 03:05:18 -08:00
inherit cargoArtifacts;
2024-10-29 21:30:17 -07:00
}
);
2024-12-02 03:05:18 -08:00
# Check formatting
cartographer-fmt = craneLib.cargoFmt {
inherit src;
};
cartographer-toml-fmt = craneLib.taploFmt {
src = pkgs.lib.sources.sourceFilesBySuffices src [ ".toml" ];
# taplo arguments can be further customized below as needed
# taploExtraArgs = "--config ./taplo.toml";
};
# Audit dependencies
cartographer-audit = craneLib.cargoAudit {
inherit src advisory-db;
};
# Audit licenses
cartographer-deny = craneLib.cargoDeny {
inherit src;
};
# Run tests with cargo-nextest
# Consider setting `doCheck = false` on `cartographer` if you do not want
# the tests to run twice
cartographer-nextest = craneLib.cargoNextest (
commonArgs
// {
inherit cargoArtifacts;
partitions = 1;
partitionType = "count";
}
);
};
packages =
{
default = cartographer;
}
// lib.optionalAttrs (!pkgs.stdenv.isDarwin) {
cartographer-llvm-coverage = craneLibLLvmTools.cargoLlvmCov (
commonArgs
// {
inherit cargoArtifacts;
}
);
};
devenv.shells.default = {
enterShell = ''
export LD_LIBRARY_PATH=${pkgs.lib.makeLibraryPath [ pkgs.openssl ]}:$LD_LIBRARY_PATH
'';
packages = [
(fenix.packages.${system}.complete.withComponents [
"cargo"
"llvm-tools"
"rustc"
"clippy"
"rustfmt"
"rust-analyzer"
])
] ++ config.packages.default.nativeBuildInputs ++ config.packages.default.buildInputs;
2024-10-29 21:30:17 -07:00
};
};
2024-10-29 21:30:17 -07:00
};
2024-09-11 01:34:47 -07:00
}