forked from ToposInstitute/CatColab
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathflake.nix
More file actions
170 lines (155 loc) · 4.49 KB
/
flake.nix
File metadata and controls
170 lines (155 loc) · 4.49 KB
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
{
description = "configurations for deploying catcolab";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-24.11";
crate2nix = {
url = "github:nix-community/crate2nix";
inputs.nixpkgs.follows = "nixpkgs";
};
agenix.url = "github:ryantm/agenix";
deploy-rs.url = "github:serokell/deploy-rs";
fenix = {
url = "github:nix-community/fenix";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs =
{
self,
nixpkgs,
crate2nix,
agenix,
deploy-rs,
fenix,
...
}@inputs:
let
# Linux-specific outputs (NixOS configurations and deploy)
linuxSystem = "x86_64-linux";
devShellSystems = [
"x86_64-linux"
"x86_64-darwin"
"aarch64-darwin"
];
rustToolchain = fenix.packages.x86_64-linux.fromToolchainFile {
file = ./rust-toolchain.toml;
sha256 = "sha256-KUm16pHj+cRedf8vxs/Hd2YWxpOrWZ7UOrwhILdSJBU=";
};
nixpkgsFor =
system:
import nixpkgs {
inherit system;
config.allowUnfree = true;
};
pkgsLinux = nixpkgsFor linuxSystem;
# Generate devShells for each system
devShellForSystem =
system:
let
pkgs = nixpkgsFor system;
# macOS-specific configurations for libraries
darwinDeps =
if pkgs.stdenv.isDarwin then
[
pkgs.darwin.apple_sdk.frameworks.Security
pkgs.darwin.apple_sdk.frameworks.SystemConfiguration
pkgs.libiconv
]
else
[ ];
in
pkgs.mkShell {
name = "catcolab-devshell";
buildInputs =
with pkgs;
[
lld
rustToolchain
openssl
rust-analyzer
rustfmt
clippy
pkg-config
pnpm_9
nodejs_23
sqlx-cli
biome
]
++ darwinDeps
++ [
inputs.agenix.packages.${system}.agenix
inputs.deploy-rs.packages.${system}.default
inputs.crate2nix.packages.${system}.default
];
# macOS-specific environment variables for OpenSSL and pkg-config
shellHook = ''
${
if pkgs.stdenv.isDarwin then
''
export OPENSSL_DIR=${pkgs.openssl.dev}
export OPENSSL_LIB_DIR=${pkgs.openssl.out}/lib
export OPENSSL_INCLUDE_DIR=${pkgs.openssl.dev}/include
export PKG_CONFIG_PATH=${pkgs.openssl.dev}/lib/pkgconfig:$PKG_CONFIG_PATH
''
else
""
}
export PATH=$PWD/infrastructure/scripts:$PATH
# Load DATABASE_URL into the environment
if [ -f packages/backend/.env ]; then
export $(grep -v '^#' packages/backend/.env | xargs)
fi
'';
};
in
{
# Create devShells for all supported systems
devShells = builtins.listToAttrs (
map (system: {
name = system;
value = {
default = devShellForSystem system;
};
}) devShellSystems
);
# Create a NixOS configuration for each host
nixosConfigurations = {
catcolab = nixpkgs.lib.nixosSystem {
specialArgs = {
inherit inputs rustToolchain;
};
system = linuxSystem;
modules = [
./infrastructure/hosts/catcolab
agenix.nixosModules.age
];
pkgs = pkgsLinux;
};
catcolab-next = nixpkgs.lib.nixosSystem {
specialArgs = { inherit inputs rustToolchain; };
system = linuxSystem;
modules = [
./infrastructure/hosts/catcolab-next
agenix.nixosModules.age
];
pkgs = pkgsLinux;
};
};
deploy.nodes = {
catcolab = {
hostname = "backend.catcolab.org";
profiles.system = {
sshUser = "root";
path = deploy-rs.lib.${linuxSystem}.activate.nixos self.nixosConfigurations.catcolab;
};
};
catcolab-next = {
hostname = "backend-next.catcolab.org";
profiles.system = {
sshUser = "root";
path = deploy-rs.lib.${linuxSystem}.activate.nixos self.nixosConfigurations.catcolab-next;
};
};
};
};
}