Created
June 20, 2024 13:44
-
-
Save 0x61nas/37f0a63d95945ff4df1e4e3ade7a88e8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
description = "NextJS Template"; | |
inputs = { | |
nixpkgs.url = "nixpkgs"; | |
systems.url = "github:nix-systems/x86_64-linux"; | |
utils = { | |
url = "github:numtide/flake-utils"; | |
inputs.systems.follows = "systems"; | |
}; | |
devenv.url = "github:cachix/devenv"; | |
}; | |
nixConfig = { | |
extra-trusted-public-keys = "devenv.cachix.org-1:w1cLUi8dv3hnoSPGAuibQv+f9TZLr6cv/Hm9XgU50cw="; | |
extra-substituters = "https://devenv.cachix.org"; | |
}; | |
outputs = | |
{ self | |
, nixpkgs | |
, utils | |
, devenv | |
, ... | |
}@inputs: | |
utils.lib.eachDefaultSystem (system: | |
let | |
pkgs = nixpkgs.legacyPackages.${system}; | |
pname = "mentor-ai-platform"; # <same as package.json name> | |
version = "0.1.0"; | |
db = { | |
enable = true; | |
host = "127.0.0.1"; | |
port = 5432; | |
name = "${pname}-db"; | |
user = "postgres"; | |
}; | |
buildInputs = with pkgs; [ | |
nodejs_20 | |
nodePackages_latest.pnpm | |
pre-commit | |
]; | |
nativeBuildInputs = buildInputs; | |
devPkgs = with pkgs; [ | |
pre-commit | |
just | |
]; | |
in | |
rec { | |
devShells.default = devenv.lib.mkShell { | |
inherit inputs pkgs buildInputs nativeBuildInputs; | |
modules = [ | |
({ lib, pkgs, config, ... }: { | |
env = { | |
DATABASE_URL = "postgresql://${db.user}@${db.host}:${toString(db.port)}/${db.name}"; | |
}; | |
packages = devPkgs; | |
services.postgres = { | |
enable = db.enable; | |
package = pkgs.postgresql_16; | |
initialDatabases = [{ name = db.name; }]; | |
initialScript = '' | |
CREATE USER ${db.user} SUPERUSER; | |
''; | |
listen_addresses = db.host; | |
port = db.port; | |
}; | |
# pre-commit.hooks = { | |
# prettier = { | |
# enable = true; | |
# excludes = [ "pnpm-lock.yaml" "flake.lock" ]; | |
# settings = { | |
# configPath = ".prettierrc"; | |
# }; | |
# }; | |
# builder = { | |
# enable = true; | |
# name = "builder"; | |
# description = "build before push"; | |
# entry = "${pkgs.nodePackages_latest.pnpm}/bin/pnpm run build"; | |
# stages = [ "pre-push" ]; | |
# pass_filenames = false; | |
# }; | |
# }; | |
dotenv = { | |
enable = true; | |
filename = [ ".env.local" ".env" ]; | |
}; | |
processes = { | |
pgAdmin = lib.mkIf db.enable { | |
exec = "${pkgs.pgadmin4-desktopmode}/bin/pgadmin4"; | |
}; | |
next = { | |
exec = "${pkgs.nodePackages_latest.pnpm}/bin/pnpm run dev"; | |
}; | |
}; | |
# enterShell = '' | |
# #!/usr/bin/env bash | |
# if ! grep -q "pre-commit" .git/hooks/pre-commit 2>/dev/null; then | |
# pre-commit install | |
# fi | |
# | |
# ${pkgs.nodePackages_latest.pnpm}/bin/pnpm i | |
# | |
# bin=${pkgs.tmux}/bin/tmux | |
# $bin new-session -As "${pname}:1" -n code -d "${pkgs.neovim}/bin/nvim ." | |
# $bin new-window -t "${pname}:2" -n shell | |
# $bin new-window -t "${pname}:3" -n processes devenv up | |
# | |
# $bin attach -t${pname}:1 | |
# ''; | |
}) | |
]; | |
}; | |
packages = rec { | |
devenv-up = self.devShells.${system}.default.config.procfileScript; | |
# Executed by `nix build` | |
default = devenv-up; | |
}; | |
# Executed by `nix run` | |
apps.default = utils.lib.mkApp { | |
drv = packages.default; | |
}; | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment