-
Notifications
You must be signed in to change notification settings - Fork 0
/
flake.nix
141 lines (125 loc) · 5.99 KB
/
flake.nix
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
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
devenv.url = "github:cachix/devenv";
};
outputs = { self, nixpkgs, devenv, ... } @ inputs:
let
systems = [ "x86_64-linux" "x86_64-darwin" "aarch64-linux" "aarch64-darwin" ];
forAllSystems = f: builtins.listToAttrs (map (name: { inherit name; value = f name; }) systems);
in
{
devShells = forAllSystems (system:
let
pkgs = nixpkgs.legacyPackages.${system};
bashPkg = pkgs.bashInteractive;
nodejsPkg = pkgs.nodejs-18_x;
in
{
default = devenv.lib.mkShell {
inherit inputs pkgs;
modules = [
{
# Languages
# https://devenv.sh/reference/options
languages = {
# Languages - JavaScript - Enable
# https://devenv.sh/reference/options/#languagesjavascriptenable
javascript.enable = true;
# Languages - JavaScript - Package
# https://devenv.sh/reference/options/#languagesjavascriptpackage
javascript.package = nodejsPkg;
# Languages - TypeScript - Enable
# https://devenv.sh/reference/options/#languagestypescriptenable
typescript.enable = true;
};
# Services
# https://devenv.sh/reference/options
services = {
# Services - PostgreSQL
# https://devenv.sh/reference/options/#servicespostgresenable
postgres = {
# Services - PostgreSQL - Enable
# https://devenv.sh/reference/options/#servicespostgresenable
enable = true;
# Services - PostgreSQL - Packages
# https://devenv.sh/reference/options/#servicespostgrespackage
package = pkgs.postgresql_14.withPackages (p: [ p.postgis p.pg_cron p.timescaledb p.pg_partman ]);
# Services - PostgreSQL - Initial Script
# https://devenv.sh/reference/options/#servicespostgresinitialscript
initialScript = ''
CREATE USER postgres SUPERUSER;
'';
# Services - PostgreSQL - Initial Databases
# https://devenv.sh/reference/options/#servicespostgresinitialdatabases
initialDatabases = [
{ name = "postgres"; }
];
# Services - PostgreSQL - Host / Listen Address
# https://devenv.sh/reference/options/#servicespostgreslisten_addresses
listen_addresses = "127.0.0.1";
# Services - PostgreSQL - Port
# https://devenv.sh/reference/options/#servicespostgresport
port = 5555;
# Services - PostgreSQL - Settings
# https://devenv.sh/reference/options/#servicespostgressettings
settings = {
# Configuration
log_connections = true;
log_disconnections = true;
log_duration = true;
log_timezone = "UTC";
log_statement = "all";
log_directory = "pg_log";
log_filename = "postgresql-%Y-%m-%d_%H%M%S.log";
# Logging Collector
logging_collector = true;
log_min_messages = "warning";
log_min_error_statement = "error";
log_min_duration_statement = 100; # ms
};
};
};
# Packages
# https://devenv.sh/reference/options/#packages
# https://search.nixos.org/packages?channel=unstable
packages = [
# Bash - Shell
bashPkg
# Tiny Web Server
pkgs.microserver
# NodeJS LTS 18
nodejsPkg
# NodeJS Packages - PNPM & CDKTF CLI
pkgs.nodePackages.pnpm
pkgs.nodePackages.cdktf-cli
# Terraform - Infrastructure As Code
pkgs.terraform
pkgs.terraform-ls
pkgs.terraform-providers.aws
# Utilities
pkgs.zip
];
enterShell = ''
echo "***************************************************************"
echo "Project: serverless-starter "
echo "Bash: ${bashPkg.name} "
echo "NodeJS: ${nodejsPkg.name} "
echo "PostgreSQL: ${pkgs.postgresql_14.name} "
echo "Terraform: ${pkgs.terraform.name} "
echo "Terraform CDK: ${pkgs.nodePackages.cdktf-cli.name} "
echo "Microserver: ${pkgs.microserver.name} "
echo "Zip: ${pkgs.zip.name} "
echo "***************************************************************"
echo "Dev Environment Commands: "
echo "devenv version: devenv version output "
echo "devenv up: starts services (e.g. PostgreSQL DB) "
echo "***************************************************************"
'';
}
];
};
}
);
};
}