-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdefault.nix
137 lines (124 loc) · 4.38 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
self:
rec {
gradientosSystem =
{ name
, nixpkgs ? self.inputs.nixpkgs
, ...
}@args:
nixpkgs.lib.nixosSystem (gradientosSystemInternal args);
gradientosSystemGenerator =
{ name
, format
, ...
}@args:
self.inputs.nixos-generators.nixosGenerate ((gradientosSystemInternal (args // { deployment = null; })) // { inherit format; });
gradientosSystemColmena =
{ name
, ...
}@args:
let
gradientosConfig = gradientosSystemInternal args;
in {
meta = {
nodeNixpkgs.${name} = gradientosConfig.pkgs;
nodeSpecialArgs.${name} = gradientosConfig.specialArgs;
};
${name} = gradientosConfig.modules;
};
gradientosSystemInternal =
{ name
, nixpkgs ? self.inputs.nixpkgs
, system ? "x86_64-linux"
, modules ? [ ]
, overlays ? [ ]
, users ? { }
, specialArgs ? { }
, deployment ? {}
, makeSystem ? true
, importCore ? true
, importHost ? true
, importModules ? true
, importLix ? true
, ...
}:
{
inherit system;
specialArgs = { inherit self; } // specialArgs;
pkgs = import nixpkgs {
inherit system;
config = {
allowUnfree = true;
allowBroken = true;
permittedInsecurePackages = [
"dotnet-sdk-7.0.410" # TODO: Remove when not needed anymore
"dotnet-sdk-wrapped-7.0.410" # TODO: Remove when not needed anymore
"dotnet-sdk-6.0.428" # TODO: Remove when not needed anymore
"dotnet-sdk-wrapped-6.0.428" # TODO: Remove when not needed anymore
"aspnetcore-runtime-wrapped-6.0.36" # TODO: Remove when not needed anymore
"aspnetcore-runtime-6.0.36" # TODO: Remove when not needed anymore
];
};
overlays = [
(import ../overlays/gradientos.nix self)
(import ../overlays/gradientpkgs.nix)
] ++ overlays;
};
modules = [
(mkHostNameModule name)
self.inputs.home-manager.nixosModules.home-manager
{
home-manager.useGlobalPkgs = true;
home-manager.useUserPackages = true;
home-manager.backupFileExtension = "bck";
home-manager.extraSpecialArgs = { inherit self; };
}
] ++ modules ++ (mkUserModules users)
++ (if importCore then [../core/default.nix] else [])
++ (if importHost then [../hosts/${name}/default.nix] else [])
++ (if importModules then [../modules/default.nix] else [])
++ (if importLix then [self.inputs.lix-module.nixosModules.default] else [])
++ (if deployment != null then [{ inherit deployment; }] else []);
} // (if deployment != null then {
# See https://github.com/zhaofengli/colmena/issues/60#issuecomment-1047199551
extraModules = [ self.inputs.colmena.nixosModules.deploymentOptions ];
} else {});
mkHostNameModule = name:
({ ... }: { networking.hostName = self.inputs.nixpkgs.lib.mkForce name; });
mkUserModules = users: # { test = { modules = [ ./example.nix ] } }
with self.inputs.nixpkgs.lib;
(lists.flatten (attrsets.mapAttrsToList
(name: value: [
../users/${name}
{
home-manager.users.${name} = {
imports = [
../users/common/home.nix
../users/${name}/home.nix
] ++ value.modules;
};
}
])
users));
forAllSystems = function: forAllSystemsCustom { config.allowUnfree = true; } function;
forAllSystemsWithOverlays = overlays: function: forAllSystemsCustom { inherit overlays; config.allowUnfree = true; } function;
forAllSystemsCustom = nixpkgsCfg: function:
self.inputs.nixpkgs.lib.genAttrs [ "x86_64-linux" "aarch64-linux" ]
(system: function (import self.inputs.nixpkgs (nixpkgsCfg // { inherit system; })));
/*
* similar to switch statements in other programming languages.
value -> any
cases -> list of attrset "case"
case -> {
case -> any, must match value
value -> any
}
a case with a null value is treated as the default match.
in case of multiple matches, the first one is returned.
in case of no matches, null is returned.
*/
switch = value: cases:
let
matches = builtins.filter (case: (case.case == value) || (case.case == null)) cases;
in
if matches == [] then null else (builtins.head(matches)).value;
}