From 149be6bc33f37e9c55a247b2538c22fd14216ad4 Mon Sep 17 00:00:00 2001 From: Wolfgang Walther Date: Mon, 24 Mar 2025 14:12:05 +0100 Subject: [PATCH] nix: expose nixpkgs input on flake This also moves the pin for nixpkgs into flake.lock instead of our custom file. Even for the classic interface via default.nix, the pin will be loaded from flake.lock, thus everything stays in-sync. --- default.nix | 14 ++++++--- flake.lock | 19 ++++++------ flake.nix | 14 ++++++--- nix/README.md | 6 ++-- nix/nixpkgs-version.nix | 9 ------ nix/tools/nixpkgsTools.nix | 62 -------------------------------------- shell.nix | 1 - 7 files changed, 31 insertions(+), 94 deletions(-) delete mode 100644 nix/nixpkgs-version.nix delete mode 100644 nix/tools/nixpkgsTools.nix diff --git a/default.nix b/default.nix index b5f0cd15d..1ce8e5977 100644 --- a/default.nix +++ b/default.nix @@ -3,7 +3,15 @@ , compiler ? "ghc948" , # Commit of the Nixpkgs repository that we want to use. - nixpkgsVersion ? import nix/nixpkgs-version.nix + # It defaults to reading the inputs from flake.lock, which serves + # as a compatibility layer for non-flake builds / default.nix / shell.nix. + nixpkgsVersion ? let + lock = builtins.fromJSON (builtins.readFile ./flake.lock); + in + { + inherit (lock.nodes.nixpkgs.locked) owner repo rev; + tarballHash = lock.nodes.nixpkgs.locked.narHash; + } , # Nix files that describe the Nixpkgs repository. We evaluate the expression # using `import` below. @@ -119,10 +127,6 @@ rec { memory = pkgs.callPackage nix/tools/memory.nix { inherit postgrestProfiled withTools; }; - # Utility for updating the pinned version of Nixpkgs. - nixpkgsTools = - pkgs.callPackage nix/tools/nixpkgsTools.nix { }; - # Scripts for publishing new releases. release = pkgs.callPackage nix/tools/release.nix { }; diff --git a/flake.lock b/flake.lock index ba0150abf..9994726e2 100644 --- a/flake.lock +++ b/flake.lock @@ -1,23 +1,24 @@ { "nodes": { - "nixpkgs-lib": { + "nixpkgs": { "locked": { - "lastModified": 1742692082, - "narHash": "sha256-s3XOULQj7BVO7myY5V4Sob0tRZ7nRpwEOIzXg/MkD/Q=", - "owner": "nix-community", - "repo": "nixpkgs.lib", - "rev": "a09310bc940f245e51b1ffea68731244ca38f2bd", + "lastModified": 1731165248, + "narHash": "sha256-DiHFKIdBmMx5/DUARhVqaxvEIiy4EE6Eqs9Qs4oxme8=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "a90280100f41a10914edfe729a4053e60c92b8e3", "type": "github" }, "original": { - "owner": "nix-community", - "repo": "nixpkgs.lib", + "owner": "nixos", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", "type": "github" } }, "root": { "inputs": { - "nixpkgs-lib": "nixpkgs-lib" + "nixpkgs": "nixpkgs" } } }, diff --git a/flake.nix b/flake.nix index f64c907c2..24f4c50f2 100644 --- a/flake.nix +++ b/flake.nix @@ -2,7 +2,7 @@ description = "REST API for any Postgres database"; inputs = { - nixpkgs-lib.url = "github:nix-community/nixpkgs.lib"; + nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable"; }; nixConfig = { @@ -10,7 +10,7 @@ extra-trusted-public-keys = "postgrest.cachix.org-1:icgW4R15fz1+LqvhPjt4EnX/r19AaqxiVV+1olwlZtI="; }; - outputs = { nixpkgs-lib, ... }: + outputs = { nixpkgs, ... }: let systems = [ "aarch64-darwin" @@ -21,15 +21,21 @@ pgrstFor = system: import ./default.nix { inherit system; + nixpkgsVersion = { + owner = "nixos"; + repo = "nixpkgs"; + inherit (nixpkgs) rev; + tarballHash = nixpkgs.narHash; + }; }; - genSystems = f: nixpkgs-lib.lib.genAttrs systems (system: f (pgrstFor system)); + genSystems = f: nixpkgs.lib.genAttrs systems (system: f (pgrstFor system)); in { packages = genSystems (attrs: { default = attrs.postgrestPackage; profiled = attrs.postgrestProfiled; - } // nixpkgs-lib.lib.optionalAttrs (attrs ? postgrestStatic) { + } // nixpkgs.lib.optionalAttrs (attrs ? postgrestStatic) { static = attrs.postgrestStatic; }); diff --git a/nix/README.md b/nix/README.md index c138a3cb0..9b5798d10 100644 --- a/nix/README.md +++ b/nix/README.md @@ -379,10 +379,8 @@ that). We also use `default.nix` to load our pinned version of the `nixpkgs` repository. This set of packages will always be the same, independently from -where or when you use it. The pinned version can be upgraded with the small -`nixpkgs-upgrade` utility. Running `nixpkgs-upgrade > nix/nixpkgs-version.nix` -in `nix-shell` will upgrade the pinned version to the latest `nixpkgs-unstable` -version. +where or when you use it. The pinned version is taken from `flake.lock` and +can be updated with `nix flake update`. ### `shell.nix` diff --git a/nix/nixpkgs-version.nix b/nix/nixpkgs-version.nix deleted file mode 100644 index 52dcfe645..000000000 --- a/nix/nixpkgs-version.nix +++ /dev/null @@ -1,9 +0,0 @@ -# Pinned version of Nixpkgs, generated with postgrest-nixpkgs-upgrade. -{ - owner = "NixOS"; - repo = "nixpkgs"; - ref = "refs/heads/nixpkgs-unstable-darwin"; - date = "2024-11-09"; - rev = "a90280100f41a10914edfe729a4053e60c92b8e3"; - tarballHash = "1vwr665b6l6gma24w45q5hic86vbd8alc01mziwwr621hwlca88f"; -} diff --git a/nix/tools/nixpkgsTools.nix b/nix/tools/nixpkgsTools.nix deleted file mode 100644 index 6ae8234a0..000000000 --- a/nix/tools/nixpkgsTools.nix +++ /dev/null @@ -1,62 +0,0 @@ -{ buildToolbox -, checkedShellScript -, coreutils -, curl -, jq -, nix -}: -# Utility script for pinning the latest stable version of Nixpkgs. - -# Instead of pinning Nixpkgs based on the huge Git repository, we reference a -# specific tarball that only contains the source of the revision that we want -# to pin. -let - name = - "postgrest-nixpkgs-upgrade"; - - refUrl = - "https://api.github.com/repos/nixos/nixpkgs/git/matching-refs/heads/nixpkgs-"; - - githubV3Header = - "Accept: application/vnd.github.v3+json"; - - tarballUrlBase = - "https://github.com/nixos/nixpkgs/archive/"; - - upgrade = - checkedShellScript - { - inherit name; - docs = "Pin the newest stable version of Nixpkgs."; - workingDir = "/"; - } - '' - # The list of refs is sorted. The first result will be nixpkgs-unstable, the second the latest stable branch. - # shellcheck disable=SC2207 - commit=($(${curl}/bin/curl "${refUrl}" -H "${githubV3Header}" | ${jq}/bin/jq -r 'sort_by(.ref) | reverse | [.[0].object.sha, .[0].ref] | @tsv')) - tarballUrl="${tarballUrlBase}''${commit[0]}.tar.gz" - tarballHash="$(${nix}/bin/nix-prefetch-url --unpack "$tarballUrl")" - currentDate="$(${coreutils}/bin/date --iso)" - - cat > nix/nixpkgs-version.nix << EOF - # Pinned version of Nixpkgs, generated with ${name}. - { - owner = "NixOS"; - repo = "nixpkgs"; - ref = "''${commit[1]}"; - date = "$currentDate"; - rev = "''${commit[0]}"; - tarballHash = "$tarballHash"; - } - EOF - - echo "# This file is auto-generated by ${name}" > docs/requirements.txt - cat "$(nix-build -A docs.requirements)" >> docs/requirements.txt - ''; - -in -buildToolbox -{ - name = "postgrest-nixpkgs"; - tools = { inherit upgrade; }; -} diff --git a/shell.nix b/shell.nix index 12c4e3fe9..854d3b05e 100644 --- a/shell.nix +++ b/shell.nix @@ -23,7 +23,6 @@ let postgrest.docs postgrest.loadtest postgrest.memory - postgrest.nixpkgsTools postgrest.release postgrest.style postgrest.tests