-
Notifications
You must be signed in to change notification settings - Fork 2
/
flake.nix
118 lines (110 loc) · 3.51 KB
/
flake.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
{
description = "NixOS configuration";
inputs = {
nixpkgs = {
url = "github:nixos/nixpkgs/nixos-unstable-small";
};
home-manager = {
url = "github:nix-community/home-manager";
inputs.nixpkgs.follows = "nixpkgs";
};
nix-darwin = {
url = "github:LnL7/nix-darwin";
inputs.nixpkgs.follows = "nixpkgs";
};
nur-packages = {
url = "github:wegank/nur-packages";
inputs.nixpkgs.follows = "nixpkgs";
};
vscode-server = {
url = "github:nix-community/nixos-vscode-server";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs =
{
self,
nixpkgs,
home-manager,
nix-darwin,
nur-packages,
vscode-server,
}:
let
metadata = builtins.fromTOML (builtins.readFile ./flake.toml);
lib = nixpkgs.lib;
# Filter machines by suffix.
filterMachines =
suffix: (lib.filterAttrs (_: config: lib.hasSuffix suffix config.platform) metadata.machines);
# Get username.
getUserName =
name: host:
let
fullName = lib.splitString " " (lib.toLower metadata.users.${name}.fullName);
in
if (lib.hasSuffix "darwin" host.platform) then lib.concatStrings fullName else lib.head fullName;
# Set special args.
setSpecialArgs = host: {
isDarwin = lib.hasSuffix "darwin" host.platform;
isLinux = lib.hasSuffix "linux" host.platform;
isDesktop = (host.profile == "desktop");
isHomeServer = (host.profile == "home-server");
isMobile = (host.profile == "mobile");
isServer = (host.profile == "server");
owner = metadata.users.${metadata.owner.name} // {
name = getUserName metadata.owner.name host;
};
nur-pkgs = import nur-packages { pkgs = import nixpkgs { system = host.platform; }; };
};
# Set Home Manager template.
setHomeManagerTemplate = host: {
home-manager = {
useUserPackages = true;
useGlobalPkgs = true;
extraSpecialArgs = setSpecialArgs host;
users = lib.mapAttrs' (
name: _: lib.nameValuePair (getUserName name host) (./users + "/${name}" + /home.nix)
) metadata.users;
};
};
in
{
# macOS configurations.
darwinConfigurations = builtins.mapAttrs (
hostname: host:
nix-darwin.lib.darwinSystem {
system = host.platform;
specialArgs = setSpecialArgs host;
modules = [
# Nix Modules.
./modules/environment.nix
# System configuration.
./system/configuration.nix
# Home Manager configuration.
home-manager.darwinModules.home-manager
(setHomeManagerTemplate host)
];
}
) (filterMachines "darwin");
# NixOS configurations.
nixosConfigurations = builtins.mapAttrs (
hostname: host:
nixpkgs.lib.nixosSystem {
system = host.platform;
specialArgs = setSpecialArgs host;
modules = [
# Nix Modules.
vscode-server.nixosModule
./modules/environment.nix
# Hardware configuration.
(./hardware + "/${hostname}" + /hardware-configuration.nix)
# System configuration.
./system/configuration.nix
# Home Manager configuration.
home-manager.nixosModules.home-manager
(setHomeManagerTemplate host)
];
}
) (filterMachines "linux");
};
}