From 2ddbb18906c19d351274b68e182839f1801f4ce9 Mon Sep 17 00:00:00 2001 From: tv Date: Sat, 14 Nov 2026 04:18:14 +0000 Subject: krops: leave targets to populate, also in pure evaluation writeDeploy, writeCommand, and writeTest pass target strings to pkgs.populate as they are, so populate fills in what they leave out, and decides whether the target is local, when it runs. runShell runs populate shell, which decides that for running nixos-rebuild and writeCommand's commands, so rebuild's unbuffer for local targets with allocateTTY depends on $1, and runShell returns shell code, also for remote targets. Target attribute sets get mkTarget's defaults and whether they're local during evaluation, as before, unless that's pure: then mkTarget leaves the user and the host null, instead of reading /etc/hostname, which pure evaluation pretends doesn't exist, and pkgs.populate and populate shell leave them, and whether the target is local, to populate, which also refuses copying flakes to targets using sudo then. writeTest checks that its target is local during evaluation, unless that's pure, and with populate shell --local-only before populating. writeDeploy needs a target's host for a separate buildTarget in pure evaluation. pkgs/krops/target.nix has what pkgs.populate and pkgs.krops need of targets. pkgs.populate's derivations stay the same, for strings and attribute sets. The deploy scenarios get target strings too, for the local and the remote target, and so does the allocateTTY scenario. --- lib/with.nix | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/with.nix b/lib/with.nix index 7305b7d..b3ff7fa 100644 --- a/lib/with.nix +++ b/lib/with.nix @@ -5,6 +5,10 @@ let populate.lib = import ../pkgs/populate/lib { inherit lib; }; + + # Whether evaluation is pure, which hides the environment and files + # outside the store. + pure = !(builtins ? currentSystem); in rec { @@ -30,19 +34,26 @@ rec { firstWord = s: lib.head (lib.match "^([^[:space:]]*).*" s); + # Whether target is the machine krops runs on, as the user running it. + # Pure evaluation can't tell, so krops leaves that to populate then. isLocalTarget = let origin = mkTarget ""; in target: target.user == origin.user && lib.elem target.host [origin.host "localhost"]; + # A target as krops' functions take it: an attribute set, with the parts + # the string s, [USER@][HOST][:PORT][PATH], leaves out defaulting to + # LOGNAME, the machine's name, and /var/src. Pure evaluation can't tell + # the first two, so they're null then, which populate fills in when it + # runs. s can also be an attribute set, which the defaults fill up. mkTarget = s: let parse = lib.match "(([^@]*)@)?(([^:/]+))?(:([^/]+))?(/.*)?" s; elemAt' = xs: i: if lib.length xs > i then lib.elemAt xs i else null; filterNull = lib.filterAttrs (n: v: v != null); in { user = lib.maybeEnv "LOGNAME" null; - host = lib.maybeEnv "HOSTNAME" (maybeHostName "localhost"); + host = if pure then null else lib.maybeEnv "HOSTNAME" (maybeHostName "localhost"); port = null; path = "/var/src"; sudo = false; -- cgit v1.3.1