aboutsummaryrefslogtreecommitdiff
path: root/src/libstore/build/drv-output-substitution-goal.hh
blob: f33196665fd6033f92ed030bb14e3043d4769b31 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#pragma once
///@file

#include "notifying-counter.hh"
#include "store-api.hh"
#include "goal.hh"
#include "realisation.hh"
#include <future>

namespace nix {

class Worker;

/**
 * Substitution of a derivation output.
 * This is done in three steps:
 * 1. Fetch the output info from a substituter
 * 2. Substitute the corresponding output path
 * 3. Register the output info
 */
class DrvOutputSubstitutionGoal : public Goal {

    /**
     * The drv output we're trying to substitute
     */
    DrvOutput id;

    /**
     * The realisation corresponding to the given output id.
     * Will be filled once we can get it.
     */
    std::shared_ptr<const Realisation> outputInfo;

    /**
     * The remaining substituters.
     */
    std::list<ref<Store>> subs;

    /**
     * The current substituter.
     */
    std::shared_ptr<Store> sub;

    NotifyingCounter<uint64_t>::Bump maintainRunningSubstitutions;

    struct DownloadState
    {
        Pipe outPipe;
        std::future<std::shared_ptr<const Realisation>> result;
    };

    std::shared_ptr<DownloadState> downloadState;

    /**
     * Whether a substituter failed.
     */
    bool substituterFailed = false;

public:
    DrvOutputSubstitutionGoal(
        const DrvOutput & id,
        Worker & worker,
        bool isDependency,
        RepairFlag repair = NoRepair,
        std::optional<ContentAddress> ca = std::nullopt
    );

    typedef kj::Promise<Result<WorkResult>> (DrvOutputSubstitutionGoal::*GoalState)(bool inBuildSlot) noexcept;
    GoalState state;

    kj::Promise<Result<WorkResult>> init(bool inBuildSlot) noexcept;
    kj::Promise<Result<WorkResult>> tryNext(bool inBuildSlot) noexcept;
    kj::Promise<Result<WorkResult>> realisationFetched(bool inBuildSlot) noexcept;
    kj::Promise<Result<WorkResult>> outPathValid(bool inBuildSlot) noexcept;
    kj::Promise<Result<WorkResult>> finished() noexcept;

    Finished timedOut(Error && ex) override { abort(); };

    std::string key() override;

    kj::Promise<Result<WorkResult>> work(bool inBuildSlot) noexcept override;

    JobCategory jobCategory() const override {
        return JobCategory::Substitution;
    };
};

}