-
Notifications
You must be signed in to change notification settings - Fork 346
/
flake-module.nix
70 lines (63 loc) · 2.3 KB
/
flake-module.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
devenvFlake: { flake-parts-lib, lib, inputs, ... }: {
options.perSystem = flake-parts-lib.mkPerSystemOption ({ config, pkgs, system, ... }:
let
devenvType = (devenvFlake.lib.mkEval {
inherit inputs pkgs;
modules = [{
config = {
# Add flake-parts-specific config here if necessary
};
}] ++ config.devenv.modules;
}).type;
shellPrefix = shellName: if shellName == "default" then "" else "${shellName}-";
in
{
options.devenv.modules = lib.mkOption {
type = lib.types.listOf lib.types.deferredModule;
description = ''
Extra modules to import into every shell.
Allows flakeModules to add options to devenv for example.
'';
default = [ ];
};
options.devenv.shells = lib.mkOption {
type = lib.types.lazyAttrsOf devenvType;
description = ''
The [devenv.sh](https://devenv.sh) settings, per shell.
Each definition `devenv.shells.<name>` results in a value for
[`devShells.<name>`](flake-parts.html#opt-perSystem.devShells).
Define `devenv.shells.default` for the default `nix develop`
invocation - without an argument.
'';
example = lib.literalExpression ''
{
# create devShells.default
default = {
# devenv settings, e.g.
languages.elm.enable = true;
};
}
'';
default = { };
};
config.devShells = lib.mapAttrs (_name: devenv: devenv.shell) config.devenv.shells;
config.packages =
lib.concatMapAttrs
(shellName: devenv:
(lib.concatMapAttrs
(containerName: container:
{ "${shellPrefix shellName}container-${containerName}" = container.derivation; }
)
devenv.containers
) // {
"${shellPrefix shellName}devenv-up" = devenv.procfileScript;
"${shellPrefix shellName}devenv-test" = devenv.test;
}
)
config.devenv.shells;
});
# the extra parameter before the module make this module behave like an
# anonymous module, so we need to manually identify the file, for better
# error messages, docs, and deduplication.
_file = __curPos.file;
}