Skip to content

Commit 845d9af

Browse files
committed
fix: attribute builds to remote store for ssh-ng builds
When using remote stores via --store "ssh-ng://...", Nix reports builds with empty host field in JSON output. Previously this was treated as localhost. Now we detect the remote store from upload activities and use that host for builds reporting empty host. :house: Remote-Dev: homespace
1 parent 7f35aa1 commit 845d9af

2 files changed

Lines changed: 15 additions & 3 deletions

File tree

lib/NOM/State.hs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,10 @@ data NOMState = MkNOMState
262262
, evaluationState :: EvalInfo
263263
, successTokens :: Int
264264
, buildsActivity :: Strict.Maybe ActivityId
265+
, remoteStore :: Strict.Maybe (Host WithContext)
266+
{- ^ Detected remote store from upload activities. When builds report empty
267+
host but we're uploading to a remote store, builds are happening there.
268+
-}
265269
}
266270
deriving stock (Show, Eq, Ord)
267271

@@ -291,6 +295,7 @@ initalStateFromBuildPlatform platform = do
291295
MkEvalInfo{count = 0, at = 0, lastFileName = Strict.Nothing}
292296
0
293297
Strict.Nothing
298+
Strict.Nothing
294299

295300
instance Semigroup DependencySummary where
296301
(MkDependencySummary ls1 lm2 lm3 lm4 ls5 lm6 lm7 lm8 lm9) <> (MkDependencySummary rs1 rm2 rm3 rm4 rs5 rm6 rm7 rm8 rm9) = MkDependencySummary (ls1 <> rs1) (lm2 <> rm2) (lm3 <> rm3) (lm4 <> rm4) (ls5 <> rs5) (lm6 <> rm6) (lm7 <> rm7) (lm8 <> rm8) (lm9 <> rm9)

lib/NOM/Update.hs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,8 @@ processJsonMessage = \case
263263
now <- getNow
264264
pathId <- getStorePathId path
265265
uploading to pathId now (Just id')
266+
-- Track remote store for builds that report empty host
267+
when (to /= Localhost) $ assign' #remoteStore (Strict.Just to)
266268
JSON.Unknown | Text.isPrefixOf "querying info" startAction.text -> set_interesting
267269
JSON.Builds -> do
268270
ba <- use #buildsActivity
@@ -486,15 +488,20 @@ uploaded host pathId end =
486488

487489
building :: Host WithContext -> Derivation -> Double -> Maybe ActivityId -> ProcessingT m ()
488490
building host drvName now activityId = do
491+
-- When host is Localhost but we have a known remote store, use that instead.
492+
-- This happens with ssh-ng builds where Nix reports empty host.
493+
effectiveHost <- case host of
494+
Localhost -> Strict.maybe Localhost id <$> use #remoteStore
495+
_ -> pure host
489496
reportName <- getReportName <$> lookupDerivationInfos drvName
490-
lastNeeded <- (median <=< Map.lookup (forgetProto host, reportName)) . (.buildReports) <$> get
497+
lastNeeded <- (median <=< Map.lookup (forgetProto effectiveHost, reportName)) . (.buildReports) <$> get
491498
drvId <- lookupDerivation drvName
492499
updateDerivationState drvId
493500
$ Building
494501
. \case
495-
Building bi -> bi & #activityId .~ Strict.toStrict activityId -- This happens with ssh-ng. After we already registered this build as started we get a second activity start event. No frome the remote host. Sadly we can not see whether a message is from the local or the remote daemon.
502+
Building bi -> bi & #activityId .~ Strict.toStrict activityId -- This happens with ssh-ng. After we already registered this build as started we get a second activity start event. Now from the remote host. Sadly we can not see whether a message is from the local or the remote daemon.
496503
-- It would probably be better to only mark the build running on the second start message, but that probably does not work with all remote build protocols other than ssh-ng.
497-
_ -> MkBuildInfo now host (Strict.toStrict lastNeeded) (Strict.toStrict activityId) ()
504+
_ -> MkBuildInfo now effectiveHost (Strict.toStrict lastNeeded) (Strict.toStrict activityId) ()
498505

499506
median :: Map a Int -> Maybe Int
500507
median xs = case drop ((len - 1) `div` 2) $ sort $ toList xs of

0 commit comments

Comments
 (0)