-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathflake.nix
More file actions
167 lines (158 loc) · 6.52 KB
/
flake.nix
File metadata and controls
167 lines (158 loc) · 6.52 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
{
description = "Imphnen Frontend Service - Nx Monorepo";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
};
outputs = { self, nixpkgs, flake-utils }:
let
npmDepsHash = "sha256-IcmCUGguQNIchE2m9Ggim8bo1GZt+yvnHl/pKsnlhvE=";
mkViteApp = { pkgs, src }: { name, buildScript, envVars ? {} }:
pkgs.buildNpmPackage {
pname = "imphnen-${name}";
version = "0.0.1";
inherit src npmDepsHash;
npmFlags = [ "--legacy-peer-deps" ];
makeCacheWritable = true;
nativeBuildInputs = with pkgs; [ nodejs_22 util-linux ];
buildPhase = ''
runHook preBuild
export NX_DAEMON=false HOME=$TMPDIR CI=true NO_COLOR=1 TERM=dumb
export NX_SKIP_NX_CACHE=true NX_TASKS_RUNNER_DYNAMIC_OUTPUT=false NX_NATIVE=false
${pkgs.lib.concatStringsSep "\n" (pkgs.lib.mapAttrsToList (k: v: "export ${k}=\"${v}\"") envVars)}
script -q -c "./node_modules/.bin/nx build ${name} --output-style=static" /dev/null || true
test -d dist/apps/${name}
runHook postBuild
'';
installPhase = ''
runHook preInstall
mkdir -p $out
cp -r dist/apps/${name}/* $out/
runHook postInstall
'';
dontNpmBuild = true;
};
mkLandingApp = { pkgs, src }:
pkgs.buildNpmPackage {
pname = "imphnen-landing";
version = "0.0.1";
inherit src npmDepsHash;
npmFlags = [ "--legacy-peer-deps" ];
makeCacheWritable = true;
nativeBuildInputs = with pkgs; [ nodejs_22 util-linux ];
buildPhase = ''
runHook preBuild
export NX_DAEMON=false HOME=$TMPDIR CI=true NO_COLOR=1 TERM=dumb
export NX_SKIP_NX_CACHE=true NX_TASKS_RUNNER_DYNAMIC_OUTPUT=false NX_NATIVE=false
script -q -c "./node_modules/.bin/nx build landing --output-style=static" /dev/null || true
test -d dist/apps/landing
runHook postBuild
'';
installPhase = ''
runHook preInstall
mkdir -p $out
cp -r dist/apps/landing/* $out/
runHook postInstall
'';
dontNpmBuild = true;
};
mkLandingModule = mkStaticAppModule "landing";
mkStaticAppModule = appName: { config, lib, pkgs, ... }:
let cfg = config.services."imphnen-${appName}"; in {
options.services."imphnen-${appName}" = {
enable = lib.mkEnableOption "Imphnen ${appName}";
domain = lib.mkOption { type = lib.types.str; };
package = lib.mkOption { type = lib.types.package; default = self.packages.${pkgs.system}.${appName}; };
enableSSL = lib.mkOption { type = lib.types.bool; default = true; };
extraLocations = lib.mkOption { type = lib.types.attrsOf lib.types.anything; default = {}; };
extraConfig = lib.mkOption { type = lib.types.lines; default = ""; };
};
config = lib.mkIf cfg.enable {
services.nginx = {
enable = true;
recommendedGzipSettings = true;
recommendedOptimisation = true;
recommendedProxySettings = true;
recommendedTlsSettings = true;
virtualHosts.${cfg.domain} = {
forceSSL = cfg.enableSSL;
enableACME = cfg.enableSSL;
root = cfg.package;
locations = {
"/" = { tryFiles = "$uri $uri/ /index.html"; };
"~* \\.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$" = {
tryFiles = "$uri =404";
extraConfig = ''
expires 1y;
add_header Cache-Control "public, immutable";
'';
};
} // cfg.extraLocations;
extraConfig = cfg.extraConfig;
};
};
};
};
in
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs { inherit system; };
buildViteApp = mkViteApp { inherit pkgs; src = ./.; };
in {
packages = {
backoffice = buildViteApp { name = "backoffice"; buildScript = "backoffice:build"; };
gacha = buildViteApp { name = "gacha"; buildScript = "gacha:build"; };
dimentorin = buildViteApp { name = "dimentorin"; buildScript = "dimentorin:build"; };
hackathon = buildViteApp { name = "hackathon"; buildScript = "hackathon:build"; };
infra = buildViteApp { name = "infra"; buildScript = "infra:build"; };
qrcampaign = buildViteApp { name = "qrcampaign"; buildScript = "qrcampaign:build"; };
landing = mkLandingApp { inherit pkgs; src = ./.; };
default = self.packages.${system}.landing;
};
devShells.default = pkgs.mkShell {
buildInputs = with pkgs; [ nodejs_22 bun git jq ];
shellHook = ''
export PATH="$PWD/node_modules/.bin:$PATH"
'';
};
}
) // {
nixosModules = {
landing = mkStaticAppModule "landing";
backoffice = mkStaticAppModule "backoffice";
gacha = mkStaticAppModule "gacha";
dimentorin = mkStaticAppModule "dimentorin";
hackathon = mkStaticAppModule "hackathon";
infra = mkStaticAppModule "infra";
qrcampaign = mkStaticAppModule "qrcampaign";
all = { ... }: {
imports = [
self.nixosModules.landing
self.nixosModules.backoffice
self.nixosModules.gacha
self.nixosModules.dimentorin
self.nixosModules.hackathon
self.nixosModules.infra
self.nixosModules.qrcampaign
];
};
};
overlays.default = final: prev: {
imphnen = {
landing = self.packages.${final.system}.landing;
backoffice = self.packages.${final.system}.backoffice;
gacha = self.packages.${final.system}.gacha;
dimentorin = self.packages.${final.system}.dimentorin;
hackathon = self.packages.${final.system}.hackathon;
infra = self.packages.${final.system}.infra;
qrcampaign = self.packages.${final.system}.qrcampaign;
mkHackathonWithEnv = envVars:
mkViteApp { pkgs = final; src = self; } {
name = "hackathon";
buildScript = "hackathon:build";
inherit envVars;
};
};
};
};
}