diff options
| author | Ben Sima <ben@bsima.me> | 2025-11-15 10:06:18 -0500 |
|---|---|---|
| committer | Ben Sima <ben@bsima.me> | 2025-11-15 10:06:18 -0500 |
| commit | b3dd5f285365f59153a8f4549efa0607ccddf19d (patch) | |
| tree | 60f4fbe7a8d4e858f069f997546c2b3337a0002a /Omni/Log/Terminal.hs | |
| parent | 905c6aa06c00150f0c051ead776a64aee0b2212c (diff) | |
Fix NixOS integration: separate package building from OS builds
Problem: Calling bild.run inside NixOS configs triggered IFD during
OS evaluation. ANSI escape codes from bild broke JSON parsing in Nix
sandbox, causing build failures.
Root cause: bild.run uses IFD (Import From Derivation) which runs
bild --plan during Nix evaluation. When this happened inside NixOS
service definitions, it ran recursively and bild output ANSI codes
that corrupted the JSON analysis output.
Solution: Two-phase architecture + NO_COLOR support
1. Biz/Packages.nix: Pre-builds all packages outside NixOS context
2. Biz.nix: Accepts packages as function argument (default:
Packages.nix) 3. Omni/Bild.nix: Sets NO_COLOR=1 in analysis
derivation 4. Omni/Log/Terminal.hs: Respects NO_COLOR env var
5. Omni/Log/Terminal.hs: Skip getTerminalSize when NO_COLOR set
to avoid
escape code output
6. Omni/Log/Concurrent.hs: Skip line initialization without ANSI
support
Now NixOS builds succeed: - Package IFD happens once at top level -
No recursive builds during service evaluation - Clean JSON output
from bild --plan in Nix sandbox - NixOS configs reference pre-analyzed
packages
Changes: - Add Biz/Packages.nix - standalone package builder - Update
Biz.nix to accept packages argument - Update Biz/Dragons/Analysis.nix
to use Packages.nix - Remove Biz/Targets.nix (replaced by
Packages.nix) - Add NO_COLOR support throughout logging stack -
Fix ANSI.getTerminalSize outputting escape codes when NO_COLOR set
Amp-Thread-ID:
https://ampcode.com/threads/T-bc0f6fc7-46bf-4aa2-892e-dd62e7251d4b
Co-authored-by: Amp <amp@ampcode.com>
Diffstat (limited to 'Omni/Log/Terminal.hs')
| -rw-r--r-- | Omni/Log/Terminal.hs | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/Omni/Log/Terminal.hs b/Omni/Log/Terminal.hs index a78e544..0d2ca7a 100644 --- a/Omni/Log/Terminal.hs +++ b/Omni/Log/Terminal.hs @@ -33,16 +33,22 @@ detectTerminal :: IO TerminalInfo detectTerminal = do term <- Env.lookupEnv "TERM" area <- Env.lookupEnv "AREA" + noColor <- Env.lookupEnv "NO_COLOR" -- Check if we support ANSI - let supportsANSI = case (term, area) of - (Just "dumb", _) -> False - (_, Just "Live") -> False -- production logs - (Nothing, _) -> False + let supportsANSI = case (term, area, noColor) of + (_, _, Just _) -> False -- NO_COLOR set + (Just "dumb", _, _) -> False + (_, Just "Live", _) -> False -- production logs + (Nothing, _, _) -> False _ -> True -- Get terminal size, catching exceptions from stdin issues - mSize <- Exception.catch ANSI.getTerminalSize <| \(_ :: Exception.IOException) -> pure Nothing + -- When NO_COLOR is set or ANSI is not supported, skip terminal size detection + -- to avoid outputting escape codes + mSize <- case supportsANSI of + False -> pure Nothing -- Skip if no ANSI support + True -> Exception.catch ANSI.getTerminalSize <| \(_ :: Exception.IOException) -> pure Nothing let (width, height) = case mSize of Just (h, w) -> (w, h) Nothing -> (80, 24) -- sensible default |
