-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
flakeLib.nix
102 lines (101 loc) · 3.23 KB
/
flakeLib.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
{ inputs, mkPkgsWithSystem }:
let
# my own custom lib will be accessible with `lib.myLib.<name>`
lib = inputs.nixpkgs.lib.extend (final: prev: { myLib = import ./lib { lib = final; }; });
in
{
mkSystem =
{
hostname,
adminUser ? "budiman", # default user to login with `sudo` access
system ? "x86_64-linux",
nixpkgs ? inputs.nixpkgs,
# myPkgs defaulted to the `legacyPackages` from this flake
myPkgs ? inputs.self.legacyPackages.${system},
# homeUsers is list of home-manager users for the host
# each user needs a `./home-manager/<name>/default.nix` file present
# set it to empty list to disable home-manager altogether for the host
homeUsers ? [ adminUser ],
# baseModules is the base of the entire machine building
baseModules ? [
inputs.sops-nix.nixosModules.sops
inputs.home-manager.nixosModules.home-manager
inputs.catppuccin.nixosModules.catppuccin
./system/_modules # all machines get my own NixOS modules
./system/hosts # entrypoint to all machines
{
config = {
mySystem = {
adminUser = adminUser;
};
};
}
],
# extraModules is additional modules you want to add for the host
extraModules ? [ ],
}:
let
mkHomeUsers = lib.optionals (homeUsers != [ ]) [
{
config.home-manager = {
users = builtins.listToAttrs (
builtins.map (name: {
name = name;
value = {
imports = [ ./home/${name} ];
config.myHome = {
username = name;
};
};
}) homeUsers
);
useGlobalPkgs = true;
useUserPackages = true;
extraSpecialArgs = {
inherit inputs myPkgs hostname;
};
sharedModules = [
inputs.sops-nix.homeManagerModules.sops
inputs.catppuccin.homeManagerModules.catppuccin
./home/_modules # all users get my own home-manager modules
];
};
}
];
in
nixpkgs.lib.nixosSystem {
inherit system lib;
pkgs = mkPkgsWithSystem system;
specialArgs = {
inherit inputs myPkgs hostname;
};
modules = baseModules ++ extraModules ++ mkHomeUsers;
};
mkHome =
{
hostname,
username ? "budiman",
system ? "x86_64-linux",
nixpkgs ? inputs.nixpkgs,
# myPkgs defaulted to the `legacyPackages` from this flake
myPkgs ? inputs.self.legacyPackages.${system},
}:
inputs.home-manager.lib.homeManagerConfiguration {
inherit lib;
pkgs = mkPkgsWithSystem system;
extraSpecialArgs = {
inherit inputs myPkgs hostname;
# need to have this because a lot of my modules depends on `osConfig` argument
osConfig = { };
};
modules = [
inputs.sops-nix.homeManagerModules.sops
inputs.catppuccin.homeManagerModules.catppuccin
./home/_modules # all users get my own home-manager modules
{
imports = [ ./home/${username} ];
config.myHome.username = username;
}
];
};
}