Skip to content

Commit 30b2ae3

Browse files
committedMar 21, 2025
Move DerivationBuilder to its own file/header
The building logic is now free of the scheduling logic! (The interface between them is just what is in the new header. This makes it much easier to audit, and shrink over time.)
1 parent 1bf3b90 commit 30b2ae3

9 files changed

+145
-6830
lines changed
 

‎maintainers/flake-module.nix

+2
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,8 @@
284284
''^src/libstore/build/goal\.cc$''
285285
''^src/libstore/build/goal\.hh$''
286286
''^src/libstore/unix/build/hook-instance\.cc$''
287+
''^src/libstore/unix/build/derivation-builder\.cc$''
288+
''^src/libstore/unix/build/derivation-builder\.hh$''
287289
''^src/libstore/unix/build/local-derivation-goal\.cc$''
288290
''^src/libstore/unix/build/local-derivation-goal\.hh$''
289291
''^src/libstore/build/substitution-goal\.cc$''
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#pragma once
2+
/**
3+
* @file Misc type defitions for both local building and remote (RPC building)
4+
*/
5+
6+
#include "hash.hh"
7+
#include "path.hh"
8+
9+
namespace nix {
10+
11+
class Store;
12+
13+
/**
14+
* Unless we are repairing, we don't both to test validity and just assume it,
15+
* so the choices are `Absent` or `Valid`.
16+
*/
17+
enum struct PathStatus {
18+
Corrupt,
19+
Absent,
20+
Valid,
21+
};
22+
23+
struct InitialOutputStatus
24+
{
25+
StorePath path;
26+
PathStatus status;
27+
/**
28+
* Valid in the store, and additionally non-corrupt if we are repairing
29+
*/
30+
bool isValid() const
31+
{
32+
return status == PathStatus::Valid;
33+
}
34+
/**
35+
* Merely present, allowed to be corrupt
36+
*/
37+
bool isPresent() const
38+
{
39+
return status == PathStatus::Corrupt || status == PathStatus::Valid;
40+
}
41+
};
42+
43+
struct InitialOutput
44+
{
45+
bool wanted;
46+
Hash outputHash;
47+
std::optional<InitialOutputStatus> known;
48+
};
49+
50+
void runPostBuildHook(Store & store, Logger & logger, const StorePath & drvPath, const StorePathSet & outputPaths);
51+
52+
}

‎src/libstore/build/derivation-goal.cc

-14
Original file line numberDiff line numberDiff line change
@@ -5,31 +5,17 @@
55
#include "processes.hh"
66
#include "config-global.hh"
77
#include "worker.hh"
8-
#include "builtins.hh"
9-
#include "builtins/buildenv.hh"
10-
#include "references.hh"
11-
#include "finally.hh"
128
#include "util.hh"
13-
#include "archive.hh"
149
#include "compression.hh"
1510
#include "common-protocol.hh"
1611
#include "common-protocol-impl.hh"
17-
#include "topo-sort.hh"
18-
#include "callback.hh"
1912
#include "local-store.hh" // TODO remove, along with remaining downcasts
2013

21-
#include <regex>
22-
#include <queue>
23-
2414
#include <fstream>
2515
#include <sys/types.h>
2616
#include <fcntl.h>
2717
#include <unistd.h>
2818

29-
#ifndef _WIN32 // TODO abstract over proc exit status
30-
# include <sys/wait.h>
31-
#endif
32-
3319
#include <nlohmann/json.hpp>
3420

3521
#include "strings.hh"

‎src/libstore/build/derivation-goal.hh

+1-39
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@
33

44
#include "parsed-derivations.hh"
55
#include "derivation-options.hh"
6-
#ifndef _WIN32
7-
# include "user-lock.hh"
8-
#endif
6+
#include "derivation-building-misc.hh"
97
#include "outputs-spec.hh"
108
#include "store-api.hh"
119
#include "pathlocks.hh"
@@ -21,40 +19,6 @@ struct HookInstance;
2119

2220
typedef enum {rpAccept, rpDecline, rpPostpone} HookReply;
2321

24-
/**
25-
* Unless we are repairing, we don't both to test validity and just assume it,
26-
* so the choices are `Absent` or `Valid`.
27-
*/
28-
enum struct PathStatus {
29-
Corrupt,
30-
Absent,
31-
Valid,
32-
};
33-
34-
struct InitialOutputStatus {
35-
StorePath path;
36-
PathStatus status;
37-
/**
38-
* Valid in the store, and additionally non-corrupt if we are repairing
39-
*/
40-
bool isValid() const {
41-
return status == PathStatus::Valid;
42-
}
43-
/**
44-
* Merely present, allowed to be corrupt
45-
*/
46-
bool isPresent() const {
47-
return status == PathStatus::Corrupt
48-
|| status == PathStatus::Valid;
49-
}
50-
};
51-
52-
struct InitialOutput {
53-
bool wanted;
54-
Hash outputHash;
55-
std::optional<InitialOutputStatus> known;
56-
};
57-
5822
/** Used internally */
5923
void runPostBuildHook(
6024
Store & store,
@@ -307,6 +271,4 @@ struct DerivationGoal : public Goal
307271
};
308272
};
309273

310-
MakeError(NotDeterministic, BuildError);
311-
312274
}

‎src/libstore/meson.build

+1
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,7 @@ include_dirs = [
256256
headers = [config_h] + files(
257257
'binary-cache-store.hh',
258258
'build-result.hh',
259+
'build/derivation-building-misc.hh',
259260
'build/derivation-goal.hh',
260261
'build/drv-output-substitution-goal.hh',
261262
'build/goal.hh',

0 commit comments

Comments
 (0)
Failed to load comments.