Nix 2.36.0
Nix, the purely functional package manager; unstable internal interfaces
Loading...
Searching...
No Matches
fetch-settings.hh
Go to the documentation of this file.
1#pragma once
3
4#include "nix/util/types.hh"
6#include "nix/util/ref.hh"
7#include "nix/util/sync.hh"
8
9#include <map>
10#include <limits>
11
12#include <sys/types.h>
13
14namespace nix {
15
16struct GitRepo;
17struct SrcToStore;
18struct GitRepoPool;
19
20} // namespace nix
21
22namespace nix::fetchers {
23
24struct Cache;
25
26struct Settings : public Config
27{
28 Settings();
29
30 Setting<StringMap> accessTokens{
31 this,
32 {},
33 "access-tokens",
34 R"(
35 Access tokens used to access protected GitHub, GitLab, or
36 other locations requiring token-based authentication.
37
38 Access tokens are specified as a string made up of
39 space-separated `host=token` values. The specific token
40 used is selected by matching the `host` portion against the
41 "host" specification of the input. The `host` portion may
42 contain a path element which matches against the prefix
43 URL for the input. (eg: `github.com/org=token`). The actual use
44 of the `token` value is determined by the type of resource
45 being accessed:
46
47 * Github: the token value is the OAUTH-TOKEN string obtained
48 as the Personal Access Token from the Github server (see
49 https://docs.github.com/en/developers/apps/building-oauth-apps/authorizing-oauth-apps).
50
51 * Gitlab: the token value is either the OAuth2 token or the
52 Personal Access Token (these are different types tokens
53 for gitlab, see
54 https://docs.gitlab.com/12.10/ee/api/README.html#authentication).
55 The `token` value should be `type:tokenstring` where
56 `type` is either `OAuth2` or `PAT` to indicate which type
57 of token is being specified.
58
59 Example `~/.config/nix/nix.conf`:
60
61 ```
62 access-tokens = github.com=23ac...b289 gitlab.mycompany.com=PAT:A123Bp_Cd..EfG gitlab.com=OAuth2:1jklw3jk
63 ```
64
65 Example `~/code/flake.nix`:
66
67 ```nix
68 input.foo = {
69 type = "gitlab";
70 host = "gitlab.mycompany.com";
71 owner = "mycompany";
72 repo = "pro";
73 };
74 ```
75
76 This example specifies three tokens, one each for accessing
77 github.com, gitlab.mycompany.com, and gitlab.com.
78
79 The `input.foo` uses the "gitlab" fetcher, which might
80 requires specifying the token type along with the token
81 value.
82 )"};
83
84 Setting<bool> allowDirty{this, true, "allow-dirty", "Whether to allow dirty Git/Mercurial trees."};
85
86 Setting<bool> warnDirty{this, true, "warn-dirty", "Whether to warn about dirty Git/Mercurial trees."};
87
88 Setting<bool> allowDirtyLocks{
89 this,
90 false,
91 "allow-dirty-locks",
92 R"(
93 Whether to allow dirty inputs (such as dirty Git workdirs)
94 to be locked via their NAR hash. This is generally bad
95 practice since Nix has no way to obtain such inputs if they
96 are subsequently modified. Therefore lock files with dirty
97 locks should generally only be used for local testing, and
98 should not be pushed to other users.
99 )",
100 {},
101 true,
102 Xp::Flakes};
103
104 Setting<bool> trustTarballsFromGitForges{
105 this,
106 true,
107 "trust-tarballs-from-git-forges",
108 R"(
109 If enabled (the default), Nix considers tarballs from
110 GitHub and similar Git forges to be locked if a Git revision
111 is specified,
112 e.g. `github:NixOS/patchelf/7c2f768bf9601268a4e71c2ebe91e2011918a70f`.
113 This requires Nix to trust that the provider returns the
114 correct contents for the specified Git revision.
115
116 If disabled, such tarballs are only considered locked if a
117 `narHash` attribute is specified,
118 e.g. `github:NixOS/patchelf/7c2f768bf9601268a4e71c2ebe91e2011918a70f?narHash=sha256-PPXqKY2hJng4DBVE0I4xshv/vGLUskL7jl53roB8UdU%3D`.
119 )"};
120
121 Setting<std::string> flakeRegistry{
122 this,
123 "https://channels.nixos.org/flake-registry.json",
124 "flake-registry",
125 R"(
126 Path or URI of the global flake registry.
127
128 When empty, disables the global flake registry.
129 )",
130 {},
131 true,
132 Xp::Flakes};
133
134 Setting<unsigned int> tarballTtl{
135 this,
136 60 * 60,
137 "tarball-ttl",
138 R"(
139 The number of seconds a downloaded tarball is considered fresh. If
140 the cached tarball is stale, Nix checks whether it is still up
141 to date using the ETag header. Nix downloads a new version if
142 the ETag header is unsupported, or the cached ETag doesn't match.
143
144 Setting the TTL to `0` forces Nix to always check if the tarball is
145 up to date.
146
147 Nix caches tarballs in `$XDG_CACHE_HOME/nix/tarballs`.
148
149 Files fetched via `NIX_PATH`, `fetchGit`, `fetchMercurial`,
150 `fetchTarball`, and `fetchurl` respect this TTL.
151 )"};
152
153 ref<Cache> getCache() const;
154
155 ref<GitRepo> getTarballCache() const;
156
162
163 const ref<SrcToStore> srcToStore = createSrcToStore();
164
165 ref<GitRepoPool> getTarballWriterPool() const;
166
167private:
168 void anchor() override;
169
170 mutable Sync<std::shared_ptr<Cache>> _cache;
171};
172
173} // namespace nix::fetchers
Definition configuration.hh:476
Definition ref.hh:58
Definition git-utils.hh:140
Definition git-utils.hh:27
Definition fetch-to-store.cc:12
Definition cache.hh:14
static ref< SrcToStore > createSrcToStore()
Definition fetch-to-store.cc:19