-
Notifications
You must be signed in to change notification settings - Fork 0
/
flake.nix
168 lines (160 loc) · 4.73 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
{
description = "changeme";
inputs = {
flake-utils.url = "github:numtide/flake-utils";
nixpkgs.url = "github:nixos/nixpkgs/23.11";
nixos-hardware.url = "github:nixos/nixos-hardware";
agenix.url = "github:ryantm/agenix";
agenix.inputs.nixpkgs.follows = "nixpkgs";
nixos-generators = {
url = "github:nix-community/nixos-generators";
inputs.nixpkgs.follows = "nixpkgs";
};
wsdd = {
url = "github:christgau/wsdd";
flake = false;
};
website = {
url = "github:meatcar/denys.me";
flake = false;
};
transit-dashboard.url = "git+ssh://git@github.com/meatcar/transit-dashboard";
};
outputs = {self, ...} @ inputs: let
nixpkgsConfig = {config = {allowUnfree = true;};};
specialArgs = {inherit inputs;};
in
inputs.flake-utils.lib.eachDefaultSystem
(system: let
pkgs = import inputs.nixpkgs (nixpkgsConfig // {inherit system;});
scripts = [
(pkgs.writeShellScriptBin "deploy" ''
FLAKE="$1"; shift 1
REMOTE_HOST=
REMOTE_OPTS= # opts to pass to nixos-rebuild
BUILD_HOST=
case "$FLAKE" in
chunkymonkey)
REMOTE_HOST=chunkymonkey.fish-hydra.ts.net
BUILD_HOST="$REMOTE_HOST"
;;
vps)
REMOTE_HOST=$(cd terraform && ${pkgs.terraform}/bin/terraform output --raw ip)
BUILD_HOST="$REMOTE_HOST"
;;
cube)
REMOTE_HOST=cube.fish-hydra.ts.net
REMOTE_OPTS=--impure
BUILD_HOST="$REMOTE_HOST"
;;
*)
echo no such remote host "$FLAKE" >&2
exit 1
esac
if ! ssh -o ConnectTimeout=5 "$REMOTE_HOST" exit; then
echo "$0: no connection to $REMOTE_HOST" >&2
exit 1
fi
cmd=$(echo nixos-rebuild "$@" \
--flake .#"$FLAKE" \
--target-host "$REMOTE_HOST" \
--build-host "$BUILD_HOST" \
--use-remote-sudo \
--use-substitutes $REMOTE_OPTS)
echo "$cmd"
$cmd
'')
];
in {
devShells.default = pkgs.mkShell rec {
name = "deploy.denys.me";
BASE_NIX_VERSION = self.nixosConfigurations.doImage.config.system.stateVersion;
buildInputs =
scripts
++ (with pkgs; [
inputs.agenix.packages.${system}.default
(terraform.withPlugins (p: [
p.local
p.external
p.null
p.random
p.aws
p.digitalocean
p.cloudflare
]))
awscli
wireguard-tools
jq
flyctl
oci-cli
packer
nixos-generators
]);
};
})
// {
nixosConfigurations = {
doImage = inputs.nixpkgs.lib.nixosSystem {
inherit specialArgs;
system = "x86_64-linux";
modules = [
./nixos/modules/base.nix
./nixos/modules/digitalocean.nix
{
system.stateVersion = "23.11";
mine.githubKeyUser = "meatcar";
mine.username = "meatcar";
}
];
};
chunkymonkey = inputs.nixpkgs.lib.nixosSystem {
inherit specialArgs;
system = "aarch64-linux";
modules = [
{
nixpkgs = nixpkgsConfig;
system.stateVersion = "23.11";
}
inputs.agenix.nixosModules.default
./nixos/systems/chunkymonkey/configuration.nix
];
};
vps = inputs.nixpkgs.lib.nixosSystem {
inherit specialArgs;
system = "x86_64-linux";
modules = [
{
nixpkgs = nixpkgsConfig;
system.stateVersion = "23.11";
}
inputs.agenix.nixosModules.default
./nixos/systems/vps/configuration.nix
];
};
rpi = inputs.nixpkgs.lib.nixosSystem {
inherit specialArgs;
system = "aarch64-linux";
modules = [
{
nixpkgs = nixpkgsConfig;
system.stateVersion = "23.11";
}
inputs.nixos-hardware.nixosModules.raspberry-pi-4
./nixos/systems/rpi.nix
];
};
cube = inputs.nixpkgs.lib.nixosSystem {
system = "x86_64-linux";
specialArgs = {inherit inputs;};
modules = [
{
system.stateVersion = "23.11";
nixpkgs = nixpkgsConfig;
}
inputs.agenix.nixosModules.default
./nixos/systems/cube/configuration.nix
];
};
};
};
}