(zilch nixpkgs): print stderr through (current-error-port)

This fixes the nix-instantiate warning/etc leaking through the CLI.
This commit is contained in:
puck 2024-10-04 16:39:23 +00:00
parent e86317583d
commit fa3103ac82

View file

@ -2,12 +2,22 @@
(import (import
(scheme base) (scheme base)
(zilch magic) (zilch nix drv) (zilch nix hash) (zilch magic) (zilch nix drv) (zilch nix hash)
(srfi 18)
(chicken process)) (chicken process))
(export nix-prefetch-url nixpkgs) (export nix-prefetch-url nixpkgs)
(begin (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 (read-from-nixpkgs path)
(define-values (stdout stdin pid) (process "nix-instantiate" `("--argstr" "path" ,path "-E" "{path}: let nixpkgs = import <nixpkgs> {}; in nixpkgs.${path}.out"))) (define-values (stdout stdin pid stderr) (process* "nix-instantiate" `("--argstr" "path" ,path "-E" "{path}: let nixpkgs = import <nixpkgs> {}; 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) (close-port stdin)
(define drvpath (read-line stdout)) (define drvpath (read-line stdout))
(define-values (_ _ _) (process-wait pid #t)) (define-values (_ _ _) (process-wait pid #t))
@ -16,7 +26,8 @@
;; Returns the hash (as bytevector) of prefetching the specified URL. ;; Returns the hash (as bytevector) of prefetching the specified URL.
(define (nix-prefetch-url name 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) (close-port stdin)
(define hash (read-line stdout)) (define hash (read-line stdout))
(define-values (_ _ _) (process-wait pid #t)) (define-values (_ _ _) (process-wait pid #t))