From 6e3f2fba3f2bafe562db86b19a60fcf764ac3e96 Mon Sep 17 00:00:00 2001 From: Sridhar Ratnakumar Date: Wed, 26 Apr 2023 17:40:32 -0400 Subject: [PATCH] Add a 'debug' option to log drv hashes at all stages --- CHANGELOG.md | 1 + nix/build-haskell-package.nix | 9 ++++++--- nix/flake-module.nix | 9 +++++++++ nix/haskell-project.nix | 5 ++++- nix/logging.nix | 11 +++++++++++ 5 files changed, 31 insertions(+), 4 deletions(-) create mode 100644 nix/logging.nix diff --git a/CHANGELOG.md b/CHANGELOG.md index 12ae355..298d5c9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ - #143: Changed `autoWire` to be an enum type, for granular controlling of which outputs to autowire. - #137: Expose cabal executables as flake apps. Add a corresponding `outputs.apps` option, while the `outputs.localPackages` option is renamed to `outputs.packages` (it now contains package metadata, including packages and its executables). - #148: Remove automatic hpack->cabal generation. Use `pre-commit-hooks.nix` instead. +- #149: Fix unnecessary re-runs of cabal2nix evaluation. Add a `debug` option to enable produce verbose diagnostic messages. ## 0.2.0 (Mar 13, 2023) diff --git a/nix/build-haskell-package.nix b/nix/build-haskell-package.nix index c287eda..680e79d 100644 --- a/nix/build-haskell-package.nix +++ b/nix/build-haskell-package.nix @@ -1,9 +1,11 @@ # Like callCabal2nix, but does more: # - Source filtering (to prevent parent content changes causing rebuilds) # - Always build from cabal's sdist for release-worthiness -{ pkgs, lib, self, ... }: +{ pkgs, lib, self, debug, ... }: let + log = import ./logging.nix { inherit lib debug; }; + fromSdist = self.buildFromCabalSdist or (builtins.trace "Your version of Nixpkgs does not support hs.buildFromCabalSdist yet." (pkg: pkg)); mkNewStorePath = name: src: @@ -23,12 +25,13 @@ lib.pipe pkgCfg.root [ # Avoid rebuilding because of changes in parent directories (mkNewStorePath "source-${name}") - - (x: builtins.trace x.outPath x) + (log.traceDebug "${name}.mkNewStorePath" (x: x.outPath)) (root: self.callCabal2nix name root { }) + (log.traceDebug "${name}.cabal2nixDeriver" (x: x.cabal2nixDeriver.outPath)) # Make sure all files we use are included in the sdist, as a check # for release-worthiness. fromSdist + (log.traceDebug "${name}.fromSdist" (x: x.outPath)) ] diff --git a/nix/flake-module.nix b/nix/flake-module.nix index 4c2056e..9b9f051 100644 --- a/nix/flake-module.nix +++ b/nix/flake-module.nix @@ -201,6 +201,15 @@ in default = self; defaultText = "Top-level directory of the flake"; }; + debug = mkOption { + type = types.bool; + default = false; + description = '' + Whether to enable verbose trace output from haskell-flake. + + Useful for debugging. + ''; + }; basePackages = mkOption { type = types.attrsOf raw; description = '' diff --git a/nix/haskell-project.nix b/nix/haskell-project.nix index b0f7be6..e8f00ec 100644 --- a/nix/haskell-project.nix +++ b/nix/haskell-project.nix @@ -35,7 +35,10 @@ in localPackagesOverlay = self: _: let - build-haskell-package = import ./build-haskell-package.nix { inherit pkgs lib self; }; + build-haskell-package = import ./build-haskell-package.nix { + inherit pkgs lib self; + inherit (config) debug; + }; in lib.mapAttrs build-haskell-package config.packages; diff --git a/nix/logging.nix b/nix/logging.nix new file mode 100644 index 0000000..349644f --- /dev/null +++ b/nix/logging.nix @@ -0,0 +1,11 @@ +{ lib, debug, ... }: + +{ + traceDebug = k: f: + if debug then + (x: lib.pipe x [ + (builtins.trace ("DEBUG[haskell-flake]: " + k + " " + f x)) + ]) + else + (x: x); +}