2024-09-05 07:32:31 +02:00
|
|
|
# SPDX-FileCopyrightText: 2024 Christina Sørensen
|
2024-03-15 09:55:00 +01:00
|
|
|
#
|
2024-09-05 07:32:31 +02:00
|
|
|
# SPDX-License-Identifier: EUPL-1.2
|
|
|
|
|
2024-03-15 09:55:00 +01:00
|
|
|
{
|
2024-09-05 07:32:31 +02:00
|
|
|
description = "Nix Weather - Check Cache Availablility of NixOS Configurations";
|
2024-03-15 09:55:00 +01:00
|
|
|
|
|
|
|
inputs = {
|
2024-09-05 07:32:31 +02:00
|
|
|
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
|
|
|
|
|
|
|
|
lix-module = {
|
|
|
|
url = "git+https://git.lix.systems/lix-project/nixos-module?ref=main";
|
|
|
|
inputs.nixpkgs.follows = "nixpkgs";
|
2024-03-15 09:55:00 +01:00
|
|
|
};
|
|
|
|
|
2024-09-05 07:32:31 +02:00
|
|
|
crane = {
|
|
|
|
url = "github:ipetkov/crane";
|
|
|
|
inputs.nixpkgs.follows = "nixpkgs";
|
2024-03-15 09:55:00 +01:00
|
|
|
};
|
|
|
|
|
2024-09-05 07:32:31 +02:00
|
|
|
fenix = {
|
|
|
|
url = "github:nix-community/fenix";
|
2024-03-15 09:55:00 +01:00
|
|
|
inputs.nixpkgs.follows = "nixpkgs";
|
2024-09-05 07:32:31 +02:00
|
|
|
inputs.rust-analyzer-src.follows = "";
|
2024-03-15 09:55:00 +01:00
|
|
|
};
|
|
|
|
|
2024-09-05 07:32:31 +02:00
|
|
|
gitignore = {
|
|
|
|
url = "github:hercules-ci/gitignore.nix";
|
2024-03-15 09:55:00 +01:00
|
|
|
inputs.nixpkgs.follows = "nixpkgs";
|
2024-09-05 07:32:31 +02:00
|
|
|
};
|
|
|
|
nixpkgs-stable.url = "github:NixOS/nixpkgs/nixos-24.05";
|
|
|
|
|
|
|
|
flake-compat = {
|
|
|
|
url = "github:edolstra/flake-compat";
|
|
|
|
flake = false;
|
|
|
|
};
|
|
|
|
|
|
|
|
flake-utils.url = "github:numtide/flake-utils";
|
|
|
|
|
|
|
|
advisory-db = {
|
|
|
|
url = "github:rustsec/advisory-db";
|
|
|
|
flake = false;
|
2024-03-15 09:55:00 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
treefmt-nix = {
|
|
|
|
url = "github:numtide/treefmt-nix";
|
|
|
|
inputs.nixpkgs.follows = "nixpkgs";
|
|
|
|
};
|
|
|
|
|
2024-09-05 07:32:31 +02:00
|
|
|
rust-overlay = {
|
|
|
|
url = "github:oxalica/rust-overlay";
|
|
|
|
inputs = {
|
|
|
|
nixpkgs.follows = "nixpkgs";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2024-03-15 09:55:00 +01:00
|
|
|
pre-commit-hooks = {
|
2024-09-05 07:32:31 +02:00
|
|
|
url = "github:cachix/git-hooks.nix";
|
|
|
|
inputs = {
|
|
|
|
nixpkgs.follows = "nixpkgs";
|
|
|
|
nixpkgs-stable.follows = "nixpkgs-stable";
|
|
|
|
flake-compat.follows = "flake-compat";
|
|
|
|
gitignore.follows = "gitignore";
|
|
|
|
};
|
2024-03-15 09:55:00 +01:00
|
|
|
};
|
2024-09-05 07:32:31 +02:00
|
|
|
|
2024-03-15 09:55:00 +01:00
|
|
|
};
|
|
|
|
|
2024-09-05 07:32:31 +02:00
|
|
|
outputs =
|
|
|
|
{
|
|
|
|
self,
|
|
|
|
nixpkgs,
|
|
|
|
crane,
|
|
|
|
treefmt-nix,
|
|
|
|
fenix,
|
|
|
|
flake-utils,
|
|
|
|
rust-overlay,
|
|
|
|
advisory-db,
|
|
|
|
pre-commit-hooks,
|
|
|
|
lix-module,
|
|
|
|
...
|
|
|
|
}:
|
2024-03-15 09:55:00 +01:00
|
|
|
flake-utils.lib.eachDefaultSystem (
|
2024-09-05 07:32:31 +02:00
|
|
|
system:
|
|
|
|
let
|
|
|
|
overlays = [ (import rust-overlay) ];
|
2024-03-15 09:55:00 +01:00
|
|
|
|
|
|
|
pkgs = (import nixpkgs) {
|
|
|
|
inherit system overlays;
|
|
|
|
};
|
|
|
|
|
2024-09-05 07:32:31 +02:00
|
|
|
inherit (pkgs) lib;
|
|
|
|
|
|
|
|
toolchain = pkgs.rust-bin.fromRustupToolchainFile ./.config/rust-toolchain.toml;
|
2024-03-15 09:55:00 +01:00
|
|
|
|
2024-09-05 07:32:31 +02:00
|
|
|
craneLib = (crane.mkLib pkgs).overrideToolchain toolchain;
|
|
|
|
src = craneLib.cleanCargoSource ./.;
|
|
|
|
|
|
|
|
# Common arguments can be set here to avoid repeating them later
|
|
|
|
commonArgs = {
|
|
|
|
inherit src;
|
|
|
|
strictDeps = true;
|
|
|
|
|
|
|
|
nativeBuildInputs = [
|
|
|
|
pkgs.pkg-config
|
|
|
|
];
|
|
|
|
|
|
|
|
buildInputs =
|
|
|
|
[
|
|
|
|
pkgs.openssl
|
|
|
|
pkgs.installShellFiles
|
|
|
|
]
|
|
|
|
++ lib.optionals pkgs.stdenv.isDarwin [
|
|
|
|
# Additional darwin specific inputs can be set here
|
|
|
|
pkgs.libiconv
|
|
|
|
];
|
|
|
|
|
|
|
|
# Additional environment variables can be set directly
|
|
|
|
# MY_CUSTOM_VAR = "some value";
|
2024-03-15 09:55:00 +01:00
|
|
|
};
|
|
|
|
|
2024-09-05 07:32:31 +02:00
|
|
|
craneLibLLvmTools = craneLib.overrideToolchain (
|
|
|
|
fenix.packages.${system}.complete.withComponents [
|
|
|
|
"cargo"
|
|
|
|
"llvm-tools"
|
|
|
|
"rustc"
|
|
|
|
]
|
|
|
|
);
|
2024-03-15 09:55:00 +01:00
|
|
|
|
2024-09-05 07:32:31 +02:00
|
|
|
# Build *just* the cargo dependencies (of the entire workspace),
|
|
|
|
# so we can reuse all of that work (e.g. via cachix) when running in CI
|
|
|
|
# It is *highly* recommended to use something like cargo-hakari to avoid
|
|
|
|
# cache misses when building individual top-level-crates
|
|
|
|
cargoArtifacts = craneLib.buildDepsOnly commonArgs;
|
2024-03-15 09:55:00 +01:00
|
|
|
|
2024-09-05 07:32:31 +02:00
|
|
|
individualCrateArgs = commonArgs // {
|
|
|
|
inherit cargoArtifacts;
|
|
|
|
inherit (craneLib.crateNameFromCargoToml { inherit src; }) version;
|
|
|
|
# NB: we disable tests since we'll run them all via cargo-nextest
|
|
|
|
doCheck = false;
|
|
|
|
};
|
2024-03-15 09:55:00 +01:00
|
|
|
|
2024-09-05 07:32:31 +02:00
|
|
|
fileSetForCrate =
|
|
|
|
crate:
|
|
|
|
lib.fileset.toSource {
|
|
|
|
root = ./.;
|
|
|
|
fileset = lib.fileset.unions [
|
|
|
|
./Cargo.toml
|
|
|
|
./Cargo.lock
|
|
|
|
./crates/common
|
|
|
|
./crates/workspace-hack
|
|
|
|
crate
|
|
|
|
];
|
|
|
|
};
|
2024-03-15 09:55:00 +01:00
|
|
|
|
2024-09-05 07:32:31 +02:00
|
|
|
# Build the top-level crates of the workspace as individual derivations.
|
|
|
|
# This allows consumers to only depend on (and build) only what they need.
|
|
|
|
# Though it is possible to build the entire workspace as a single derivation,
|
|
|
|
# so this is left up to you on how to organize things
|
|
|
|
nix-weather = craneLib.buildPackage (
|
|
|
|
individualCrateArgs
|
|
|
|
// {
|
|
|
|
pname = "nix-weather";
|
|
|
|
cargoExtraArgs = "-p nix-weather";
|
|
|
|
src = fileSetForCrate ./crates/nix-weather;
|
|
|
|
MAN_OUT = "./man";
|
2024-03-15 09:55:00 +01:00
|
|
|
|
|
|
|
preInstall = ''
|
2024-09-05 07:32:31 +02:00
|
|
|
cd crates/nix-weather
|
2024-03-15 09:55:00 +01:00
|
|
|
installManPage man/nix-weather.1
|
|
|
|
installShellCompletion \
|
|
|
|
--fish man/nix-weather.fish \
|
|
|
|
--bash man/nix-weather.bash \
|
|
|
|
--zsh man/_nix-weather
|
|
|
|
mkdir -p $out
|
2024-09-05 07:32:31 +02:00
|
|
|
cd ../..
|
2024-03-15 09:55:00 +01:00
|
|
|
'';
|
|
|
|
|
2024-09-05 07:32:31 +02:00
|
|
|
meta = {
|
|
|
|
mainProgram = "nix-weather";
|
|
|
|
};
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
treefmtEval = treefmt-nix.lib.evalModule pkgs .config/treefmt.nix;
|
|
|
|
in
|
|
|
|
{
|
|
|
|
formatter = treefmtEval.config.build.wrapper;
|
|
|
|
|
|
|
|
checks = {
|
|
|
|
# Build the crates as part of `nix flake check` for convenience
|
|
|
|
inherit nix-weather;
|
|
|
|
|
|
|
|
# Run clippy (and deny all warnings) on the workspace 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.
|
|
|
|
cargo-workspace-clippy = craneLib.cargoClippy (
|
|
|
|
commonArgs
|
|
|
|
// {
|
|
|
|
inherit cargoArtifacts;
|
|
|
|
cargoClippyExtraArgs = "--all-targets -- --deny warnings";
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
cargo-workspace-doc = craneLib.cargoDoc (
|
|
|
|
commonArgs
|
|
|
|
// {
|
|
|
|
inherit cargoArtifacts;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
# Check formatting
|
|
|
|
cargo-workspace-fmt = craneLib.cargoFmt {
|
|
|
|
inherit src;
|
2024-03-15 09:55:00 +01:00
|
|
|
};
|
|
|
|
|
2024-09-05 07:32:31 +02:00
|
|
|
# Audit dependencies
|
|
|
|
cargo-workspace-audit = craneLib.cargoAudit {
|
|
|
|
inherit src advisory-db;
|
2024-03-15 09:55:00 +01:00
|
|
|
};
|
|
|
|
|
2024-09-05 07:32:31 +02:00
|
|
|
# Audit licenses
|
|
|
|
cargo-workspace-deny = craneLib.cargoDeny {
|
|
|
|
inherit src;
|
2024-03-15 09:55:00 +01:00
|
|
|
};
|
|
|
|
|
2024-09-05 07:32:31 +02:00
|
|
|
# Run tests with cargo-nextest
|
|
|
|
# Consider setting `doCheck = false` on other crate derivations
|
|
|
|
# if you do not want the tests to run twice
|
|
|
|
cargo-workspace-nextest = craneLib.cargoNextest (
|
|
|
|
commonArgs
|
|
|
|
// {
|
|
|
|
inherit cargoArtifacts;
|
|
|
|
partitions = 1;
|
|
|
|
partitionType = "count";
|
|
|
|
}
|
|
|
|
);
|
2024-03-15 09:55:00 +01:00
|
|
|
|
2024-09-05 07:32:31 +02:00
|
|
|
# Ensure that cargo-hakari is up to date
|
|
|
|
cargo-workspace-hakari = craneLib.mkCargoDerivation {
|
|
|
|
inherit src;
|
|
|
|
pname = "cargo-workspace-hakari";
|
|
|
|
cargoArtifacts = null;
|
|
|
|
doInstallCargoArtifacts = false;
|
|
|
|
|
|
|
|
buildPhaseCargoCommand = ''
|
|
|
|
cargo hakari generate --diff # workspace-hack Cargo.toml is up-to-date
|
|
|
|
cargo hakari manage-deps --dry-run # all workspace crates depend on workspace-hack
|
|
|
|
cargo hakari verify
|
|
|
|
'';
|
|
|
|
|
|
|
|
nativeBuildInputs = [
|
|
|
|
pkgs.cargo-hakari
|
|
|
|
];
|
|
|
|
};
|
|
|
|
pre-commit-check =
|
|
|
|
let
|
|
|
|
# some treefmt formatters are not supported in pre-commit-hooks we filter them out for now.
|
|
|
|
toFilter = [ "yamlfmt" ];
|
|
|
|
filterFn = n: _v: (!builtins.elem n toFilter);
|
|
|
|
treefmtFormatters = pkgs.lib.mapAttrs (_n: v: { inherit (v) enable; }) (
|
|
|
|
pkgs.lib.filterAttrs filterFn (import ./.config/treefmt.nix).programs
|
|
|
|
);
|
|
|
|
in
|
2024-03-15 09:55:00 +01:00
|
|
|
pre-commit-hooks.lib.${system}.run {
|
|
|
|
src = ./.;
|
2024-09-05 07:32:31 +02:00
|
|
|
hooks = treefmtFormatters // {
|
|
|
|
convco.enable = true; # not in treefmt
|
|
|
|
reuse = {
|
|
|
|
enable = true;
|
|
|
|
name = "reuse";
|
|
|
|
entry = with pkgs; "${pkgs.reuse}/bin/reuse lint";
|
|
|
|
pass_filenames = false;
|
2024-03-15 09:55:00 +01:00
|
|
|
};
|
2024-09-05 07:32:31 +02:00
|
|
|
};
|
2024-03-15 09:55:00 +01:00
|
|
|
};
|
|
|
|
formatting = treefmtEval.config.build.check self;
|
2024-09-05 07:32:31 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
packages =
|
|
|
|
{
|
|
|
|
inherit nix-weather;
|
|
|
|
default = nix-weather;
|
|
|
|
}
|
|
|
|
// lib.optionalAttrs (!pkgs.stdenv.isDarwin) {
|
|
|
|
cargo-workspace-llvm-coverage = craneLibLLvmTools.cargoLlvmCov (
|
|
|
|
commonArgs
|
|
|
|
// {
|
|
|
|
inherit cargoArtifacts;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
apps = {
|
|
|
|
nix-weather = flake-utils.lib.mkApp {
|
|
|
|
drv = nix-weather;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
# For `nix develop`:
|
|
|
|
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 = [
|
|
|
|
toolchain
|
|
|
|
pkgs.fd
|
|
|
|
pkgs.rustup
|
|
|
|
pkgs.cargo-hakari
|
|
|
|
pkgs.reuse
|
|
|
|
pkgs.just
|
|
|
|
lix-module.packages.${system}.default
|
|
|
|
];
|
|
|
|
|
|
|
|
inherit (self.checks.${system}.pre-commit-check) shellHook;
|
2024-03-15 09:55:00 +01:00
|
|
|
};
|
|
|
|
}
|
|
|
|
);
|
2024-09-05 07:32:31 +02:00
|
|
|
nixConfig = {
|
|
|
|
experimental-features = [
|
|
|
|
"nix-command"
|
|
|
|
"flakes"
|
|
|
|
"pipe-operator"
|
|
|
|
"repl-flake"
|
|
|
|
];
|
|
|
|
};
|
2024-03-15 09:55:00 +01:00
|
|
|
}
|
2024-09-05 07:32:31 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|