From 0ff35842087b3b16e7e41caa6f794151b47f304a Mon Sep 17 00:00:00 2001 From: seth Date: Fri, 8 Nov 2024 20:47:25 -0500 Subject: Clean up Nix Flake and packaging (#24) * refactor(nix): split package.nix from flake.nix * chore(nix): split checks; add more * ci: run all nix checks * ci: build in debug mode * chore(nix): use versionCheckHook this makes sure the version test is always run, and on the right package * chore(nix): nix-filter -> lib.fileset * feat(nix): support stable nix * ci: fix clippy check --- flake.nix | 156 +++++++++++++++++--------------------------------------------- 1 file changed, 42 insertions(+), 114 deletions(-) (limited to 'flake.nix') diff --git a/flake.nix b/flake.nix index 040f5a3..33193cf 100644 --- a/flake.nix +++ b/flake.nix @@ -1,16 +1,12 @@ { description = "Check the forecast for today's Nix builds"; - inputs = { - nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; - nix-filter.url = "github:numtide/nix-filter"; - }; + inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; outputs = { self, nixpkgs, - nix-filter, }: let inherit (nixpkgs) lib; @@ -36,16 +32,24 @@ let pkgs = nixpkgsFor.${system}; packages = self.packages.${system}; + + mkCheck = + name: deps: script: + pkgs.runCommand name { nativeBuildInputs = deps; } '' + ${script} + touch $out + ''; in lib.optionalAttrs (lib.elem system supportedSystems) { - version-test = packages.nix-forecast.tests.version; - - clippy = packages.nix-forecast.overrideAttrs (oldAttrs: { + clippy = packages.nix-forecast.overrideAttrs { pname = "check-clippy"; - nativeBuildInputs = oldAttrs.nativeBuildInputs ++ [ + nativeBuildInputs = [ + pkgs.cargo pkgs.clippy pkgs.clippy-sarif + pkgs.rustPlatform.cargoSetupHook + pkgs.rustc pkgs.sarif-fmt ]; @@ -57,36 +61,32 @@ --tests \ --message-format=json \ | clippy-sarif | tee $out | sarif-fmt + runHook postBuild ''; dontInstall = true; doCheck = false; + doInstallCheck = 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 - ''; + }; + + rustfmt = mkCheck "check-cargo-fmt" [ + pkgs.cargo + pkgs.rustfmt + ] "cd ${self} && cargo fmt -- --check"; + + actionlint = mkCheck "check-actionlint" [ + pkgs.actionlint + ] "actionlint ${self}/.github/workflows/*"; + + deadnix = mkCheck "check-deadnix" [ pkgs.deadnix ] "deadnix --fail ${self}"; + + nixfmt = mkCheck "check-nixfmt" [ pkgs.nixfmt-rfc-style ] "nixfmt --check ${self}"; + + statix = mkCheck "check-statix" [ pkgs.statix ] "statix check ${self}"; } ); @@ -120,96 +120,24 @@ 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} - ) - ); + legacyPackages = forAllSystems (system: { + nix-forecast-debug = self.packages.${system}.nix-forecast.overrideAttrs ( + finalAttrs: _: { + cargoBuildType = "debug"; + cargoCheckType = finalAttrs.cargoBuildType; + } + ); + }); packages = forAllSystems ( system: let pkgs = nixpkgsFor.${system}; - nixForecastPackages = lib.makeScope pkgs.newScope (final: self.overlays.default final pkgs); + pkgs' = import ./default.nix { inherit pkgs; }; in - { - inherit (nixForecastPackages) nix-forecast; - default = self.packages.${system}.nix-forecast; - } + pkgs' // { default = pkgs'.nix-forecast; } ); - overlays.default = final: _: { - nix-forecast = final.callPackage ( - { - lib, - stdenv, - rustPlatform, - darwin, - installShellFiles, - makeBinaryWrapper, - nix, - nix-forecast, - testers, - }: - - rustPlatform.buildRustPackage rec { - pname = "nix-forecast"; - inherit (passthru.cargoTOML.package) version; - - src = nix-filter { - root = self; - include = [ - ./Cargo.toml - ./Cargo.lock - ./build.rs - "src" - ]; - }; - - cargoLock.lockFile = ./Cargo.lock; - - nativeBuildInputs = [ - installShellFiles - makeBinaryWrapper - ]; - - buildInputs = lib.optionals stdenv.hostPlatform.isDarwin [ - darwin.apple_sdk.frameworks.CoreFoundation - darwin.apple_sdk.frameworks.SystemConfiguration - darwin.libiconv - ]; - - 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"; - }; - } - ) { }; - }; + overlays.default = final: prev: import ./overlay.nix final prev; }; } -- cgit v1.2.3