feat: add Nix flake for reproducible builds and deployment

- Add flake.nix with packages for all 5 apps (landing, gacha, backoffice, dimentorin, hackathon)
- Add NixOS modules for deployment (systemd service for Next.js, nginx for Vite apps)
- Add mkHackathonWithEnv function for build-time environment variables
- Add development shell with Node.js 22, npm, bun

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
maulanasdqn
2026-01-21 10:02:46 +07:00
co-authored by Claude Opus 4.5
parent f77967a092
commit 5be9ec1edf
7 changed files with 447 additions and 0 deletions
+83
View File
@@ -0,0 +1,83 @@
# NixOS Module for Imphnen Landing
{ self }:
{ config, lib, pkgs, ... }:
let
cfg = config.services.imphnen-landing;
in {
options.services.imphnen-landing = {
enable = lib.mkEnableOption "Imphnen Landing Page";
port = lib.mkOption {
type = lib.types.port;
default = 3000;
description = "Port to run the landing server on";
};
hostname = lib.mkOption {
type = lib.types.str;
default = "0.0.0.0";
description = "Hostname to bind to";
};
package = lib.mkOption {
type = lib.types.package;
default = self.packages.${pkgs.system}.landing;
description = "The landing package to use";
};
openFirewall = lib.mkOption {
type = lib.types.bool;
default = false;
description = "Open firewall for the landing port";
};
environmentFile = lib.mkOption {
type = lib.types.nullOr lib.types.path;
default = null;
description = "Environment file for secrets";
};
};
config = lib.mkIf cfg.enable {
systemd.services.imphnen-landing = {
description = "Imphnen Landing Page";
wantedBy = [ "multi-user.target" ];
after = [ "network.target" ];
environment = {
NODE_ENV = "production";
PORT = toString cfg.port;
HOSTNAME = cfg.hostname;
};
serviceConfig = {
Type = "simple";
ExecStart = "${cfg.package}/bin/imphnen-landing";
Restart = "on-failure";
RestartSec = "5s";
# Hardening
DynamicUser = true;
NoNewPrivileges = true;
ProtectSystem = "strict";
ProtectHome = true;
PrivateTmp = true;
ProtectKernelTunables = true;
ProtectKernelModules = true;
ProtectControlGroups = true;
RestrictAddressFamilies = [ "AF_INET" "AF_INET6" "AF_UNIX" ];
RestrictNamespaces = true;
LockPersonality = true;
MemoryDenyWriteExecute = true;
RestrictRealtime = true;
RestrictSUIDSGID = true;
} // lib.optionalAttrs (cfg.environmentFile != null) {
EnvironmentFile = cfg.environmentFile;
};
};
networking.firewall.allowedTCPPorts = lib.mkIf cfg.openFirewall [ cfg.port ];
};
}
+76
View File
@@ -0,0 +1,76 @@
# NixOS Module for Static Vite Apps (nginx-based)
{ self }:
{ 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;
description = "Domain name for the app";
};
package = lib.mkOption {
type = lib.types.package;
default = self.packages.${pkgs.system}.${appName};
description = "The ${appName} package to use";
};
enableSSL = lib.mkOption {
type = lib.types.bool;
default = true;
description = "Enable ACME SSL";
};
extraLocations = lib.mkOption {
type = lib.types.attrsOf lib.types.anything;
default = {};
description = "Additional nginx locations";
};
extraConfig = lib.mkOption {
type = lib.types.lines;
default = "";
description = "Extra nginx configuration";
};
};
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";
};
# Cache static assets
"~* \\.(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;
};
};
};
}