-
Notifications
You must be signed in to change notification settings - Fork 43
feat: add Nix flake and package #381
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| { pkgs ? import <nixpkgs> {} }: | ||
|
|
||
| pkgs.callPackage ./nix/pgschema.nix {} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,36 @@ | ||||||
| { | ||||||
| description = "pgschema"; | ||||||
|
|
||||||
| inputs = { | ||||||
| nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The lock file pins the flake to a specific Consider targeting a stable channel (
Suggested change
|
||||||
| }; | ||||||
|
|
||||||
| outputs = { self, nixpkgs }: | ||||||
| let | ||||||
| systems = [ | ||||||
| "x86_64-linux" | ||||||
| "aarch64-linux" | ||||||
| "x86_64-darwin" | ||||||
| "aarch64-darwin" | ||||||
| ]; | ||||||
| forAllSystems = f: nixpkgs.lib.genAttrs systems (system: f system); | ||||||
| in | ||||||
| { | ||||||
| packages = forAllSystems (system: | ||||||
| let | ||||||
| pkgs = import nixpkgs { inherit system; }; | ||||||
| pgschema = pkgs.callPackage ./nix/pgschema.nix {}; | ||||||
| in | ||||||
| { | ||||||
| inherit pgschema; | ||||||
| default = pgschema; | ||||||
| }); | ||||||
|
|
||||||
| apps = forAllSystems (system: { | ||||||
| default = { | ||||||
| type = "app"; | ||||||
| program = "${self.packages.${system}.pgschema}/bin/pgschema"; | ||||||
| }; | ||||||
| }); | ||||||
| }; | ||||||
| } | ||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,35 @@ | ||||||||||||||
| { pkgs ? import <nixpkgs> {} }: | ||||||||||||||
|
|
||||||||||||||
| let | ||||||||||||||
| lib = pkgs.lib; | ||||||||||||||
| version = lib.strings.removeSuffix "\n" (builtins.readFile ../internal/version/VERSION); | ||||||||||||||
| in | ||||||||||||||
| pkgs.buildGoModule { | ||||||||||||||
| pname = "pgschema"; | ||||||||||||||
| inherit version; | ||||||||||||||
|
|
||||||||||||||
| src = lib.cleanSource ../.; | ||||||||||||||
| # go_1_24 is not available in some nixpkgs revisions; use the closest newer toolchain. | ||||||||||||||
| go = pkgs.go_1_25; | ||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
A more future-proof option is to omit the go = pkgs.go_1_24 or pkgs.go_1_25;This way the derivation respects the author-specified toolchain when available and only falls back when it isn't. |
||||||||||||||
| subPackages = [ "." ]; | ||||||||||||||
|
Comment on lines
+12
to
+14
|
||||||||||||||
| proxyVendor = true; | ||||||||||||||
|
Rooffeell marked this conversation as resolved.
|
||||||||||||||
|
|
||||||||||||||
| # Replace with the real hash from `nix build` output. | ||||||||||||||
| vendorHash = "sha256-3nV7AEsWyEvIbxHetoEsA8PPXJ6ENvU/sz7Wn5aysss="; | ||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The inline comment — "Replace with the real hash from The standard Nix workflow is to set |
||||||||||||||
|
|
||||||||||||||
| env = { | ||||||||||||||
| CGO_ENABLED = "0"; | ||||||||||||||
| }; | ||||||||||||||
|
||||||||||||||
| }; | |
| }; | |
| # Run Go tests in short mode to avoid slow or flaky integration tests | |
| # (e.g., those that start embedded Postgres) during Nix builds. | |
| checkFlags = [ "-short" ]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing version-injection ldflags
According to CLAUDE.md, the canonical build injects GitCommit and BuildDate into the binary:
-X github.com/pgplex/pgschema/cmd.GitCommit=...
-X 'github.com/pgplex/pgschema/cmd.BuildDate=...'
The Nix derivation only passes -s -w. As a result, pgschema version (or any version display) will show empty values for commit and build date. Nix exposes the revision via self.rev (or self.shortRev) in the flake, which can be threaded through to the derivation, e.g.:
# In flake.nix, pass rev to the package:
pgschema = pkgs.callPackage ./nix/pgschema.nix { rev = self.shortRev or "dirty"; };
# In nix/pgschema.nix, receive and use it:
{ pkgs ? import <nixpkgs> {}, rev ? "unknown" }:
...
ldflags = [
"-s" "-w"
"-X github.com/pgplex/pgschema/cmd.GitCommit=${rev}"
];
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nix runwithout argument separator won't forward CLI flagsnix runby itself runs the binary with no arguments. To pass arguments topgschema(e.g.pgschema plan), users need to separate nix flags from program flags with--. The example could be more helpful:or at minimum a note like: