-
Notifications
You must be signed in to change notification settings - Fork 0
/
default.nix
89 lines (89 loc) · 2.34 KB
/
default.nix
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
{
lib,
pkgs,
config,
...
}:
let
inherit (lib)
filterAttrs
mkEnableOption
mkIf
mkOption
types
;
inherit (lib.attrsets) attrNames mapAttrs' concatMapAttrs;
cfg = config.gcloud;
in
{
options.gcloud = {
enable = mkEnableOption "Install the Google Cloud SDK";
extra-components = mkOption {
description = "IDs of Google Cloud SDK components to install";
default = [ ];
example = [ "gke-gcloud-auth-plugin" ];
type = types.listOf (types.enum (attrNames pkgs.google-cloud-sdk.components));
};
package = mkOption {
readOnly = true;
internal = true;
type = types.package;
default =
if cfg.extra-components == [ ] then
pkgs.google-cloud-sdk
else
pkgs.google-cloud-sdk.withExtraComponents (
builtins.map (c: pkgs.google-cloud-sdk.components.${c}) cfg.extra-components
);
};
config-directory = mkOption {
default = null;
description = "Path to the config directory";
type = types.nullOr types.nonEmptyStr;
};
active-configuration-name = mkOption {
default = null;
description = "The name of the configuration to use in the shell";
type = types.nullOr types.nonEmptyStr;
};
properties = mkOption {
default = { };
description = "Configuration properties to set in the shell";
type = types.attrsOf (
types.attrsOf (
types.oneOf [
types.nonEmptyStr
types.bool
]
)
);
};
configEnvVars = mkOption {
readOnly = true;
internal = true;
type = types.attrsOf types.nonEmptyStr;
default =
let
toEnvName = s: builtins.replaceStrings [ "-" ] [ "_" ] (lib.strings.toUpper s);
sectionsToEnv =
section:
mapAttrs' (
property: value: {
inherit value;
name = "CLOUDSDK_${toEnvName section}_${toEnvName property}";
}
);
in
concatMapAttrs sectionsToEnv cfg.properties;
};
};
config = lib.mkIf cfg.enable {
packages = [ cfg.package ];
env =
(filterAttrs (_: v: v != null) {
CLOUDSDK_CONFIG = cfg.config-directory;
CLOUDSDK_ACTIVE_CONFIG_NAME = cfg.active-configuration-name;
})
// cfg.configEnvVars;
};
}