diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 8c5fda6a8..7bff947ee 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -130,3 +130,27 @@ jobs: run: | postgrest-loadtest-against main ${{ steps.get-latest-tag.outputs.tag }} postgrest-loadtest-report >> "$GITHUB_STEP_SUMMARY" + + + flake: + strategy: + fail-fast: false + matrix: + runs-on: + - macos-13 # x86_64-darwin + - macos-14 # aarch64-darwin + - ubuntu-24.04 # x86_64-linux + - ubuntu-24.04-arm # aarch64-linux + name: Flake Check + runs-on: ${{ matrix.runs-on }} + steps: + - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + with: + fetch-depth: 0 + - name: Setup Nix Environment + uses: ./.github/actions/setup-nix + with: + authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}' + - name: Run flake check + run: | + nix flake check diff --git a/docs/shared/installation.rst b/docs/shared/installation.rst index c7c375083..b4e9fb196 100644 --- a/docs/shared/installation.rst +++ b/docs/shared/installation.rst @@ -28,7 +28,7 @@ pacman -S postgrest - .. tab:: Nix + .. tab:: Nix via nixpkgs You can install PostgREST from nixpkgs. @@ -36,6 +36,17 @@ nix-env -i postgrest + .. tab:: Nix via flake + + You can install PostgREST via flake. + + .. code:: nix + + { + inputs.postgrest.url = "github:postgrest/postgrest"; + # ... + } + .. group-tab:: Windows You can install PostgREST using `Chocolatey `_ or `Scoop `_. diff --git a/flake.lock b/flake.lock new file mode 100644 index 000000000..ba0150abf --- /dev/null +++ b/flake.lock @@ -0,0 +1,26 @@ +{ + "nodes": { + "nixpkgs-lib": { + "locked": { + "lastModified": 1742692082, + "narHash": "sha256-s3XOULQj7BVO7myY5V4Sob0tRZ7nRpwEOIzXg/MkD/Q=", + "owner": "nix-community", + "repo": "nixpkgs.lib", + "rev": "a09310bc940f245e51b1ffea68731244ca38f2bd", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "nixpkgs.lib", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs-lib": "nixpkgs-lib" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 000000000..f64c907c2 --- /dev/null +++ b/flake.nix @@ -0,0 +1,44 @@ +{ + description = "REST API for any Postgres database"; + + inputs = { + nixpkgs-lib.url = "github:nix-community/nixpkgs.lib"; + }; + + nixConfig = { + extra-substituters = "https://postgrest.cachix.org"; + extra-trusted-public-keys = "postgrest.cachix.org-1:icgW4R15fz1+LqvhPjt4EnX/r19AaqxiVV+1olwlZtI="; + }; + + outputs = { nixpkgs-lib, ... }: + let + systems = [ + "aarch64-darwin" + "aarch64-linux" + "x86_64-darwin" + "x86_64-linux" + ]; + + pgrstFor = system: import ./default.nix { + inherit system; + }; + + genSystems = f: nixpkgs-lib.lib.genAttrs systems (system: f (pgrstFor system)); + in + { + packages = genSystems (attrs: { + default = attrs.postgrestPackage; + profiled = attrs.postgrestProfiled; + } // nixpkgs-lib.lib.optionalAttrs (attrs ? postgrestStatic) { + static = attrs.postgrestStatic; + }); + + apps = genSystems (attrs: { + default = { + type = "app"; + program = "${attrs.postgrestStatic or attrs.postgrestPackage}/bin/postgrest"; + meta.description = "REST API for any Postgres database"; + }; + }); + }; +}