-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathflake.nix
152 lines (133 loc) · 3.79 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
{
inputs = {
flake-utils.url = "github:numtide/flake-utils/v1.0.0";
disko = {
url = "github:nix-community/disko/latest";
inputs.nixpkgs.follows = "nixpkgs";
};
agenix.url = "github:ryantm/agenix";
devenv = {
url = "github:cachix/devenv";
inputs.nixpkgs.follows = "nixpkgs";
};
nixpkgs.url = "github:NixOS/nixpkgs/24.05";
};
outputs =
{
self,
nixpkgs,
flake-utils,
agenix,
devenv,
disko,
...
}@inputs:
flake-utils.lib.eachDefaultSystem (
system:
let
pkgs = import nixpkgs {
inherit system;
config.allowUnfree = true;
};
machine = nixpkgs.lib.nixosSystem {
system = builtins.replaceStrings [ "darwin" ] [ "linux" ] system;
modules = [
agenix.nixosModules.default
./modules/qemu.nix
./modules/erlang.nix
./modules/extras.nix
./modules/nginx.nix
./modules/postgres.nix
./modules/users.nix
];
specialArgs = {
inherit pkgs;
};
};
program =
imageName:
pkgs.writeShellScript "run-vm.sh" ''
export IMAGE_NAME="${imageName}.qcow2"
export NIX_DISK_IMAGE=$(mktemp -u -t $IMAGE_NAME)
trap "rm -f $NIX_DISK_IMAGE" EXIT
${machine.config.system.build.vm}/bin/run-nixos-vm
'';
in
{
# nix build
packages = {
# Remote NixOS AWS VM
nixosConfigurations = {
# This config is used when in the Terraform provisioning, so
# it contains the bare minimum for us to log in there with ssh
bootstrap = nixpkgs.lib.nixosSystem {
system = "x86_64-linux";
modules = [
./configuration.nix
./modules/extras.nix
./modules/users.nix
];
specialArgs = {
inherit pkgs;
};
};
# After provisioning the infra with Terraform, we start to deploy
# this configuration here.
nekoma = nixpkgs.lib.nixosSystem {
system = "x86_64-linux";
modules = [
agenix.nixosModules.default
./configuration.nix
./modules/erlang.nix
./modules/extras.nix
./modules/nginx.nix
./modules/postgres.nix
./modules/users.nix
./modules/secrets.nix
];
specialArgs = {
inherit pkgs agenix;
};
};
};
};
# nix run
apps = {
default = {
type = "app";
program = builtins.toString (program "nixos");
};
};
devShells = {
# `nix develop --impure`
default = devenv.lib.mkShell {
inherit inputs pkgs;
modules = [
(
{ pkgs, lib, ... }:
{
packages = with pkgs; [
bash
just
];
languages.terraform = {
enable = true;
};
scripts = {
build.exec = "just build";
run.exec = "just run";
deploy.exec = "just deploy";
};
# looks for the .env by default additionaly, there is .filename
# if an arbitrary file is desired
dotenv.enable = true;
}
)
];
};
};
# nix fmt
formatter = pkgs.nixfmt-rfc-style;
}
);
}