From fa3103ac82638fdf28625a01992dd763c9dec99f Mon Sep 17 00:00:00 2001 From: Puck Meerburg Date: Fri, 4 Oct 2024 16:39:23 +0000 Subject: [PATCH] (zilch nixpkgs): print stderr through (current-error-port) This fixes the nix-instantiate warning/etc leaking through the CLI. --- core/src/nixpkgs.sld | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/core/src/nixpkgs.sld b/core/src/nixpkgs.sld index dcf8ba6..0b437c0 100644 --- a/core/src/nixpkgs.sld +++ b/core/src/nixpkgs.sld @@ -2,12 +2,22 @@ (import (scheme base) (zilch magic) (zilch nix drv) (zilch nix hash) + (srfi 18) (chicken process)) (export nix-prefetch-url nixpkgs) (begin + (define (run-stderr-thread prefix port) + (define line (read-line port)) + (if (eof-object? line) + (close-port port) + (begin + (write-string (string-append prefix "> " line "\n") (current-error-port)) + (run-stderr-thread prefix port)))) + (define (read-from-nixpkgs path) - (define-values (stdout stdin pid) (process "nix-instantiate" `("--argstr" "path" ,path "-E" "{path}: let nixpkgs = import {}; in nixpkgs.${path}.out"))) + (define-values (stdout stdin pid stderr) (process* "nix-instantiate" `("--argstr" "path" ,path "-E" "{path}: let nixpkgs = import {}; in nixpkgs.${path}.out"))) + (define thread (thread-start! (make-thread (lambda () (run-stderr-thread (string-append "nixpkgs." path) stderr)) "read-from-nixpkgs stderr passthrough"))) (close-port stdin) (define drvpath (read-line stdout)) (define-values (_ _ _) (process-wait pid #t)) @@ -16,7 +26,8 @@ ;; Returns the hash (as bytevector) of prefetching the specified URL. (define (nix-prefetch-url name url) - (define-values (stdout stdin pid) (process "nix-prefetch-url" `("--name" ,name "--" ,url))) + (define-values (stdout stdin pid stderr) (process* "nix-prefetch-url" `("--name" ,name "--" ,url))) + (define thread (thread-start! (make-thread (lambda () (run-stderr-thread (string-append "nix-prefetch-url " url) stderr)) "nix-prefetch-url stderr passthrough"))) (close-port stdin) (define hash (read-line stdout)) (define-values (_ _ _) (process-wait pid #t))