summaryrefslogtreecommitdiff
path: root/flake.nix
diff options
context:
space:
mode:
authorseth <[email protected]>2024-09-08 23:39:48 -0400
committerseth <[email protected]>2024-09-13 17:03:00 -0400
commitcc183fccca73df619c78dd0ca2567ac547c56ad2 (patch)
treea06a87049cd90e877e626b8ff31e27a373df8f39 /flake.nix
feat: initial commit
Diffstat (limited to 'flake.nix')
-rw-r--r--flake.nix213
1 files changed, 213 insertions, 0 deletions
diff --git a/flake.nix b/flake.nix
new file mode 100644
index 0000000..b8d9d24
--- /dev/null
+++ b/flake.nix
@@ -0,0 +1,213 @@
+{
+ description = "Check the forecast for today's Nix builds";
+
+ inputs = {
+ nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
+ nix-filter.url = "github:numtide/nix-filter";
+ };
+
+ outputs =
+ {
+ self,
+ nixpkgs,
+ nix-filter,
+ }:
+ let
+ inherit (nixpkgs) lib;
+
+ # We want to generate outputs for as many systems as possible,
+ # even if we don't officially support or test for them
+ allSystems = lib.systems.flakeExposed;
+
+ # These are the systems we do officially support and test, though
+ supportedSystems = [
+ "x86_64-linux"
+ "aarch64-linux"
+ "x86_64-darwin"
+ "aarch64-darwin"
+ ];
+
+ forAllSystems = lib.genAttrs allSystems;
+ nixpkgsFor = forAllSystems (system: nixpkgs.legacyPackages.${system});
+ in
+ {
+ checks = forAllSystems (
+ system:
+ let
+ pkgs = nixpkgsFor.${system};
+ packages = self.packages.${system};
+ in
+ lib.optionalAttrs (lib.elem system supportedSystems) {
+ version-test = packages.nix-forecast.tests.version;
+
+ clippy = packages.nix-forecast.overrideAttrs (oldAttrs: {
+ pname = "check-clippy";
+
+ nativeBuildInputs = oldAttrs.nativeBuildInputs ++ [
+ pkgs.clippy
+ pkgs.clippy-sarif
+ pkgs.sarif-fmt
+ ];
+
+ buildPhase = ''
+ runHook preBuild
+ cargo clippy \
+ --all-features \
+ --all-targets \
+ --tests \
+ --message-format=json \
+ | clippy-sarif | tee $out | sarif-fmt
+ '';
+
+ dontInstall = true;
+ doCheck = false;
+ dontFixup = true;
+
+ passthru = { };
+ meta = { };
+ });
+
+ formatting =
+ pkgs.runCommand "check-formatting"
+ {
+ nativeBuildInputs = [
+ pkgs.cargo
+ pkgs.nixfmt-rfc-style
+ pkgs.rustfmt
+ ];
+ }
+ ''
+ cd ${self}
+
+ echo "Running cargo fmt"
+ cargo fmt -- --check
+
+ echo "Running nixfmt..."
+ nixfmt --check .
+
+ touch $out
+ '';
+ }
+ );
+
+ devShells = forAllSystems (
+ system:
+ let
+ pkgs = nixpkgsFor.${system};
+ in
+ lib.optionalAttrs (lib.elem system supportedSystems) {
+ default = pkgs.mkShell {
+ packages = [
+ # Rust tools
+ pkgs.clippy
+ pkgs.rust-analyzer
+ pkgs.rustfmt
+
+ # Nix tools
+ self.formatter.${system}
+ pkgs.nil
+ pkgs.statix
+ ];
+
+ env = {
+ RUST_SRC_PATH = toString pkgs.rustPlatform.rustLibSrc;
+ };
+
+ inputsFrom = [ self.packages.${system}.nix-forecast ];
+ };
+ }
+ );
+
+ formatter = forAllSystems (system: nixpkgsFor.${system}.nixfmt-rfc-style);
+
+ # for CI
+ legacyPackages = forAllSystems (
+ system:
+ lib.optionalAttrs (lib.elem system supportedSystems) (
+ lib.mapAttrs' (name: lib.nameValuePair "check-${name}") self.checks.${system}
+ )
+ );
+
+ packages = forAllSystems (
+ system:
+ let
+ pkgs = nixpkgsFor.${system};
+ nixForecastPackages = lib.makeScope pkgs.newScope (final: self.overlays.default final pkgs);
+
+ isCompatible = lib.meta.availableOn pkgs.stdenv.hostPlatform;
+ filteredPackages = lib.filterAttrs (
+ _: deriv: isCompatible deriv && lib.isDerivation deriv
+ ) nixForecastPackages;
+ in
+ filteredPackages
+ // {
+ default = filteredPackages.nix-forecast or pkgs.emptyFile;
+ }
+ );
+
+ overlays.default = final: _: {
+ nix-forecast = final.callPackage (
+ {
+ lib,
+ stdenv,
+ rustPlatform,
+ installShellFiles,
+ makeBinaryWrapper,
+ nix,
+ nix-forecast,
+ testers,
+ }:
+
+ rustPlatform.buildRustPackage rec {
+ pname = "nix-forecast";
+ inherit (passthru.cargoTOML.package) version;
+
+ cargoLock.lockFile = ./Cargo.lock;
+
+ src = nix-filter {
+ root = self;
+ include = [
+ ./Cargo.toml
+ ./Cargo.lock
+ ./build.rs
+ "src"
+ ];
+ };
+
+ nativeBuildInputs = [
+ installShellFiles
+ makeBinaryWrapper
+ ];
+
+ postInstall = ''
+ wrapProgram $out/bin/nix-forecast --suffix PATH : "${lib.makeBinPath [ nix ]}"
+
+ installShellCompletion --cmd nix-forecast \
+ --bash completions/nix-forecast.bash \
+ --fish completions/nix-forecast.fish \
+ --zsh completions/_nix-forecast
+ '';
+
+ env = {
+ COMPLETION_DIR = "completions";
+ };
+
+ passthru = {
+ cargoTOML = lib.importTOML ./Cargo.toml;
+
+ tests.version = testers.testVersion { package = nix-forecast; };
+ };
+
+ meta = {
+ description = "Check the forecast for today's Nix builds";
+ homepage = "https://github.com/getchoo/nix-forecast";
+ changelog = "https://github.com/getchoo/nix-forecast/releases/tag/${version}";
+ license = lib.licenses.mpl20;
+ maintainers = with lib.maintainers; [ getchoo ];
+ mainProgram = "nix-forecast";
+ };
+ }
+ ) { };
+ };
+ };
+}