-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmk-modules.nix
112 lines (95 loc) · 3.27 KB
/
mk-modules.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
107
108
109
110
111
112
flakeInputs: mkModulesOpts: let
lib = flakeInputs.nixpkgs.lib;
systems = mkModulesOpts.systems or [
"aarch64-darwin"
"aarch64-linux"
"x86_64-darwin"
"x86_64-linux"
];
flakeSchemaModule.options = {
apps = lib.mkOption {
type = lib.types.attrsOf lib.types.str;
default = {};
};
checks = lib.mkOption {
type = lib.types.attrsOf lib.types.package;
default = {};
};
devShells = lib.mkOption {
type = lib.types.attrsOf lib.types.package;
default = {};
};
packages = lib.mkOption {
type = lib.types.attrsOf lib.types.package;
default = {};
};
nixosConfigurations = lib.mkOption {
# This type will be checked by lib.nixosSystem below
type = lib.types.attrsOf (lib.types.listOf lib.types.unspecified);
default = {};
};
garnix = {
deployBranch = lib.mkOption {
type = lib.types.str;
description = "The branch that garnix will automatically deploy servers from on push";
};
config.servers = lib.mkOption {
# This type is checked by garnix CI on push
# See https://garnix.io/docs/yaml_config for documentation
type = lib.types.listOf lib.types.unspecified;
default = [];
};
};
};
evalModules = system: lib.evalModules {
specialArgs = {
pkgs = import flakeInputs.nixpkgs { inherit system; };
inherit system;
};
modules = [
flakeSchemaModule
(mkModulesOpts.config or {})
] ++ (mkModulesOpts.modules or []);
};
evaledModulesForSystem = builtins.listToAttrs (map (system: { name = system; value = evalModules system; }) systems);
in {
apps = builtins.mapAttrs (_: evaled:
builtins.mapAttrs (_: program: { type = "app"; inherit program; }) evaled.config.apps
) evaledModulesForSystem;
packages = builtins.mapAttrs (_: evaled: evaled.config.packages) evaledModulesForSystem;
checks = builtins.mapAttrs (_: evaled: evaled.config.checks) evaledModulesForSystem;
devShells = builtins.mapAttrs (_: evaled: evaled.config.devShells // {
# combine all defined devshells into a single "default" devshell
default =
let pkgs = evaled._module.specialArgs.pkgs;
in pkgs.mkShell {
inputsFrom = builtins.attrValues evaled.config.devShells;
};
}) evaledModulesForSystem;
nixosConfigurations = builtins.mapAttrs (name: nixosModules: lib.nixosSystem {
modules = [
flakeInputs.self.nixosModules.garnix
{
# This sets up networking and filesystems in a way that works with garnix hosting.
garnix.server.enable = true;
# This is currently the only allowed value.
nixpkgs.hostPlatform = "x86_64-linux";
# Settings to improve nixos vm debuggability
virtualisation.vmVariant = {
virtualisation.graphics = false;
users.users.root.password = "";
};
}
] ++ nixosModules;
}) evaledModulesForSystem.x86_64-linux.config.nixosConfigurations;
garnix.config.servers = let
config = evaledModulesForSystem.x86_64-linux.config;
in
map (nixosConfigName: {
configuration = nixosConfigName;
deployment = {
type = "on-branch";
branch = config.garnix.deployBranch;
};
}) (builtins.attrNames config.nixosConfigurations);
}