Add postgres spec.
parent
87d2e8ca33
commit
638c4d62ab
|
@ -0,0 +1,3 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
cp -r template/. "$OUT"
|
|
@ -0,0 +1,3 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
use flake
|
|
@ -0,0 +1,27 @@
|
||||||
|
# Postgres Flake Template
|
||||||
|
|
||||||
|
This is a template for constructing a working environment for local
|
||||||
|
[Postgres](https://www.postgresql.org/) (version 15.5) usage. [direnv](https://direnv.net/)
|
||||||
|
can be used to a launch a dev shell upon entering this directory (refer to
|
||||||
|
`.envrc`). Otherwise run via:
|
||||||
|
```bash
|
||||||
|
$> nix develop
|
||||||
|
```
|
||||||
|
|
||||||
|
## Quickstart
|
||||||
|
|
||||||
|
To begin, create a new database:
|
||||||
|
```bash
|
||||||
|
pg_ctl initdb
|
||||||
|
```
|
||||||
|
If the flake's default `devShell` is loaded, this will create a database cluster
|
||||||
|
at `$PWD/data`. To start the database, run the following:
|
||||||
|
```bash
|
||||||
|
pg_ctl start -o --unix_socket_directories="$PGDATA"
|
||||||
|
```
|
||||||
|
To shut the database down, run:
|
||||||
|
```bash
|
||||||
|
pg_ctl stop
|
||||||
|
```
|
||||||
|
You can also specify a different location for the database cluster using the
|
||||||
|
`-D` option in each of the above commands.
|
|
@ -0,0 +1,10 @@
|
||||||
|
(import
|
||||||
|
(
|
||||||
|
let lock = builtins.fromJSON (builtins.readFile ./flake.lock); in
|
||||||
|
fetchTarball {
|
||||||
|
url = lock.nodes.flake-compat.locked.url or "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz";
|
||||||
|
sha256 = lock.nodes.flake-compat.locked.narHash;
|
||||||
|
}
|
||||||
|
)
|
||||||
|
{ src = ./.; }
|
||||||
|
).defaultNix
|
|
@ -0,0 +1,34 @@
|
||||||
|
{
|
||||||
|
description = ''
|
||||||
|
An opinionated postgres flake.
|
||||||
|
|
||||||
|
To generate a copy of this template elsewhere, run:
|
||||||
|
$> bootstrap postgres
|
||||||
|
'';
|
||||||
|
|
||||||
|
inputs = {
|
||||||
|
flake-compat.url = "https://flakehub.com/f/edolstra/flake-compat/1.tar.gz";
|
||||||
|
flake-utils.url = "github:numtide/flake-utils";
|
||||||
|
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
|
||||||
|
};
|
||||||
|
|
||||||
|
outputs = { self, nixpkgs, flake-utils, ... }:
|
||||||
|
flake-utils.lib.eachDefaultSystem (system:
|
||||||
|
let
|
||||||
|
pkgs = nixpkgs.legacyPackages.${system};
|
||||||
|
in
|
||||||
|
{
|
||||||
|
devShells.default = pkgs.mkShell {
|
||||||
|
packages = with pkgs; [
|
||||||
|
postgresql_15
|
||||||
|
];
|
||||||
|
shellHook = ''
|
||||||
|
# The server will try to use the data directory named by this
|
||||||
|
# environment variable whenever `-D` is not specified (for e.g.
|
||||||
|
# `postgres` and `pg_ctl`).
|
||||||
|
# https://www.postgresql.org/docs/15/server-start.html
|
||||||
|
export PGDATA="$PWD/data"
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
});
|
||||||
|
}
|
Loading…
Reference in New Issue