-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdevcontainer.nix
106 lines (103 loc) · 3.92 KB
/
devcontainer.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
topLevel@{ flake-parts-lib, inputs, lib, ... }: {
imports = [
inputs.flake-parts.flakeModules.flakeModules
./common.nix
];
flake.flakeModules.devcontainer = {
imports = [
topLevel.config.flake.flakeModules.common
];
options.perSystem = flake-parts-lib.mkPerSystemOption (perSystem @{ system, pkgs, ... }: {
options.ml-ops.devcontainer = lib.mkOption {
description = lib.mdDoc ''
Configuration for the development environment.
'';
default = { };
type = lib.types.submoduleWith {
modules = [
(devcontainer: {
imports = [ perSystem.config.ml-ops.common ];
options.nixago.requests = lib.mkOption {
type = lib.types.submoduleWith {
modules = [{
_module.freeformType = lib.types.attrsOf lib.types.deferredModule;
}];
};
default = { };
};
options.nixDirenvFlakeFlags = lib.mkOption {
type = lib.types.listOf lib.types.str;
};
config.nixDirenvFlakeFlags = [
# Disable Nix's eval-cache so that we can always see error messages if any.
"--no-eval-cache"
# Environment variables are cached by direnv, so we don't need Nix's eval-cache.
"--show-trace"
];
config.nixago.requests.".envrc" = {
data = ''
if ! has nix_direnv_version || ! nix_direnv_version 2.3.0; then
source_url "https://raw.githubusercontent.com/nix-community/nix-direnv/2.3.0/direnvrc" "sha256-Dmd+j63L84wuzgyjITIfSxSD57Tx7v51DMxVZOsiUD8="
fi
use flake . ${
lib.escapeShellArgs devcontainer.config.nixDirenvFlakeFlags
}
'';
hook.mode = "copy";
engine = { data, output, ... }: pkgs.writeTextFile {
name = output;
text = data;
};
};
options.mountVolumeWithSudo = lib.mkOption {
default = true;
};
config.devenvShellModule = {
name = "devcontainer";
packages = [
pkgs.git
pkgs.openssh
];
devenv.skipLibraryPathEnv = true;
enterShell =
lib.mkMerge
([
(inputs.nixago.lib.${system}.makeAll (
lib.attrsets.mapAttrsToList
(output: request: {
imports = [ request ];
inherit output;
})
devcontainer.config.nixago.requests
)).shellHook
] ++ (
builtins.concatMap
(lib.attrsets.mapAttrsToList
(mountPath: protocolConfig:
if devcontainer.config.mountVolumeWithSudo then
lib.escapeShellArgs [
"sudo"
"bash"
"-c"
protocolConfig.mountScript
]
else
protocolConfig.mountScript)
)
(builtins.attrValues (devcontainer.config.volumeMounts or { }))
));
};
})
];
};
};
config = {
devenv.shells.default = {
imports = [ perSystem.config.ml-ops.devcontainer.devenvShellModule ];
devcontainer.enable = true;
devcontainer.settings.updateContentCommand = "direnv allow";
};
};
});
};
}