aboutsummaryrefslogtreecommitdiff
path: root/src/libexpr/flake/flake.hh
blob: 107498c1bf858a24dde13b7c6ed9fde27e7d51aa (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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#pragma once

#include "types.hh"
#include "flakeref.hh"
#include "lockfile.hh"

namespace nix {

struct Value;
class EvalState;

namespace fetchers { struct Tree; }

namespace flake {

struct FlakeInput;

typedef std::map<FlakeId, FlakeInput> FlakeInputs;

struct FlakeInput
{
    FlakeRef ref;
    bool isFlake = true;
    std::optional<InputPath> follows;
    FlakeInputs overrides;
};

struct Flake
{
    FlakeRef originalRef;
    FlakeRef resolvedRef;
    FlakeRef lockedRef;
    std::optional<std::string> description;
    std::shared_ptr<const fetchers::Tree> sourceInfo;
    FlakeInputs inputs;
    Value * vOutputs; // FIXME: gc
    ~Flake();
};

Flake getFlake(EvalState & state, const FlakeRef & flakeRef, bool allowLookup);

/* Fingerprint of a locked flake; used as a cache key. */
typedef Hash Fingerprint;

struct LockedFlake
{
    Flake flake;
    LockFile lockFile;

    Fingerprint getFingerprint() const;
};

struct LockFlags
{
    /* Whether to ignore the existing lock file, creating a new one
       from scratch. */
    bool recreateLockFile = false;

    /* Whether to update the lock file at all. If set to false, if any
       change to the lock file is needed (e.g. when an input has been
       added to flake.nix), you get a fatal error. */
    bool updateLockFile = true;

    /* Whether to write the lock file to disk. If set to true, if the
       any changes to the lock file are needed and the flake is not
       writable (i.e. is not a local Git working tree or similar), you
       get a fatal error. If set to false, Nix will use the modified
       lock file in memory only, without writing it to disk. */
    bool writeLockFile = true;

    /* Whether to use the registries to lookup indirect flake
       references like 'nixpkgs'. */
    bool useRegistries = true;

    /* Whether mutable flake references (i.e. those without a Git
       revision or similar) without a corresponding lock are
       allowed. Mutable flake references with a lock are always
       allowed. */
    bool allowMutable = true;

    /* Whether to commit changes to flake.lock. */
    bool commitLockFile = false;

    /* Flake inputs to be overriden. */
    std::map<InputPath, FlakeRef> inputOverrides;

    /* Flake inputs to be updated. This means that any existing lock
       for those inputs will be ignored. */
    std::set<InputPath> inputUpdates;
};

LockedFlake lockFlake(
    EvalState & state,
    const FlakeRef & flakeRef,
    const LockFlags & lockFlags);

void callFlake(
    EvalState & state,
    const LockedFlake & lockedFlake,
    Value & v);

}

void emitTreeAttrs(
    EvalState & state,
    const fetchers::Tree & tree,
    std::shared_ptr<const fetchers::Input> input,
    Value & v);

}