From 8bbee566fc0f3ca29d02c4942d31ac2547931117 Mon Sep 17 00:00:00 2001 From: lassulus Date: Sat, 5 Jul 2025 19:47:35 +0200 Subject: [PATCH 1/3] clan_cli run: add trace runOption to disable verbose traces in debug mode --- pkgs/clan-cli/clan_lib/cmd/__init__.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pkgs/clan-cli/clan_lib/cmd/__init__.py b/pkgs/clan-cli/clan_lib/cmd/__init__.py index d31ec65d1..17dc5faff 100644 --- a/pkgs/clan-cli/clan_lib/cmd/__init__.py +++ b/pkgs/clan-cli/clan_lib/cmd/__init__.py @@ -290,6 +290,7 @@ class RunOpts: # Ask for sudo password in a graphical way. # This is needed for GUI applications graphical_perm: bool = False + trace: bool = True def cmd_with_root(cmd: list[str], graphical: bool = False) -> list[str]: @@ -344,7 +345,7 @@ def run( # Use our sudo ask proxy here as well options.needs_user_terminal = True - if cmdlog.isEnabledFor(logging.DEBUG): + if cmdlog.isEnabledFor(logging.DEBUG) and options.trace: if options.input and isinstance(options.input, bytes): if any( not ch.isprintable() for ch in options.input.decode("ascii", "replace") From af33f122b08dce93723696f64448fc64f08cfc77 Mon Sep 17 00:00:00 2001 From: lassulus Date: Sun, 6 Jul 2025 00:48:26 +0200 Subject: [PATCH 2/3] clan_cli flake: remove apply from select, as it will break stuff in horrible ways Since apply changes the structure of the retuned value, the cache will be confused about the structure and in subsequent request will use this wrong structure. For example: we would use builtins.attrNames on inputs, the flake will forever think that inputs is a list of strings and will report errors whenever we try to fetch subkeys from it --- pkgs/clan-cli/clan_lib/flake/flake.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pkgs/clan-cli/clan_lib/flake/flake.py b/pkgs/clan-cli/clan_lib/flake/flake.py index 3a3b90310..529207860 100644 --- a/pkgs/clan-cli/clan_lib/flake/flake.py +++ b/pkgs/clan-cli/clan_lib/flake/flake.py @@ -621,7 +621,9 @@ class Flake: return self._is_local def get_input_names(self) -> list[str]: - return self.select("inputs", apply="builtins.attrNames") + log.debug("flake.get_input_names is deprecated and will be removed") + flakes = self.select("inputs.*._type") + return list(flakes.keys()) @property def path(self) -> Path: @@ -710,7 +712,6 @@ class Flake: def get_from_nix( self, selectors: list[str], - apply: str = "v: v", ) -> None: """ Retrieves specific attributes from a Nix flake using the provided selectors. @@ -772,7 +773,7 @@ class Flake: result = builtins.toJSON [ {" ".join( [ - f"(({apply}) (selectLib.applySelectors (builtins.fromJSON ''{attr}'') flake))" + f"(selectLib.applySelectors (builtins.fromJSON ''{attr}'') flake)" for attr in str_selectors ] )} @@ -840,7 +841,6 @@ class Flake: def select( self, selector: str, - apply: str = "v: v", ) -> Any: """ Selects a value from the cache based on the provided selector string. @@ -856,6 +856,6 @@ class Flake: if not self._cache.is_cached(selector): log.debug(f"Cache miss for {selector}") - self.get_from_nix([selector], apply=apply) + self.get_from_nix([selector]) value = self._cache.select(selector) return value From aaa27a0d0ec2950dda2dee8c52725a99437de348 Mon Sep 17 00:00:00 2001 From: lassulus Date: Sat, 5 Jul 2025 19:48:38 +0200 Subject: [PATCH 3/3] clan_cli: better select debug output --- pkgs/clan-cli/clan_lib/flake/flake.py | 31 +++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/pkgs/clan-cli/clan_lib/flake/flake.py b/pkgs/clan-cli/clan_lib/flake/flake.py index 529207860..2d82a8acb 100644 --- a/pkgs/clan-cli/clan_lib/flake/flake.py +++ b/pkgs/clan-cli/clan_lib/flake/flake.py @@ -730,7 +730,7 @@ class Flake: ClanError: If the number of outputs does not match the number of selectors. AssertionError: If the cache or flake cache path is not properly initialized. """ - from clan_lib.cmd import Log, RunOpts, run + from clan_lib.cmd import run, RunOpts, Log from clan_lib.dirs import select_source from clan_lib.nix import ( nix_build, @@ -796,11 +796,38 @@ class Flake: ]; }} """ + if len(selectors) > 1: + log.debug(f""" +selecting: {selectors} +to debug run: +nix repl --expr 'rec {{ + flake = builtins.getFlake "self.identifier"; + selectLib = (builtins.getFlake "path:{select_source()}?narHash={select_hash}").lib; + query = [ + {" ".join( + [ + f"(selectLib.select ''{selector}'' flake)" + for selector in selectors + ] + )} + ]; +}}' + """) # fmt: on + elif len(selectors) == 1: + log.debug(f""" +selecting: {selectors[0]} +to debug run: +nix repl --expr 'rec {{ + flake = builtins.getFlake "{self.identifier}"; + selectLib = (builtins.getFlake "path:{select_source()}?narHash={select_hash}").lib; + query = selectLib.select '"''{selectors[0]}''"' flake; +}}' + """) build_output = Path( run( - nix_build(["--expr", nix_code, *nix_options]), RunOpts(log=Log.NONE) + nix_build(["--expr", nix_code, *nix_options]), RunOpts(log=Log.NONE, trace=False), ).stdout.strip() )