Skip to content

Commit 57a41b6

Browse files
authored
Nix/fix mkdocs (#2053)
* fix: nix/doc build from devshell Adding the documentation virtual env to the devshell packages creates a conflict on pygmentize with the existing python viruatlenv. > pkgs.buildEnv error: two given paths contain a conflicting subpath: > `/nix/store/kvryivzraaa1cw1j3r9zslng9n8nf8lw-python3-3.13.11-env/bin/pygmentize' and > `/nix/store/yag41lb6wzdj5vh0ikjf072ycf546cc2-python3-3.13.11-env/bin/pygmentize' > hint: this may be caused by two different versions of the same package in buildEnv's `paths` parameter > hint: `pkgs.nix-diff` can be used to compare derivations Instead of authorizing the conflicts in this devshell buildEnv, we prefer hiding the doc devenv in a separate command to make sure nothing unexpectally breaks on a nixpkgs update in the future. * fix: nix/doc various nix doc md format issues The list rendering was broken in a few places. Adding some minor visual tweaks as well. * fix: nix/doc add links to orphan pages * fix: nix/doc, remove dead links mkdocs do not support linking to source files living outside of the doc repository. Replacing these dead links with quoted paths.
1 parent 21338c8 commit 57a41b6

12 files changed

Lines changed: 86 additions & 59 deletions

nix/devShells.nix

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -32,28 +32,28 @@
3232
export HISTFILE=.history
3333
'';
3434
};
35+
docvenv = pkgs.python3.buildEnv.override {
36+
extraLibs = self'.packages.docs.nativeBuildInputs;
37+
};
3538
in
3639
{
3740
devShells = {
3841
default = pkgs.devshell.mkShell {
39-
packages =
40-
with pkgs;
41-
[
42-
coreutils
43-
just
44-
nix-update
45-
#pg_prove
46-
shellcheck
47-
ansible
48-
ansible-lint
49-
aws-vault
50-
packer
51-
dbmate
52-
nushell
53-
pythonEnv
54-
config.treefmt.build.wrapper
55-
]
56-
++ self'.packages.docs.nativeBuildInputs;
42+
packages = with pkgs; [
43+
coreutils
44+
just
45+
nix-update
46+
#pg_prove
47+
shellcheck
48+
ansible
49+
ansible-lint
50+
aws-vault
51+
packer
52+
dbmate
53+
nushell
54+
pythonEnv
55+
config.treefmt.build.wrapper
56+
];
5757
devshell.startup.pre-commit.text = config.pre-commit.installationScript;
5858
commands = [
5959
{
@@ -74,6 +74,12 @@
7474
command = "pre-commit run --all-files";
7575
category = "check";
7676
}
77+
{
78+
name = "serve-nix-doc";
79+
help = "Spin up a server exposing the nix documentation";
80+
command = "pushd $(git rev-parse --show-toplevel)/nix && ${docvenv}/bin/mkdocs serve -o";
81+
category = "doc";
82+
}
7783
{
7884
name = "watch";
7985
help = "Watch for file changes and run all checks";

nix/docs/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,19 @@ learn how to play with `postgres` in the [build guide](./build-postgres.md).
1818
- **[Receipt Files](./receipt-files.md)** - Understanding build receipts
1919
- **[Start Client/Server](./start-client-server.md)** - Running PostgreSQL client and server
2020
- **[Docker](./docker.md)** - Docker integration and usage
21+
- **[Docker Image Size Analyzer](./image-size-analyzer-usage.md)** - Tool to analyze the Docker image sizes
2122
- **[Use direnv](./use-direnv.md)** - Development environment with direnv
2223
- **[Pre-commit Hooks](./pre-commit-hooks.md)** - Automatic formatting and code checks before commits
2324
- **[Nix Formatter](./nix-formatter.md)** - Code formatting with treefmt
25+
- **[Create a New pgrx Extension](./creating-pgrx-extension.md)** - How to set up a new cargo pgrx extension
26+
- **[Updating pgrx Extensions](./updating-pgrx-extensions.md)** - How to upgrade the cargo pgrx extensions
27+
- **[Receipt Files](./receipt-files.md)** - Understand what receipt files are
2428

2529
## Package Management
2630

2731
- **[Adding New Packages](./adding-new-package.md)** - How to add new PostgreSQL extensions
2832
- **[Update Extensions](./update-extension.md)** - How to update existing extensions
33+
- **[Update Nix Dependecies](./updating-dependencies.md)** - How to update the Nix dependencies
2934
- **[New Major PostgreSQL](./new-major-postgres.md)** - Adding support for new PostgreSQL versions
3035
- **[Nix Overlays](./nix-overlays.md)** - Understanding and using Nix overlays
3136

@@ -34,6 +39,7 @@ learn how to play with `postgres` in the [build guide](./build-postgres.md).
3439
- **[Adding Tests](./adding-tests.md)** - How to add tests for extensions
3540
- **[Migration Tests](./migration-tests.md)** - Testing database migrations
3641
- **[Testing PG Upgrade Scripts](./testing-pg-upgrade-scripts.md)** - Testing PostgreSQL upgrades
42+
- **[Docker Image testing](./docker-testing.md)** - How to test the docker images against the pg_regress test suite.
3743

3844
## Reference
3945

nix/docs/adding-tests.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ There are basically two types of tests you can add:
55
- Migration tests.
66

77
In all cases, a number of extensions may be installed into the database for
8-
use; you can see those in both [postgresql.conf.in](../tests/postgresql.conf.in)
9-
and [prime.sql](../tests/prime.sql) (extensions may be enabled in either place.)
8+
use; you can see those in both `/nix/tests/postgresql.conf.in`
9+
and `/nix/tests/prime.sql` (extensions may be enabled in either place.)
1010

1111
## pg\_regress tests
1212

13-
pg\_regress tests are in [tests/sql](./../tests/sql/) with output in [tests/expected](./../tests/expected/).
14-
To create a new test, create a new SQL file in [tests/sql](./../tests/sql/)
13+
pg\_regress tests are in `/nix/tests/sql/` with output in `/nix/tests/expected/`.
14+
To create a new test, create a new SQL file in `/nix/tests/sql/`.
1515

1616
Next, for each current major version of postgres, we run a "flake check" build one at a time.
1717

@@ -29,8 +29,8 @@ Next, review the logs to identify where the test output was written
2929

3030
```
3131
postgres> CREATE EXTENSION IF NOT EXISTS index_advisor;
32-
postgres> CREATE EXTENSION
33-
postgres> (using postmaster on localhost, port 5432)
32+
postgres> CREATE EXTENSION
33+
postgres> (using postmaster on localhost, port 5432)
3434
postgres> ============== running regression test queries ==============
3535
postgres> test new_test ... diff: /nix/store/5gk419ddz7mzzwhc9j6yj5i8lkw67pdl-tests/expected/new_test.out: No such file or directory
3636
postgres> diff command failed with status 512: diff "/nix/store/5gk419ddz7mzzwhc9j6yj5i8lkw67pdl-tests/expected/new_test.out" "/nix/store/2fbrvnnr7iz6yigyf0rb0vxnyqvrgxzp-postgres-15.6-check-harness/regression_output/results/new_test.out" > "/nix/store/2fbrvnnr7iz6yigyf0rb0vxnyqvrgxzp-postgres-15.6-check-harness/regression_output/results/new_test.out.diff
@@ -44,15 +44,15 @@ cp -r /nix/store/2fbrvnnr7iz6yigyf0rb0vxnyqvrgxzp-postgres-15.6-check-harness/re
4444

4545
Then you can review the contents of `regression_output/results/new_test.out` to see if it matches what you expected.
4646

47-
If it does match your expectations, copy the file to [tests/expected](./../tests/expected/) and the test will pass on the next run.
47+
If it does match your expectations, copy the file to `/nix/tests/expected/` and the test will pass on the next run.
4848

4949
If the output does not match your expectations, update the `<new_test>.sql` file, re-run with `nix flake check -L` and try again
5050

5151

5252
## pgTAP tests
5353

5454
These are super easy: simply add `.sql` files to the
55-
[tests/smoke](./../tests/smoke/) directory, then:
55+
`/nix/tests/smoke/` directory, then:
5656

5757
```
5858
nix flake check -L
@@ -100,7 +100,7 @@ extension authors), step 3 isn't guaranteed, so that's what the whole idea is
100100
designed to test.
101101

102102
To add data into the database, modify the
103-
[data.sql](../nix/tests/migrations/data.sql) script and add whatever you want into
103+
`/nix/tests/migrations/data.sql` script and add whatever you want into
104104
it. This script gets loaded into the old version of the database at startup, and
105105
it's expected that the new version of the database can handle it.
106106

nix/docs/development-workflow.md

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,14 @@ nix run .#trigger-nix-build
2020
```
2121

2222
This will:
23+
2324
- Trigger a GitHub Actions workflow
2425
- Build PostgreSQL and extensions
2526
- Run nix flake check tests (evaluation of nix code, pg_regress and migrations tests)
2627
- Cache the results in the Supabase Nix binary cache
2728
- Watch the workflow progress until completion
2829

29-
The workflow will run on the branch you're currently on.
30+
The workflow will run on the branch you're currently on.
3031

3132
If you're on a feature different branch, you'll be prompted to confirm before proceeding.
3233

@@ -46,6 +47,7 @@ aws-vault exec <profile-name> -- nix run .#build-test-ami orioledb-17
4647
```
4748

4849
This will:
50+
4951
- Build two AMI stages using Packer
5052
- Clean up temporary instances after AMI builds
5153
- Output the final AMI name (e.g., `supabase-postgres-abc123`)
@@ -62,13 +64,15 @@ nix run .#run-testinfra -- --aws-vault-profile <profile-name> --ami-name supabas
6264
```
6365

6466
This will:
67+
6568
- Create a Python virtual environment
6669
- Install required Python packages
6770
- Create an EC2 instance from the AMI
6871
- Run the test suite
6972
- Automatically terminate the EC2 instance when done
7073

7174
The script handles:
75+
7276
- Setting up AWS credentials via aws-vault
7377
- Creating and managing the Python virtual environment
7478
- Running the tests
@@ -85,6 +89,7 @@ aws-vault exec <profile-name> -- nix run .#cleanup-ami supabase-postgres-abc123
8589
```
8690

8791
This will:
92+
8893
- Deregister the AMI
8994
- Clean up any associated resources
9095

@@ -109,26 +114,29 @@ This will:
109114
### Environment Variables
110115

111116
The following environment variables are used:
117+
112118
- `AWS_VAULT`: AWS Vault profile name (default: staging)
113119
- `AWS_REGION`: AWS region (default: ap-southeast-1)
114120
- `AMI_NAME`: Name of the AMI to test
115121

116122
## Best Practices
117123

118124
1. **Branch Management**
119-
- Use feature branches for development
120-
- Merge to develop for testing
121-
- Use release branches for version-specific changes
125+
126+
- Use feature branches for development
127+
- Merge to develop for testing
128+
- Use release branches for version-specific changes
122129

123130
2. **Resource Cleanup**
124-
- Always run the cleanup step after testing
125-
- Monitor AWS console for any lingering resources
126-
- Use the cleanup-ami command when done with an AMI
131+
132+
- Always run the cleanup step after testing
133+
- Monitor AWS console for any lingering resources
134+
- Use the cleanup-ami command when done with an AMI
127135

128136
3. **Testing**
129-
- Run tests locally before pushing changes
130-
- Verify AMI builds before running testinfra
131-
- Check test output for any warnings or errors
137+
- Run tests locally before pushing changes
138+
- Verify AMI builds before running testinfra
139+
- Check test output for any warnings or errors
132140

133141
## Additional Commands
134142

@@ -138,4 +146,4 @@ nix run .#show-commands
138146

139147
# Update README with latest command information
140148
nix run .#update-readme
141-
```
149+
```

nix/docs/documentation.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ We are using markdown for documentation in the `nix/docs` directory, which is re
77
To generate the documentation locally, you can use the following command in a development shell:
88

99
```bash
10-
cd nix
11-
mkdocs serve
10+
serve-nix-doc
1211
```
1312

1413
This will start a local server at `http://localhost:8000` where you can view the documentation.

nix/docs/nix-formatter.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,20 @@ This repository uses [treefmt](https://treefmt.com/) with [nixfmt](https://githu
77
### nixfmt-rfc-style
88

99
- **Purpose**: Formats Nix code according to [RFC 166](https://github.com/NixOS/rfcs/blob/master/rfcs/0166-nix-formatting.md) style guidelines
10-
- **What it does**:
10+
- **What it does**:
1111

12-
- Standardizes indentation and spacing
13-
- Formats function calls and attribute sets consistently
14-
- Ensures consistent line breaks and alignment
12+
- Standardizes indentation and spacing
13+
- Formats function calls and attribute sets consistently
14+
- Ensures consistent line breaks and alignment
1515

1616
### deadnix
1717

1818
- **Purpose**: Removes unused/dead code from Nix expressions
1919
- **What it does**:
2020

21-
- Identifies unused variables and bindings
22-
- Removes unused function arguments
23-
- Cleans up dead code paths
21+
- Identifies unused variables and bindings
22+
- Removes unused function arguments
23+
- Cleans up dead code paths
2424

2525
## Usage
2626

nix/docs/nix-overlays.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Overlays are a feature of Nixpkgs that allow you to:
88
disabled-by-default feature.
99

1010
First, you need to define a file for the overlay under
11-
[overlays/](../overlays/), and then import it in `nix/overlays/default.nix`. There is an
11+
`/nix/overlays/`, and then import it in `nix/overlays/default.nix`. There is an
1212
example pull request in
1313
[#14](https://github.com/supabase/nix-postgres/issues/14) for this; an overlay
1414
typically looks like this:

nix/docs/receipt-files.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# Receipt Files
2+
13
Every time you run `nix build` on this repository to build PostgreSQL, the
24
installation directory comes with a _receipt_ file that tells you what's inside
35
of it. Primarily, this tells you:

nix/docs/start-client-server.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
If you want to run a postgres server, just do this from the root of the
44
repository:
55

6-
```
6+
```bash
77
nix run .#start-server 15
88
```
99

@@ -15,7 +15,7 @@ Actually, you don't even need the repository. You can do this from arbitrary
1515
directories, if the left-hand side of the hash character (`.` in this case) is a
1616
valid "flake reference":
1717

18-
```
18+
```bash
1919
# from any arbitrary directory
2020
nix run github:supabase/postgres#start-server 15
2121
```
@@ -26,7 +26,7 @@ Let's say you want to use a PostgreSQL build from a specific version of the
2626
repository. You can change the syntax of the above to use _any_ version of the
2727
repository, at any time, by adding the commit hash after the repository name:
2828

29-
```
29+
```bash
3030
# use postgresql 15 build at commit <some commit hash>
3131
nix run github:supabase/postgres/<some commit hash>#start-server 15
3232
```
@@ -36,7 +36,7 @@ nix run github:supabase/postgres/<some commit hash>#start-server 15
3636
All of the same rules apply, but try using `start-client` on the right-hand side
3737
of the hash character, instead. For example:
3838

39-
```
39+
```bash
4040
nix run github:supabase/postgres#start-server 15 &
4141
sleep 5
4242
nix run github:supabase/postgres#start-client 16
@@ -52,7 +52,7 @@ To start a replica you can use the `start-postgres-replica` command.
5252

5353
First start a server and a couple of replicas:
5454

55-
```
55+
```bash
5656
$ start-postgres-server 15 5435
5757

5858
$ start-postgres-replica 15 5439
@@ -62,7 +62,7 @@ $ start-postgres-replica 15 5440
6262

6363
Now check the master server:
6464

65-
```
65+
```bash
6666
$ start-postgres-client 15 5435
6767
```
6868

@@ -80,7 +80,7 @@ create table items as select x::int from generate_series(1,100) x;
8080

8181
And a replica:
8282

83-
```
83+
```bash
8484
$ start-postgres-client 15 5439
8585
```
8686

nix/docs/update-extension.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
# Update an existing nix extension
32

43
## Overview
@@ -107,7 +106,7 @@ These extensions use `mkPgrxExtension` and require additional Rust and pgrx vers
107106

108107
Nix build will fail and print the correct hash. Update the `hash` field in `versions.json`.
109108

110-
If needed, you can access the extension name by running the command `nix flake show`
109+
If needed, you can access the extension name by running the command `nix flake show`
111110

112111
4. **Update `previouslyPackagedVersions`** in the extension's `default.nix` file:
113112

0 commit comments

Comments
 (0)