-
Notifications
You must be signed in to change notification settings - Fork 57
/
systemFlake.nix
127 lines (111 loc) · 3.62 KB
/
systemFlake.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
{ flake-utils }:
{ self
, defaultSystem ? "x86_64-linux"
, sharedExtraArgs ? { inherit inputs; }
, supportedSystems ? flake-utils.lib.defaultSystems
, inputs
, nixosConfigurations ? { }
, nixosProfiles ? { }
, channels ? { }
, channelsConfig ? { }
, sharedModules ? [ ]
, sharedOverlays ? [ ]
# `Func` postfix is soon to be deprecated. Replaced with `Builder` instead
, packagesFunc ? null
, defaultPackageFunc ? null
, appsFunc ? null
, defaultAppFunc ? null
, devShellFunc ? null
, checksFunc ? null
, packagesBuilder ? packagesFunc
, defaultPackageBuilder ? defaultPackageFunc
, appsBuilder ? appsFunc
, defaultAppBuilder ? defaultAppFunc
, devShellBuilder ? devShellFunc
, checksBuilder ? checksFunc
, ...
}@args:
let
otherArguments = builtins.removeAttrs args [
"defaultSystem"
"sharedExtraArgs"
"inputs"
"nixosProfiles"
"channels"
"channelsConfig"
"self"
"sharedModules"
"sharedOverlays"
"supportedSystems"
# `Func` postfix is deprecated. Replaced with `Builder` instead
"packagesFunc"
"defaultPackageFunc"
"appsFunc"
"defaultAppFunc"
"devShellFunc"
"checksFunc"
"packagesBuilder"
"defaultPackageBuilder"
"appsBuilder"
"defaultAppBuilder"
"devShellBuilder"
"checksBuilder"
];
nixosConfigurationBuilder = name: value: (
# It would be nice to get `nixosSystem` reference from `selectedNixpkgs` but it is not possible at this moment
inputs.nixpkgs.lib.nixosSystem (genericConfigurationBuilder name value)
);
genericConfigurationBuilder = name: value: (
let
system = if (value ? system) then value.system else defaultSystem;
channelName = if (value ? channelName) then value.channelName else "nixpkgs";
selectedNixpkgs = self.pkgs."${system}"."${channelName}";
in
with selectedNixpkgs.lib; {
inherit system;
modules = [
{
networking.hostName = name;
nixpkgs = {
pkgs = selectedNixpkgs;
config = selectedNixpkgs.config;
};
system.configurationRevision = mkIf (self ? rev) self.rev;
nix.package = mkDefault selectedNixpkgs.nixUnstable;
}
]
++ sharedModules
++ (optionals (value ? modules) value.modules);
extraArgs = sharedExtraArgs // optionalAttrs (value ? extraArgs) value.extraArgs;
}
);
in
otherArguments
// flake-utils.lib.eachSystem supportedSystems (system:
let
patchChannel = channel: patches:
if patches == [ ] then channel else
(import channel { inherit system; }).pkgs.applyPatches {
name = "nixpkgs-patched-${channel.shortRev}";
src = channel;
patches = patches;
};
importChannel = name: value: import (patchChannel value.input (value.patches or [ ])) {
inherit system;
overlays = sharedOverlays ++ (if (value ? overlaysBuilder) then (value.overlaysBuilder pkgs) else [ ]);
config = channelsConfig // (if (value ? config) then value.config else { });
};
pkgs = builtins.mapAttrs importChannel channels;
optional = check: value: (if check != null then value else { });
in
{ inherit pkgs; }
// optional packagesBuilder { packages = packagesBuilder pkgs; }
// optional defaultPackageBuilder { defaultPackage = defaultPackageBuilder pkgs; }
// optional appsBuilder { apps = appsBuilder pkgs; }
// optional defaultAppBuilder { defaultApp = defaultAppBuilder pkgs; }
// optional devShellBuilder { devShell = devShellBuilder pkgs; }
// optional checksBuilder { checks = checksBuilder pkgs; }
)
// {
nixosConfigurations = nixosConfigurations // (builtins.mapAttrs nixosConfigurationBuilder nixosProfiles);
}