Added nix

This commit is contained in:
2025-12-25 23:38:40 -07:00
parent 455c3dbd9a
commit 13821cbcd5
4 changed files with 83 additions and 3 deletions

1
.envrc Normal file
View File

@@ -0,0 +1 @@
use flake

27
flake.lock generated Normal file
View File

@@ -0,0 +1,27 @@
{
"nodes": {
"nixpkgs": {
"locked": {
"lastModified": 1766622938,
"narHash": "sha256-Eovt/DOCYjFFBZuYbbG9j5jhklzxdNbUGVYYxh3lG3s=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "5900a0a8850cbba98e16d5a7a6ed389402dfcf4f",
"type": "github"
},
"original": {
"owner": "nixos",
"ref": "nixos-25.11",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"nixpkgs": "nixpkgs"
}
}
},
"root": "root",
"version": 7
}

38
flake.nix Normal file
View File

@@ -0,0 +1,38 @@
{
description = "Zamaan dev shell";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-25.11";
};
outputs = { self, nixpkgs }:
let
allSystems = [
"x86_64-linux"
"aarch64-linux"
"x86_64-darwin"
"aarch64-darwin"
];
forAllSystems = f: nixpkgs.lib.genAttrs allSystems (system: f {
pkgs = import nixpkgs { inherit system; };
});
in
{
devShells = forAllSystems ({ pkgs }: {
default = pkgs.mkShell {
packages = with pkgs; [
nodejs_24
nodePackages.pnpm
sqlite
];
shellHook = ''
echo "Zamaan dev shell"
echo "Node version: $(node --version)"
echo "pnpm version: $(pnpm --version)"
'';
};
});
};
}

View File

@@ -3,6 +3,20 @@ import { drizzle } from 'drizzle-orm/better-sqlite3';
import * as schema from './schema'; import * as schema from './schema';
import path from 'path'; import path from 'path';
let _db: ReturnType<typeof drizzle> | null = null;
function initDb() {
if (!_db) {
const dbUrl = process.env.DATABASE_URL || path.resolve(process.cwd(), 'zamaan.db'); const dbUrl = process.env.DATABASE_URL || path.resolve(process.cwd(), 'zamaan.db');
const sqlite = new Database(dbUrl, { readonly: false }); const sqlite = new Database(dbUrl, { readonly: false });
export const db = drizzle(sqlite, { schema }); _db = drizzle(sqlite, { schema });
}
return _db;
}
export const db = new Proxy({} as ReturnType<typeof drizzle>, {
get(_target, prop) {
const database = initDb();
return database[prop as keyof typeof database];
}
});