Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build logs are missing when using nixUnstable #261

Closed
roberth opened this issue Jan 3, 2021 · 1 comment
Closed

Build logs are missing when using nixUnstable #261

roberth opened this issue Jan 3, 2021 · 1 comment
Labels
bug Something isn't working workaround or fix available

Comments

@roberth
Copy link
Member

roberth commented Jan 3, 2021

Description

No build logs appear in the dashboard, except perhaps some lines about substitution from Nix itself.

To Reproduce

Deploy an agent system with

nix.package = pkgs.nixUnstable;
services.hercules-ci-agent.enable = true;
# etcetera

Solution

Soon: update Nixpkgs. For now:

Apply the following configuration to the system:

NixOS configuration.nix or nix-darwin configuration:

  nixpkgs.overlays = [
    (final: prev: {
      nixUnstable = prev.nixUnstable.overrideAttrs (o: {
        patches = (o.patches or []) ++ [
          # Fix #4234, send build logs to Nix 2.3 / Hercules CI 0.8
          # https://github.com/NixOS/nix/pull/4418
          ./nix-issue-4234-build-output-for-nix-2.3.diff
        ];
      });

      # Pick up our overrides (Nixpkgs uses the same definition
      # instead of a reference to the final nixUnstable attribute)
      nixFlakes = final.nixUnstable;
    })
  ];

Add to the same directory the file nix-issue-4234-build-output-for-nix-2.3.diff:

commit aae705f9fc6f118315bf6d2bb49c98e2558fa190
Author: Robert Hensing <[email protected]>
Date:   Sat Jan 2 19:27:34 2021 +0100

    daemon.cc: Duplicate build output as general logs for Nix 2.3
    
    The conditional on clientVersion isn't accurate for a certain
    range of master commits, but those are unsupported anyway.
    
    It's not accurate for repeated builds either, because that
    would complicate the code for too little gain.

diff --git a/src/libstore/daemon.cc b/src/libstore/daemon.cc
index ba5788b64..14e5b1b9b 100644
--- a/src/libstore/daemon.cc
+++ b/src/libstore/daemon.cc
@@ -142,6 +142,14 @@ struct TunnelLogger : public Logger
 
     void result(ActivityId act, ResultType type, const Fields & fields) override
     {
+        if (GET_PROTOCOL_MINOR(clientVersion) < 22 && type == resBuildLogLine && settings.verboseBuild) {
+            // Nix < 2.4 expects build logs to be logged as general logs at lvlError.
+            // We probably shouldn't do this for repeated builds, but that's not
+            // something we can know here without complicating the implementation
+            // unnecessarily.
+            auto lastLine = fields[0].s;
+            log(lvlError, lastLine);
+        }
         if (GET_PROTOCOL_MINOR(clientVersion) < 20) return;
         StringSink buf;
         buf << STDERR_RESULT << act << type << fields;

Platform / Version

Hercules CI Agent: all versions
Nix: nixUnstable / master between NixOS/nix#3073 and NixOS/nix#4418

@roberth
Copy link
Member Author

roberth commented Jan 21, 2022

Versions >= 0.8.4 build against Nix 2.4 by default, with the possible exception of some Nixpkgs versions. This means that the Nix client version has caught up with the NIx daemon version and it won't exhibit this problem anymore.

@roberth roberth closed this as completed Jan 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working workaround or fix available
Projects
None yet
Development

No branches or pull requests

2 participants
@roberth and others