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.
This commit is contained in:
Wolfgang Walther
2025-03-28 09:22:34 +00:00
parent 144b0c46ca
commit 149be6bc33
7 changed files with 31 additions and 94 deletions
+9 -5
View File
@@ -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 { };
Generated
+10 -9
View File
@@ -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"
}
}
},
+10 -4
View File
@@ -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;
});
+2 -4
View File
@@ -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`
-9
View File
@@ -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";
}
-62
View File
@@ -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; };
}
-1
View File
@@ -23,7 +23,6 @@ let
postgrest.docs
postgrest.loadtest
postgrest.memory
postgrest.nixpkgsTools
postgrest.release
postgrest.style
postgrest.tests