Skip to content

{buildPostgresql,orioledb}: init#513940

Open
wolfgangwalther wants to merge 6 commits into
NixOS:masterfrom
wolfgangwalther:postgresql-overrides
Open

{buildPostgresql,orioledb}: init#513940
wolfgangwalther wants to merge 6 commits into
NixOS:masterfrom
wolfgangwalther:postgresql-overrides

Conversation

@wolfgangwalther
Copy link
Copy Markdown
Contributor

@wolfgangwalther wolfgangwalther commented Apr 27, 2026

I want to package orioledb, which is an extension that needs a patched version of postgresql. In other words, I need to package a postgresql fork.

The first thing I tried downstream was something like (postgresql.overrideAttrs { src = ... orioledb/postgres ... }).withPackages (pkgs: pkgs.callPackage (... orioledb/orioledb ...)). Unfortunately that doesn't work, because withPackages looses overrideAttrs. We tried to fix that in #488692, but failed - the interactions between withPackages and overriding are more complicated.

I tried a few different things to fix that, but ultimately failed with all of them. So I went this way: We're now exposing a separate buildPostgresql function, which can be used to call the generic builder. Also added orioledb as an example of its usage.

(more text in the commits!)

Things done

TODO: Investigate aarch64-related failure for orioledb.

@nixpkgs-ci nixpkgs-ci Bot requested a review from a team April 27, 2026 09:13
@nixpkgs-ci nixpkgs-ci Bot added 8.has: package (new) This PR adds a new package 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux. 10.rebuild-darwin: 1-10 This PR causes between 1 and 10 packages to rebuild on Darwin. 10.rebuild-darwin: 1 This PR causes 1 package to rebuild on Darwin. 10.rebuild-linux: 1 This PR causes 1 package to rebuild on Linux. labels Apr 27, 2026
@wolfgangwalther
Copy link
Copy Markdown
Contributor Author

nixpkgs-vet failure is due to NixOS/nixpkgs-vet#203 (comment).

@wolfgangwalther
Copy link
Copy Markdown
Contributor Author

nixpkgs-review result

Generated using nixpkgs-review.

Command: nixpkgs-review pr 513940
Commit: 4e71fb46d5c2f67051c96bc70a0e3ffbffa82580


x86_64-linux

✅ 1 package built:
  • orioledb

aarch64-linux

❌ 1 package failed to build:
  • orioledb

x86_64-darwin

✅ 1 package built:
  • orioledb

aarch64-darwin

❌ 1 package failed to build:
  • orioledb

Comment thread pkgs/servers/sql/postgresql/wrapper.nix Outdated
let
attrName = if jitSupport then "${version}_jit" else version;
postgresql = buildPostgresql (import path);
postgresql = buildPostgresql (import path { inherit (self) fetchFromGitHub lib; });
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any good reason left that I'm forgetting / not seeing on why we have this weird self construct here?

Doesn't have to be done in this PR, but I wonder if we can replace this with a normal callPackage interface by now.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I briefly looked into that when writing the PR and it seemed to me that we need self when creating the new scope for the package set. I did not look at it in-depth, though.

};

buildPostgresql =
args: self.callPackage (import ./generic.nix args) { inherit buildPostgresql self; };
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are not implementing the finalAttrs interface here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume you mean why I'm not using lib.extendMkDerivation on buildPostgresql?

I thought a lot about this and I don't see a way to make it work:

  • the builder needs to reference this, which is a reference to same derivation, to make the withJIT, withoutJIT and withPackages modifiers work.
  • this can't use finalAttrs.finalPackage, because that one does not provide .override - it's just a derivation, but nothing wrapped in a callPackage call - we tried and had to revert that fix,
  • to provide .override it will need to ultimately callPackage on the builder expression again - and at this stage any overrideAttrs will be lost.

This means I need a different way to pass these arguments along to the builder, which is what I'm doing here: These args are wrapped around the callPackage interface (kind of the inverse of where finalAttrs would be, related to callPackage).

I tried a lot of different things, but was not able to make any work. I might be missing something obvious, though...

Comment thread pkgs/by-name/or/orioledb/package.nix Outdated
Moves the function to a separate file and makes it callPackage-able. Now
that buildEnv also supports finalAttrs, the finalPackage construct can
also be rewritten that way.

This gives us clear separation of concern between the package builder in
generic.nix and wrapper.nix.
Removes all the indentation in generic.nix, which is possible by
changing the `self.callPackage` call to point at the file itself, not
the `generic` function.
Exposes the postgresql builder function as a top-level argument. Not
really useful that much, so far, because it needs some more arguments to
allow passing relevant configuration.

Split into multiple commits for ease of review.

Eventually, this will allow to build forks of PostgreSQL including the
whole package set machinery.

This is not possible via overrideAttrs / override, because of the
withPackages wrapper, which does support either of the two properly -
and can't be made to do that, at least not by me.
Exposes the minimal set of arguments required to effective build a
forked PostgreSQL. Considerations were:
- Putting the `fetchFromGitHub` call as a default value for the `src`
argument would have made all the arguments hash, rev and src optional,
which is an odd interface. A little duplication in each of the versioned
files is tolerable, imho.
- Putting the `meta` information in a default value would possibly lead
to people forgetting to set it when packaging forks, which would lead to
wrong metadata. It would also lead to some forks be attributed to the
postgres team, but not others. We should rather be explicit about
whether the postgres team wants to maintain all forks or none of them. I
went with "none of them" here and moved the setting of meta.teams to the
versioned files instead.
- My best guess is that forks of PostgreSQL must be published under the
same license, so I kept that in the builder. It's overridable, though.
We have dropped everything below v14 by now.

To not cause rebuilds, I left the order in the list alone.
@wolfgangwalther wolfgangwalther force-pushed the postgresql-overrides branch from f6b58bb to 38ee3fc Compare May 3, 2026 11:33
@nixpkgs-ci nixpkgs-ci Bot added the 2.status: merge conflict This PR has merge conflicts with the target branch label May 22, 2026
@Kranzes
Copy link
Copy Markdown
Member

Kranzes commented May 28, 2026

@wolfgangwalther hey, do you plan on picking this PR back up?

@wolfgangwalther
Copy link
Copy Markdown
Contributor Author

hey, do you plan on picking this PR back up?

Not exactly sure what you'd expect me to do at this stage. From my perspective this PR requires review, which will take "as long as it takes".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

2.status: merge conflict This PR has merge conflicts with the target branch 8.has: package (new) This PR adds a new package 10.rebuild-darwin: 1-10 This PR causes between 1 and 10 packages to rebuild on Darwin. 10.rebuild-darwin: 1 This PR causes 1 package to rebuild on Darwin. 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux. 10.rebuild-linux: 1 This PR causes 1 package to rebuild on Linux.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants