-
Notifications
You must be signed in to change notification settings - Fork 0
/
flake.nix
163 lines (155 loc) · 4.72 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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
{
description = "dotfiles of nokazn";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
# In nixpkgs-unstale all packages are built for supported platforms including darwin
# https://discourse.nixos.org/t/differences-between-nix-channels/13998/5
nixpkgs-darwin.url = "github:nixos/nixpkgs/nixpkgs-unstable";
nix-darwin = {
url = "github:lnl7/nix-darwin";
inputs.nixpkgs.follows = "nixpkgs-darwin";
};
home-manager = {
url = "github:nix-community/home-manager/master";
inputs.nixpkgs.follows = "nixpkgs";
};
flake-utils.url = "github:numtide/flake-utils";
devshell.url = "github:numtide/devshell";
};
outputs =
{ nixpkgs
, nixpkgs-darwin
, nix-darwin
, home-manager
, flake-utils
, ...
}:
let
USER = "nokazn";
users = [
# For GitHub Actions
{ name = "runner"; isCi = true; }
# HACK: this line is replaced by the real user name as fallback
{ name = "${USER}"; isCi = false; }
];
nix = {
version = "24.05";
};
homeManagerConfigurations = (user: home: {
home-manager = {
useGlobalPkgs = true;
useUserPackages = true;
users = { ${user.name} = home; };
};
});
in
{
# For user environments
# - home-manager switch .#${USER}
# - home-manager switch .#${USER}-wsl
# For GitHub Actions
# - home-manager switch .#runner
# - home-manager switch .#runner-wsl
homeConfigurations =
let
generateContext = (user:
map (context: context // { user = { inherit (user) name; }; })
([
{
name = user.name;
meta = { inherit (user) isCi; isWsl = false; };
}
{
name = user.name + "-wsl";
meta = { inherit (user) isCi; isWsl = true; };
}
])
);
contexts = nixpkgs.lib.lists.flatten (map generateContext users);
generateConfiguration = (context:
{
name = context.name;
value = home-manager.lib.homeManagerConfiguration {
pkgs = nixpkgs.legacyPackages.x86_64-linux;
modules = [
./home/linux.nix
];
extraSpecialArgs = with context; {
inherit nix user meta;
};
};
}
);
in
nixpkgs.lib.listToAttrs
(builtins.map (generateConfiguration) contexts);
# For darwin
# - darwin-rebuild switch .#${system}-$(USER)
# For GitHub Actions
# - darwin-rebuild switch .#${system}-runner
darwinConfigurations =
let
systems = [ "aarch64-darwin" "x86_64-darwin" ];
contextGenerators = map
(system: user: ({
inherit system;
name = system + "-" + user.name;
user = { inherit (user) name; };
meta = {
inherit (user) isCi;
isWsl = false;
};
}))
systems;
contexts = nixpkgs.lib.flatten (
map (generator: map generator users) contextGenerators
);
generateConfiguration = (context:
{
name = context.name;
value = with context; nix-darwin.lib.darwinSystem rec {
inherit system;
pkgs = nixpkgs-darwin.legacyPackages.${system};
modules = [
./hosts/darwin
home-manager.darwinModules.home-manager
(homeManagerConfigurations user (import ./home/darwin.nix {
inherit pkgs nix user meta;
lib = pkgs.lib;
}))
];
specialArgs = { inherit user nix meta; };
};
});
in
nixpkgs.lib.listToAttrs
(builtins.map generateConfiguration contexts);
} // (flake-utils.lib.eachDefaultSystem
(system:
let
pkgs = import nixpkgs {
inherit system;
};
in
{
devShells.default = pkgs.mkShell
{
buildInputs = with pkgs; [
gnumake
shellcheck
shfmt
nixpkgs-fmt
yamlfmt
dprint
pre-commit
treefmt
];
};
}));
nixConfig = {
experimental-features = [ "nix-command" "flakes" ];
# https://nixos.org/manual/nix/stable/command-ref/conf-file.html#conf-auto-optimise-store
auto-optimise-store = true;
eval-cache = true;
};
}