-
Notifications
You must be signed in to change notification settings - Fork 0
/
flake.nix
201 lines (189 loc) · 5.77 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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
{
description = "nix system configurations";
nixConfig = {
substituters = [
"https://nix-community.cachix.org/"
"https://cache.nixos.org"
];
trusted-public-keys = [
"nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs="
"cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY="
];
};
inputs = {
devshell.url = "github:numtide/devshell";
flake-utils.url = "github:numtide/flake-utils";
nixos-hardware.url = "github:nixos/nixos-hardware";
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
stable.url = "github:nixos/nixpkgs/nixos-21.05";
treefmt.url = "github:numtide/treefmt";
spacebar.url = "github:cmacrae/spacebar/v1.3.0";
work.url = "git+https://github.com/circleci/sarahhodne-nix.git?ref=main";
flake-compat = {
url = "github:edolstra/flake-compat";
flake = false;
};
darwin = {
url = "github:kclejeune/nix-darwin/backup-etc";
inputs.nixpkgs.follows = "nixpkgs";
};
home-manager = {
url = "github:nix-community/home-manager/master";
inputs.nixpkgs.follows = "nixpkgs";
};
neovim-nightly-overlay = {
url = "github:nix-community/neovim-nightly-overlay";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs =
inputs@{ self
, nixpkgs
, stable
, darwin
, home-manager
, nixos-hardware
, devshell
, treefmt
, spacebar
, flake-utils
, ...
}:
let
supportedSystems = [ "x86_64-darwin" "x86_64-linux" ];
overlays = [ inputs.neovim-nightly-overlay.overlay ];
lib = nixpkgs.lib.extend
(final: prev: (import ./lib final) // home-manager.lib);
inherit (darwin.lib) darwinSystem;
inherit (nixpkgs.lib) nixosSystem;
inherit (home-manager.lib) homeManagerConfiguration;
inherit (flake-utils.lib) eachDefaultSystem eachSystem;
inherit (builtins) listToAttrs map;
# generate a base darwin configuration with the
# specified hostname, overlays, and any extraModules applied
mkDarwinConfig =
{ system ? "x86_64-darwin"
, baseModules ? [
home-manager.darwinModules.home-manager
./modules/darwin
]
, extraModules ? [ ]
}:
darwinSystem {
# system = "x86_64-darwin";
modules = baseModules ++ extraModules
++ [{ nixpkgs.overlays = overlays; }];
specialArgs = { inherit inputs lib; };
};
# generate a base nixos configuration with the
# specified overlays, hardware modules, and any extraModules applied
mkNixosConfig =
{ system ? "x86_64-linux"
, hardwareModules
, baseModules ? [
home-manager.nixosModules.home-manager
./modules/nixos
]
, extraModules ? [ ]
}:
nixosSystem {
inherit system;
modules = baseModules ++ hardwareModules ++ extraModules
++ [{ nixpkgs.overlays = overlays; }];
specialArgs = { inherit inputs lib; };
};
# generate a home-manager configuration usable on any unix system
# with overlays and any extraModules applied
mkHomeConfig =
{ username
, system ? "x86_64-linux"
, baseModules ? [ ./modules/home-manager ]
, extraModules ? [ ]
}:
homeManagerConfiguration rec {
inherit system username;
homeDirectory = "/home/${username}";
extraSpecialArgs = { inherit inputs lib; };
configuration = {
imports = baseModules ++ extraModules
++ [{ nixpkgs.overlays = overlays; }];
};
};
in
{
checks = listToAttrs (
# darwin checks
(map
(system: {
name = system;
value = {
darwin =
self.darwinConfigurations.work.config.system.build.toplevel;
};
})
lib.platforms.darwin) ++
# linux checks
(map
(system: {
name = system;
value = {
nixos = self.nixosConfigurations.phil.config.system.build.toplevel;
server = self.homeConfigurations.server.activationPackage;
};
})
lib.platforms.linux)
);
darwinConfigurations = {
work = mkDarwinConfig {
extraModules =
[
inputs.work.nixosModules.work
./modules/darwin/apps.nix
];
};
};
nixosConfigurations = { };
homeConfigurations = {
work = mkHomeConfig {
username = "sarah";
extraModules = [ inputs.work.hmModule ];
};
};
} //
# add a devShell to this flake
eachSystem supportedSystems (system:
let
pkgs = import nixpkgs {
inherit system;
overlays = [ devshell.overlay ];
};
pyEnv = (pkgs.python3.withPackages
(ps: with ps; [ black pylint typer colorama shellingham ]));
nixBin = pkgs.writeShellScriptBin "nix" ''
${pkgs.nixFlakes}/bin/nix --option experimental-features "nix-command flakes" "$@"
'';
sysdo = pkgs.writeShellScriptBin "sysdo" ''
cd $DEVSHELL_ROOT && ${pyEnv}/bin/python3 bin/do.py $@
'';
fmt = treefmt.defaultPackage.${system};
in
{
devShell = pkgs.devshell.mkShell {
packages = with pkgs; [ nixBin pyEnv fmt ];
commands = [
{
name = "sysdo";
package = sysdo;
category = "utilities";
help = "perform actions on this repository";
}
{
help = "Format the entire code tree";
name = "fmt";
command = "treefmt -q";
category = "utilities";
}
];
};
});
}