Merge pull request #215 from srid/debug-logging

More logging; document debugging
This commit is contained in:
Sridhar Ratnakumar 2024-01-11 05:23:07 -05:00 committed by GitHub
commit b3da9415e6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 48 additions and 4 deletions

View File

@ -4,7 +4,7 @@
<img src="./doc/logo.webp" width=100 />
There are [several ways](https://nixos.wiki/wiki/Haskell) to manage Haskell packages using Nix with varying degrees of integration. `haskell-flake` makes Haskell development, packaging and deployment with Nix flakes a lot [simpler](https://community.flake.parts/haskell-flake/start#under-the-hood) than other existing approaches. This project is set up as a modern [`flake-parts`](https://flake.parts/) module to integrate easily into other Nix projects and shell development environments in a lightweight and modular way.
There are [several ways](https://nixos.asia/en/haskell) to manage Haskell packages using [Nix](https://nixos.asia/en/nix) with varying degrees of integration. `haskell-flake` makes Haskell development, packaging and deployment with Nix flakes a lot [simpler](https://community.flake.parts/haskell-flake/start#under-the-hood) than other existing approaches. This project is set up as a modern [`flake-parts`](https://flake.parts/) module to integrate easily into other Nix projects and shell development environments in a lightweight and modular way.
To see more background information, guides and best practices, visit https://community.flake.parts/haskell-flake

39
doc/guide/debugging.md Normal file
View File

@ -0,0 +1,39 @@
---
slug: /haskell-flake/debugging
---
# Debugging logs
Enabling the `debug` option causes haskell-flake to print verbose logging of its activity. To enable it:
```nix
haskellProjects.default = {
debug = true; # Turn on verbose logging
projectRoot = ./.;
...
}
```
>[!tip] Timestamps in logs
> `moreutils` provides the `ts` command that you can pipe your nix command output to in order to get timestamps in the logs.
With debug option enabled, you can execute your `nix` commands piped through `ts` to get timestamps in the debug logs. The below is a sample output when building [haskell-multi-nix](https://github.com/srid/haskell-multi-nix/tree/debug):
```
$ nix build github:srid/haskell-multi-nix/debug#bar 2>&1 | ts '[%Y-%m-%d %H:%M:%S]'
[2024-01-11 15:33:32] trace: DEBUG[haskell-flake] [k0ad89r6pa70rly68ibff1jkw59bljgh-source#haskellProjects.default]: default.findPackagesInCabalProject = {"bar":"/nix/store/k0ad89r6pa70rly68ibff1jkw59bljgh-source/./bar","foo":"/nix/store/k0ad89r6pa70rly68ibff1jkw59bljgh-source/./foo"}
[2024-01-11 15:33:32] trace: DEBUG[haskell-flake] [k0ad89r6pa70rly68ibff1jkw59bljgh-source#haskellProjects.default]: defaults.packages = {"bar":{"imports":[{"_file":"/nix/store/n2nb5achv6p0bv3nvqw731mfr907d8ny-source/nix/modules/project/defaults.nix, via option perSystem.aarch64-darwin.haskellProjects.default.defaults.packages.bar","imports":[{"source":"/nix/store/k0ad89r6pa70rly68ibff1jkw59bljgh-source/./bar"}]}]},"foo":{"imports":[{"_file":"/nix/store/n2nb5achv6p0bv3nvqw731mfr907d8ny-source/nix/modules/project/defaults.nix, via option perSystem.aarch64-darwin.haskellProjects.default.defaults.packages.foo","imports":[{"source":"/nix/store/k0ad89r6pa70rly68ibff1jkw59bljgh-source/./foo"}]}]}}
[2024-01-11 15:33:32] trace: DEBUG[haskell-flake] [k0ad89r6pa70rly68ibff1jkw59bljgh-source#haskellProjects.default]: bar.getCabalExecutables = bar
[2024-01-11 15:33:32] trace: DEBUG[haskell-flake] [k0ad89r6pa70rly68ibff1jkw59bljgh-source#haskellProjects.default]: foo.getCabalExecutables =
[2024-01-11 15:33:32] trace: DEBUG[haskell-flake] [k0ad89r6pa70rly68ibff1jkw59bljgh-source#haskellProjects.default]: default.packages:apply {"bar":{"cabal":{"executables":["bar"]},"local":{"toCurrentProject":true,"toDefinedProject":true},"source":"/nix/store/k0ad89r6pa70rly68ibff1jkw59bljgh-source/./bar"},"foo":{"cabal":{"executables":[]},"local":{"toCurrentProject":true,"toDefinedProject":true},"source":"/nix/store/k0ad89r6pa70rly68ibff1jkw59bljgh-source/./foo"}}
[2024-01-11 15:33:34] trace: DEBUG[haskell-flake] [k0ad89r6pa70rly68ibff1jkw59bljgh-source#haskellProjects.default]: settings.bar {"haddock":false,"libraryProfiling":false}
[2024-01-11 15:33:34] trace: DEBUG[haskell-flake] [k0ad89r6pa70rly68ibff1jkw59bljgh-source#haskellProjects.default]: bar.callCabal2nix /nix/store/k0ad89r6pa70rly68ibff1jkw59bljgh-source/./bar
[2024-01-11 15:33:34] trace: DEBUG[haskell-flake] [k0ad89r6pa70rly68ibff1jkw59bljgh-source#haskellProjects.default]: bar.mkNewStorePath /nix/store/hr0a6v8wwwvw323clv9x28zknd5fqz84-source-bar
[2024-01-11 15:33:35] trace: DEBUG[haskell-flake] [k0ad89r6pa70rly68ibff1jkw59bljgh-source#haskellProjects.default]: bar.cabal2nixDeriver /nix/store/pxcqizj7mvmwflx7hxlq7ll5bdmcis2a-cabal2nix-bar
[2024-01-11 15:33:35] trace: DEBUG[haskell-flake] [k0ad89r6pa70rly68ibff1jkw59bljgh-source#haskellProjects.default]: settings.foo {"haddock":false,"libraryProfiling":false}
[2024-01-11 15:33:35] trace: DEBUG[haskell-flake] [k0ad89r6pa70rly68ibff1jkw59bljgh-source#haskellProjects.default]: foo.callCabal2nix /nix/store/k0ad89r6pa70rly68ibff1jkw59bljgh-source/./foo
[2024-01-11 15:33:35] trace: DEBUG[haskell-flake] [k0ad89r6pa70rly68ibff1jkw59bljgh-source#haskellProjects.default]: foo.mkNewStorePath /nix/store/bpybsny4gd5jnw0lvk5khpq7md6nwg5f-source-foo
[2024-01-11 15:33:35] trace: DEBUG[haskell-flake] [k0ad89r6pa70rly68ibff1jkw59bljgh-source#haskellProjects.default]: foo.cabal2nixDeriver /nix/store/i36x01zcdpm7c3m3fjjq1qa4slv61jpw-cabal2nix-foo
[2024-01-11 15:33:35] trace: DEBUG[haskell-flake] [k0ad89r6pa70rly68ibff1jkw59bljgh-source#haskellProjects.default]: foo.fromSdist /nix/store/qrsy0bm4khcs1hxy0rhb6m3g2bvi15sm-foo-0.1.0.0
[2024-01-11 15:33:35] trace: DEBUG[haskell-flake] [k0ad89r6pa70rly68ibff1jkw59bljgh-source#haskellProjects.default]: bar.fromSdist /nix/store/anyx51rm5gjdclafcz5is7jpqgfq2i4w-bar-0.1.0.0
```

View File

@ -6,6 +6,6 @@ slug: /haskell-flake
# Haskell development using `haskell-flake`
[haskell-flake](https://github.com/srid/haskell-flake) is a [flake-parts](https://flake.parts/) module to make Haskell development [simpler](/haskell-flake/start#under-the-hood) with Nix.
[haskell-flake](https://github.com/srid/haskell-flake) is a [flake-parts](https://flake.parts/) module to make Haskell development [simpler](/haskell-flake/start#under-the-hood) with [Nix](https://nixos.asia/en/nix).
To get started, see [Getting Started](/haskell-flake/start).

View File

@ -1,5 +1,5 @@
# A module representing the default values used internally by haskell-flake.
{ lib, pkgs, config, ... }:
{ name, lib, pkgs, config, ... }:
let
inherit (lib)
mkOption
@ -46,6 +46,7 @@ in
};
localPackages = lib.pipe config.projectRoot [
haskell-parsers.findPackagesInCabalProject
(x: config.log.traceDebug "${name}.findPackagesInCabalProject = ${builtins.toJSON x}" x)
(lib.mapAttrs (_: path: {
# The rest of the module options are not defined, because we'll use
# the submodule defaults.

View File

@ -42,7 +42,11 @@ in
};
in
if lib.types.path.check config.source
then haskell-parsers.getCabalExecutables config.source
then
lib.pipe config.source [
haskell-parsers.getCabalExecutables
(x: project.config.log.traceDebug "${name}.getCabalExecutables = ${builtins.toString x}" x)
]
else null; # cfg.source is Hackage version; nothing to do.
};