aboutsummaryrefslogtreecommitdiff
path: root/src/libutil/apply-config-options.hh
blob: 533904a695c9e6fb3a7f4a16dea2a7ba76b27660 (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
#pragma once
/**
 * @file
 * @brief Options for applying `Config` settings.
 */

#include <types.hh>

namespace nix {

/**
 * Options for applying `Config` settings.
 */
struct ApplyConfigOptions
{
    /**
     * The configuration file being loaded.
     *
     * If set, relative paths are allowed and interpreted as relative to the
     * directory of this path.
     */
    std::optional<Path> path = std::nullopt;

    /**
     * If set, tilde paths (like `~/.config/repl.nix`) are allowed and the
     * tilde is substituted for this directory.
     */
    std::optional<Path> home = std::nullopt;

    /**
     * Is the configuration being loaded from the `$NIX_CONFIG` environment
     * variable?
     *
     * Used for formatting error messages.
     */
    bool fromEnvVar = false;

    /**
     * Display the `relative` path field, with a reasonable default if none is
     * available.
     */
    std::string relativeDisplay() const {
        if (path) {
            return *path;
        } else if (fromEnvVar) {
            return "$NIX_CONFIG";
        } else {
            return "<unknown>";
        }
    }
};

}