add nix dev env
This commit is contained in:
1 parent
0de6ee4ca2
commit
f871c8c8c8
4 files changed
+232
No files matched your search
@@ -21,3 +21,8 @@ pnpm-debug.log*
|
|||||||
|
|
||||||
# jetbrains setting folder
|
# jetbrains setting folder
|
||||||
.idea/
|
.idea/
|
||||||
|
|
||||||
|
# nix/dev environment
|
||||||
|
.direnv/
|
||||||
|
.data/
|
||||||
|
result
|
||||||
Generated
+93
@@ -0,0 +1,93 @@
|
|||||||
|
{
|
||||||
|
"nodes": {
|
||||||
|
"flake-parts": {
|
||||||
|
"inputs": {
|
||||||
|
"nixpkgs-lib": "nixpkgs-lib"
|
||||||
|
},
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1790898470,
|
||||||
|
"narHash": "sha256-zTwuwezD0w3hpga6a6P8emidzAZFyWqlNeRBlpWOOl8=",
|
||||||
|
"owner": "hercules-ci",
|
||||||
|
"repo": "flake-parts",
|
||||||
|
"rev": "024633cd702b10285db5cb19b40ad48d2399ba60",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "hercules-ci",
|
||||||
|
"repo": "flake-parts",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"nixpkgs": {
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1793110635,
|
||||||
|
"narHash": "sha256-dhoW6VgFWlaodSY5jrBn+CF2FLmaUvDVgM7+C7T2+NM=",
|
||||||
|
"owner": "NixOS",
|
||||||
|
"repo": "nixpkgs",
|
||||||
|
"rev": "31ecbaca1bdefa45dffc409f0250bd8039ea0010",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "NixOS",
|
||||||
|
"ref": "nixos-unstable",
|
||||||
|
"repo": "nixpkgs",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"nixpkgs-lib": {
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1790477367,
|
||||||
|
"narHash": "sha256-oujbxmVKDhci2E4EM3KyAbRUgp5/IsCoiA/LfEF7OOk=",
|
||||||
|
"owner": "nix-community",
|
||||||
|
"repo": "nixpkgs.lib",
|
||||||
|
"rev": "f7cd230690d9fc982d06129f9189b101fddcfa3b",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "nix-community",
|
||||||
|
"repo": "nixpkgs.lib",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"process-compose-flake": {
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1791992503,
|
||||||
|
"narHash": "sha256-ak6baHPCy6SUTskWRfxdlgF5mtEfFx9kIMskKVPpaMY=",
|
||||||
|
"owner": "Platonic-Systems",
|
||||||
|
"repo": "process-compose-flake",
|
||||||
|
"rev": "8e27bc993c0156b5e033ad5889094d65fd27f623",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "Platonic-Systems",
|
||||||
|
"repo": "process-compose-flake",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"root": {
|
||||||
|
"inputs": {
|
||||||
|
"flake-parts": "flake-parts",
|
||||||
|
"nixpkgs": "nixpkgs",
|
||||||
|
"process-compose-flake": "process-compose-flake",
|
||||||
|
"services-flake": "services-flake"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"services-flake": {
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1792894486,
|
||||||
|
"narHash": "sha256-YJI+dPZ4x2gOxKljG8EANJ+HfSH8tPwLLcCKgM31XtA=",
|
||||||
|
"owner": "juspay",
|
||||||
|
"repo": "services-flake",
|
||||||
|
"rev": "e3ea146da042e8055c4ee51cda64097ccf27c32b",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "juspay",
|
||||||
|
"repo": "services-flake",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"root": "root",
|
||||||
|
"version": 7
|
||||||
|
}
|
||||||
@@ -0,0 +1,133 @@
|
|||||||
|
{
|
||||||
|
description = "CraftAttack website development environment";
|
||||||
|
|
||||||
|
inputs = {
|
||||||
|
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
|
||||||
|
|
||||||
|
flake-parts.url = "github:hercules-ci/flake-parts";
|
||||||
|
|
||||||
|
process-compose-flake.url = "github:Platonic-Systems/process-compose-flake";
|
||||||
|
|
||||||
|
services-flake.url = "github:juspay/services-flake";
|
||||||
|
};
|
||||||
|
|
||||||
|
outputs =
|
||||||
|
inputs:
|
||||||
|
inputs.flake-parts.lib.mkFlake { inherit inputs; } {
|
||||||
|
systems = [ "x86_64-linux" ];
|
||||||
|
|
||||||
|
imports = [ inputs.process-compose-flake.flakeModule ];
|
||||||
|
|
||||||
|
perSystem =
|
||||||
|
{
|
||||||
|
self',
|
||||||
|
pkgs,
|
||||||
|
lib,
|
||||||
|
...
|
||||||
|
}:
|
||||||
|
let
|
||||||
|
dbPort = 3306;
|
||||||
|
webPort = 4321;
|
||||||
|
dbName = "website";
|
||||||
|
dbUser = "website";
|
||||||
|
dbPassword = "website";
|
||||||
|
|
||||||
|
devEnv = {
|
||||||
|
DATABASE_URI = "mysql://${dbUser}:${dbPassword}@localhost:${toString dbPort}/${dbName}";
|
||||||
|
START_DATE = "2026-12-27T14:00:00";
|
||||||
|
UPLOAD_PATH = "./.data/uploads";
|
||||||
|
ADMIN_USER = "admin";
|
||||||
|
ADMIN_PASSWORD = "admin";
|
||||||
|
BASE_PATH = "/";
|
||||||
|
SERVER_IP = "localhost";
|
||||||
|
ASTRO_TELEMETRY_DISABLED = "1";
|
||||||
|
};
|
||||||
|
|
||||||
|
webRun = pkgs.writeShellApplication {
|
||||||
|
name = "web-run";
|
||||||
|
runtimeInputs = [
|
||||||
|
pkgs.nodejs_26
|
||||||
|
pkgs.curl
|
||||||
|
];
|
||||||
|
text = ''
|
||||||
|
if [ ! -d node_modules ] || [ package-lock.json -nt node_modules/.package-lock.json ]; then
|
||||||
|
npm ci
|
||||||
|
fi
|
||||||
|
|
||||||
|
exec npm run dev
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
in
|
||||||
|
{
|
||||||
|
process-compose.dev = {
|
||||||
|
imports = [ inputs.services-flake.processComposeModules.default ];
|
||||||
|
|
||||||
|
cli.preHook = "mkdir -p .data/uploads .data/logs";
|
||||||
|
|
||||||
|
defaults.processSettings = { name, ... }: {
|
||||||
|
availability.restart = lib.mkDefault "on_failure";
|
||||||
|
availability.max_restarts = lib.mkDefault 5;
|
||||||
|
log_location = lib.mkDefault ".data/logs/${name}.log";
|
||||||
|
};
|
||||||
|
|
||||||
|
settings.environment = devEnv;
|
||||||
|
|
||||||
|
services.mysql.db = {
|
||||||
|
enable = true;
|
||||||
|
package = pkgs.mariadb;
|
||||||
|
dataDir = "./.data/mariadb";
|
||||||
|
settings.mysqld = {
|
||||||
|
port = dbPort;
|
||||||
|
"bind-address" = "127.0.0.1";
|
||||||
|
};
|
||||||
|
initialDatabases = [
|
||||||
|
{
|
||||||
|
name = dbName;
|
||||||
|
schema = ./src/db/database.sql;
|
||||||
|
}
|
||||||
|
];
|
||||||
|
ensureUsers = [
|
||||||
|
{
|
||||||
|
name = dbUser;
|
||||||
|
password = dbPassword;
|
||||||
|
ensurePermissions = {
|
||||||
|
"${dbName}.*" = "ALL PRIVILEGES";
|
||||||
|
};
|
||||||
|
}
|
||||||
|
];
|
||||||
|
};
|
||||||
|
|
||||||
|
settings.processes.web = {
|
||||||
|
description = "CraftAttack website (Astro dev server)";
|
||||||
|
command = webRun;
|
||||||
|
depends_on."db-configure".condition = "process_completed_successfully";
|
||||||
|
readiness_probe.http_get = {
|
||||||
|
host = "127.0.0.1";
|
||||||
|
port = webPort;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
devShells.default = pkgs.mkShell {
|
||||||
|
packages = [
|
||||||
|
pkgs.nodejs_26
|
||||||
|
pkgs.mariadb
|
||||||
|
pkgs.curl
|
||||||
|
self'.packages.dev
|
||||||
|
pkgs.nixfmt
|
||||||
|
];
|
||||||
|
|
||||||
|
env = devEnv;
|
||||||
|
|
||||||
|
shellHook = ''
|
||||||
|
mkdir -p .data/uploads
|
||||||
|
echo "CraftAttack dev shell: run \`dev\` (or \`nix run .#dev\`) to start MariaDB + Astro." >&2
|
||||||
|
echo "MariaDB: mysql://${dbUser}:${dbPassword}@localhost:${toString dbPort}/${dbName}" >&2
|
||||||
|
echo "Reset database: rm -rf .data" >&2
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
formatter = pkgs.nixfmt;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
Reference in new issue
Block a user