Skip to content
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

feat: reintroduce nix flake #1683

Draft
wants to merge 5 commits into
base: develop
Choose a base branch
from

Conversation

justinrubek
Copy link

@justinrubek justinrubek commented Apr 28, 2024

overview

This reintroduces the nix code after it was removed in #1682. It has been refactored to live in a single file and many parts of it have been removed because they weren't necessary. I will attempt to provide an overview of everything that is taking place in this configuration and why I've chosen to write things the way I have. Additionally, my commit messages have context if you expand them.

The previous flake did the following things:

  • built the cargo-pgrx binary
  • exposed a function that can be called by consuming flakes to build their extension
  • had checks that validated formatting for rust and nix code in the pgrx repository
  • provided a template to get started building an extension with nix
  • provides a devShell for developers who wish to work on pgrx to obtain their dependencies

I've chosen to focus on the first two options in the above list. There is no need to verify formatting using nix since this is done through GitHub Actions. I could feasibly make an example, but I'll only do that once I'm sure that this PR can be accepted (and if it is requested). For now, as part of my testing, I've taken the arrays example from the pgrx-examples directory and made a separate repo showcasing how to use this new flake https://github.com/justinrubek/pgrx-nix-example

flake inputs

Here is what each input does and why we're using them:

  • crane
    • This is a wrapper around cargo that has some nice cache benefits for nix as well as simplifies the build
    • It is used to build the cargo-pgrx and also to call pgrx when building an extension
    • While nixpkgs has some rust tooling built in, I would suggest keeping this. It's a very mature library and the team behind it is very responsive when you need help
  • nixpkgs
    • This is the base of all packaging with nix, we need it to do nearly anything
  • fenix
    • This is the rustup equivalent for nix. Having it as an input allows consuming flakes to override the rust toolchain used with whatever they need
  • flake-parts
    • This one is technically optional, but it well designed and provides a nice way to iterate over the many supported systems
    • See the perSystem function in flake.nix
  • gitignore
    • It's use is important to avoid the .git directory from being copied into builds
    • I would prefer to use nix-filter here, but it would require editing the list of directories/files to include in the build if more are added, so using this is a good compromise for maintenance

For the most part we should be fine to leave these dependencies locked to their current version in flake.lock. However, it isn't a bad idea to try to keep them up to date. I've provided a shell script that will update the fenix input to retrieve newer rust toolchains, although I could see that it may better suit the project to have the script update every input so I will change it if asked.

flake outputs

This flake exposes two outputs: packages.${system}.cargo-pgrx and lib.buildPgrxExtension

cargo-pgrx

This is the pgrx binary, built using the source code from this repo. It's build is a pretty standard cargo build, but there are a few extra things happening.

As part of the build step the tests are ran. However, pgrx's tests appear to have two requirements that won't be met by default:

  1. The PGRX_HOME environment variable must be set
  2. For test_parse_managed_postmasters, cargo pgrx init must have been ran

For 1. the solution is easy: the preCheck block is ran which sets the file to a temporary directory. However, 2. is not as simple because we don't have the pgrx binary available yet due to this being the build step for it. The compromise is to skip any tests that require this to be ran. The rest of the tests are still ran, so we can be fairly sure the nix build isn't broken. And since the pgrx test suite is not being ran through nix any issues with this test will be detected anyway.

This should require minimal maintenance as building a cargo package is fairly trivial. The only exceptions are:

  1. If any of the above requirements change; either new tests are added that require an init, other environment variables, or similar
  2. If any of the build/runtime dependencies are changed. This will require changing the buildInputs to contain the package corresponding to the new dependency. For a list of packages, see https://search.nixos.org/packages?channel=unstable

buildPgrxExtension

This is the more complicated piece, but it is also the larger value-add for nix users. I've taken most of the logic from the previous configuration, distilling it down by removing extra code and simplifying the rest. I believe I've gotten it nearly as simple as it can be, but there may be some further room for improvement.

The function is responsible for setting up postgres in a way that stops pgrx from attempting to download it. This is because flake builds are executed in a sandbox without network access. Consuming flakes must provide the postgres package they wish to use in order for this to work. The function will determine the major version to set up the proper feature flags as well as put postgres in a subdirectory of PGRX_HOME according to its version (this is the preBuildAndTest block).

Apart from that, there is some file cleanup that takes place in the preFixup and postInstall steps, primarily to ensure that only the minimum things required end up in the final build (if I understanding right, the --out-dir flag from pgrx is placing things there that are not desired in the final build, so I chose to delete them).

Testing performed

I have tested this all using x86_64-linux. I am unable to test aarch64-linux, although I may be able to try aarch64-darwin. I suspect that it will work on aarch64-linux anyway.

I've verified that I can build extensions and load them into postgres. See justinrubek/pgrx-nix-example#1 (comment). I've also back-ported this change to pgrx v0.11 and tested using pgx_ulid.

further work

I don't have a wide variety of extensions to test against. I can imagine the need for some tweaks depending on any issues encountered by people using this flake, but I'm not sure what those would be at this time. I am willing and able to look into this should any come up, so please route these to me so I can help.

Beyond that, I have a few small changes that may be good:

  • add a nix formatter to GitHub Actions
  • add the devShell again
  • restore some of the previous options to buildPgrxExtensions
    • For example, debug/release build support, which I've not chosen to keep

why this is important for nix users

There is a cargo-pgrx binary and buildPgrxExtension function in nixpkgs, but that is not sufficient due to the pgrx binary version needing to match the cargo dependency. If a consumer wishes to use a newer version of pgrx, they will have to wait for it to make it into nixpkgs. On the other side of things, if they wish to remain on an older version of pgrx they may have to pin an old nixpkgs. By keeping the flake in this repo consumers are able to easily use the latest version of pgrx without any difficulty. Here's an example of the supabase folks dealing with a glibc issue where they pray updating cargo-pgrx will resolve the issue supabase/nix-postgres#28 (comment), which is precisely the kind of thing I'd like to avoid.

This exposes the `cargo pgrx` binary as a flake package called
`cargo-pgrx`. It can be built using `nix build .#cargo-pgrx`.

The systems specified in this flake were chosen from the project's
README of tested systems. The flake inputs were chosen to minimize the
maintenance burden.

Since the build runs tests in order to succeed, but the tests are
performed at build time for nix, the `test_parse_managed_postmasters`
test has been skipped. Since pgrx already has a test suite that runs
outside of nix, this should be a good compromise to allow the build to
work, but also keep the majority of the tests to ensure that nix users
are aware when they are broken. In addition to this, the `PGRX_HOME`
variable must be set for tests, so it is assigned to a tmpdir before
running the tests.
This script can be ran to update the rust-toolchain that is used by nix
builds. Since `fenix` is a flake input end-users are able to override it
themselves to whichever version they please, however it is useful to
have the provided version up to date, particularly if the project
ends up having an MSRV.

We could likely change this script to be one that updates all flake
inputs, however I find it useful to be able to update the rust
toolchain separately from the other dependencies and have chosen to
provide a script soley for that. This matches the existing `rustup.sh`
that is used to update the rustup toolchain version. If you wish to make
this file a generic `flake.lock` updater, remove `fenix` from the call
to `nix flake update` and it will update all inputs.
This function can be used by external nix flakes to build an extension
using pgrx. The caller must provide the postgres package, the rust
toolchain, extension source code, and flake system that they are
building for.

Most of this configuration has been converted from the previous nix
flake exposed from pgrx. I've made every attempt to trim away parts that
don't serve a purpose, but there's a chance that this could be
simplified slightly by someone who has more knowledge of pgrx than I do.
@justinrubek
Copy link
Author

I've opened this as a draft PR so it can gather attention while I try to see if I can somehow test on aarch64-darwin. It is complete and works for x86_64-linux and is otherwise ready for review from the maintainers.

pname = "${name}-pg${postgresMajor}";
nativeBuildInputs = [
pkgs.pkg-config
pkgs.rustPlatform.bindgenHook
Copy link
Author

@justinrubek justinrubek Apr 28, 2024

Choose a reason for hiding this comment

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

bindgenHook is a handy package I found that sets BINDGEN_EXTRA_CLANG_ARGS, which was previously being done manually in the build step. See https://github.com/symphorien/nixpkgs/blob/master/pkgs/build-support/rust/hooks/rust-bindgen-hook.sh

Comment on lines +98 to +101
PGRX_PG_SYS_SKIP_BINDING_REWRITE = "1";
CARGO = "${rustToolchain}/bin/cargo";
CARGO_BUILD_INCREMENTAL = "false";
RUST_BACKTRACE = "full";
Copy link
Author

Choose a reason for hiding this comment

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

These get set as environment variables for the build

@eeeebbbbrrrr
Copy link
Contributor

Thanks @justinrubek. If you will, give us a bit of time to digest this.

A quick comment is I think we'd want to see some kind of documentation in our fledgling "book". Probably from two perspectives. One being general Nix users, and the other being me and @workingjubilee and @thomcc and @NotGyro so we know how to update the things that might need updating in the future.

Additionally, I'm sure we'll require a separate CI job that tests a nix build of just the simple cargo pgrx new foo template extension. We'll need some indication that something is broken as none of us are Nix users.

@justinrubek
Copy link
Author

justinrubek commented Apr 29, 2024

Absolutely take your time, I'm in no hurry. I'm very responsive to GitHub notifications, and I'll do my best to address everything.

I can get started on those pieces and anything that is further requested as it comes in.

@samrose
Copy link

samrose commented Jun 10, 2024

This pr in nixpkgs may also be relevant for seeing some pgrx extensions successfully build on aarch64-darwin. NixOS/nixpkgs#294504

@ahacop
Copy link

ahacop commented Jun 10, 2024

@justinrubek You asked me on the pgrx discord to post this on this PR:

I saw you had an example repo (pgrx-nix-example), and gave it a spin. I ran nix develop and got this error:

error: flake 'git+file:///home/x/code/x/pgrx-nix-example' does not provide attribute
 'devShells.aarch64-linux.default', 'devShell.aarch64-linux', 'packages.aarch64-linux.default'
  or 'defaultPackage.aarch64-linux'
       Did you mean devShells?

Happy to provide additional debug info if you'd like.

@samrose
Copy link

samrose commented Jun 10, 2024

@justinrubek if I build on aarch64-darwin I see the following error

nix build .#cargo-pgrx
error:
       … while calling the 'derivationStrict' builtin
         at <nix/derivation-internal.nix>:9:12:
            8|
            9|   strict = derivationStrict drvAttrs;
             |            ^
           10|

       … while evaluating derivation 'cargo-pgrx-0.12.0-alpha.1'
         whose name attribute is located at /nix/store/370qy3d3wg9zhbn5a3dcv6k1q1iigfh4-source/pkgs/stdenv/generic/make-derivation.nix:331:7

       … while evaluating attribute 'buildInputs' of derivation 'cargo-pgrx-0.12.0-alpha.1'
         at /nix/store/370qy3d3wg9zhbn5a3dcv6k1q1iigfh4-source/pkgs/stdenv/generic/make-derivation.nix:378:7:
          377|       depsHostHost                = elemAt (elemAt dependencies 1) 0;
          378|       buildInputs                 = elemAt (elemAt dependencies 1) 1;
             |       ^
          379|       depsTargetTarget            = elemAt (elemAt dependencies 2) 0;

       error: attribute 'Security' missing
       at /nix/store/pqvlaf0ga3czljdf3yc14kmyc6i2a6gv-source/flake.nix:38:81:
           37|             nativeBuildInputs = [pkgs.pkg-config];
           38|             buildInputs = [pkgs.openssl] ++ lib.optionals pkgs.stdenv.isDarwin [pkgs.Security];
             |                                                                                 ^
           39|             # fixes to enable running pgrx tests

I think you will actually need this

diff --git a/flake.nix b/flake.nix
index d9cc60bf..164686ee 100644
--- a/flake.nix
+++ b/flake.nix
@@ -35,7 +35,7 @@
             inherit (craneLib.crateNameFromCargoToml {cargoToml = ./cargo-pgrx/Cargo.toml;}) pname version;
             cargoExtraArgs = "--package cargo-pgrx";
             nativeBuildInputs = [pkgs.pkg-config];
-            buildInputs = [pkgs.openssl] ++ lib.optionals pkgs.stdenv.isDarwin [pkgs.Security];
+            buildInputs = [pkgs.openssl] ++ lib.optionals pkgs.stdenv.isDarwin [pkgs.darwin.apple_sdk.frameworks.Security];
             # fixes to enable running pgrx tests
             preCheck = ''
               export PGRX_HOME=$(mktemp -d)

However, even with that patch, which stops the nix build from erroring, I am now running into the same issue I see on our supabase extenions when building on aarch64-darwin which is related to linking failures

nix build .#cargo-pgrx
warning: Git tree '/Users/samrose/pgrx' is dirty
error: builder for '/nix/store/dcipgim0myrpaz0hv9j8lbf2hwxhq08p-cargo-pgrx-deps-0.12.0-alpha.1.drv' failed with exit code 101;
       last 25 log lines:
       >    Compiling camino v1.1.6
       >    Compiling ring v0.17.7
       >    Compiling semver v1.0.21
       >     Checking colorchoice v1.0.0
       >     Checking anstyle v1.0.4
       >    Compiling bzip2-sys v0.1.11+1.0.8
       >     Checking terminal_size v0.3.0
       >     Checking anstream v0.6.11
       > error: linking with `cc` failed: exit status: 1
       >   |
       >   = note: env -u IPHONEOS_DEPLOYMENT_TARGET -u TVOS_DEPLOYMENT_TARGET LC_ALL="C" PATH="/nix/store/4yqg7kka35j1zayghs6d4vrzbahak3yv-rust-stable-2024-04-09/lib/rustlib/aarch64-apple-darwin/bin:/nix/store/3l8pzzkvvihqj5z1bymn5zcsm1a3gmp9-pkg-config-wrapper-0.29.2/bin:/nix/store/4yqg7kka35j1zayghs6d4vrzbahak3yv-rust-stable-2024-04-09/bin:/nix/store/lmn0856fjg2h00dbkgd0yi7dg2i1czrq-rsync-3.2.7/bin:/nix/store/vbgzzan67ycvwn6in3kpy9hkfckkkwyj-zstd-1.5.6-bin/bin:/nix/store/q95gkmqc1lb69dcclz3cxxhw79hsyrh5-zstd-1.5.6/bin:/nix/store/v4p0piwwk3a9gwrhvxa8b04ljd1arviz-clang-wrapper-16.0.6/bin:/nix/store/kq25mdy9byl6pgv3n0vsa85p6807zaqy-clang-16.0.6/bin:/nix/store/ssqkq33b9jb441g7baplb87z8vnyp34i-coreutils-9.5/bin:/nix/store/3b25yj6dyrjy76sq953a6sy1xb22lgv1-cctools-binutils-darwin-wrapper-16.0.6-973.0.1/bin:/nix/store/73x46ri7fbdfl062vnxv1dq10isyh4jh-cctools-binutils-darwin-16.0.6-973.0.1/bin:/nix/store/n8xzpnjww9iqlh7h9mdm6kx3lbqkpa50-openssl-3.0.13-bin/bin:/nix/store/ssqkq33b9jb441g7baplb87z8vnyp34i-coreutils-9.5/bin:/nix/store/f2zkblkcbxvgczjdxa53xn8d0652d4x0-findutils-4.9.0/bin:/nix/store/l9k0z4wc8lhkpdfalhgb1wd4950vb08p-diffutils-3.10/bin:/nix/store/7bv9z3svwrqc9jlxbk5mamnahfvpm2vp-gnused-4.9/bin:/nix/store/w57dxm682rl3b7ayf7ay8lsy9lkzmh7z-gnugrep-3.11/bin:/nix/store/33g5y7bqsrlpidlk43b8gc518wc784q9-gawk-5.2.2/bin:/nix/store/f8pcjixa8bq9558vhycbvv9sm27hmxad-gnutar-1.35/bin:/nix/store/qvfwvhllwqrnybcvzqrn0694bzwqvb66-gzip-1.13/bin:/nix/store/7gqdnz03xicalizs8fwn9c28lahclg8a-bzip2-1.0.8-bin/bin:/nix/store/1cjkrg6qi2hqvl2j9arrhda5ik3dw707-gnumake-4.4.1/bin:/nix/store/lp3ginchcanhcj4dgw6yzdgv8bgdkm1v-bash-5.2p26/bin:/nix/store/pxz0p3jywa3jnf29pm3hxgrhkd33f2q7-patch-2.7.6/bin:/nix/store/ywxnlqjizsxcz0q0gygwfazrglhd1s8v-xz-5.4.6-bin/bin:/nix/store/7pjzfb020206fayckw22z29nvsz4r7ks-file-5.45/bin" VSLANG="1033" ZERO_AR_DATE="1" "cc" "-arch" "arm64" "/private/tmp/nix-build-cargo-pgrx-deps-0.12.0-alpha.1.drv-0/rustc3VbzXd/symbols.o" "/private/tmp/nix-build-cargo-pgrx-deps-0.12.0-alpha.1.drv-0/source/target/release/build/bzip2-sys-d7a03512998fb2e6/build_script_build-d7a03512998fb2e6.build_script_build.51ec6b185fc5d53e-cgu.0.rcgu.o" "/private/tmp/nix-build-cargo-pgrx-deps-0.12.0-alpha.1.drv-0/source/target/release/build/bzip2-sys-d7a03512998fb2e6/build_script_build-d7a03512998fb2e6.wof29p7it4g8gow.rcgu.o" "-L" "/private/tmp/nix-build-cargo-pgrx-deps-0.12.0-alpha.1.drv-0/source/target/release/deps" "-L" "/nix/store/4yqg7kka35j1zayghs6d4vrzbahak3yv-rust-stable-2024-04-09/lib/rustlib/aarch64-apple-darwin/lib" "/private/tmp/nix-build-cargo-pgrx-deps-0.12.0-alpha.1.drv-0/source/target/release/deps/libpkg_config-a41bef66e297552e.rlib" "/private/tmp/nix-build-cargo-pgrx-deps-0.12.0-alpha.1.drv-0/source/target/release/deps/libcc-5799af08f211fc33.rlib" "/private/tmp/nix-build-cargo-pgrx-deps-0.12.0-alpha.1.drv-0/source/target/release/deps/liblibc-753c7acb4e5b4024.rlib" "/nix/store/fgi9gjhkcp8jjphf5z1qi24sc9zcy361-rust-stable-2024-04-09/lib/rustlib/aarch64-apple-darwin/lib/libstd-b7bbc4a3799f91ec.rlib" "/nix/store/fgi9gjhkcp8jjphf5z1qi24sc9zcy361-rust-stable-2024-04-09/lib/rustlib/aarch64-apple-darwin/lib/libpanic_unwind-9a832f29e113f2ac.rlib" "/nix/store/fgi9gjhkcp8jjphf5z1qi24sc9zcy361-rust-stable-2024-04-09/lib/rustlib/aarch64-apple-darwin/lib/libobject-187acb73fb221979.rlib" "/nix/store/fgi9gjhkcp8jjphf5z1qi24sc9zcy361-rust-stable-2024-04-09/lib/rustlib/aarch64-apple-darwin/lib/libmemchr-f379d77720ea5d52.rlib" "/nix/store/fgi9gjhkcp8jjphf5z1qi24sc9zcy361-rust-stable-2024-04-09/lib/rustlib/aarch64-apple-darwin/lib/libaddr2line-5f995b6402184362.rlib" "/nix/store/fgi9gjhkcp8jjphf5z1qi24sc9zcy361-rust-stable-2024-04-09/lib/rustlib/aarch64-apple-darwin/lib/libgimli-6d4646231255d040.rlib" "/nix/store/fgi9gjhkcp8jjphf5z1qi24sc9zcy361-rust-stable-2024-04-09/lib/rustlib/aarch64-apple-darwin/lib/librustc_demangle-ddf92ea3297b7931.rlib" "/nix/store/fgi9gjhkcp8jjphf5z1qi24sc9zcy361-rust-stable-2024-04-09/lib/rustlib/aarch64-apple-darwin/lib/libstd_detect-4bd9fc9ff7289783.rlib" "/nix/store/fgi9gjhkcp8jjphf5z1qi24sc9zcy361-rust-stable-2024-04-09/lib/rustlib/aarch64-apple-darwin/lib/libhashbrown-bbf01e0821f9af8a.rlib" "/nix/store/fgi9gjhkcp8jjphf5z1qi24sc9zcy361-rust-stable-2024-04-09/lib/rustlib/aarch64-apple-darwin/lib/librustc_std_workspace_alloc-df3ad4119d36f143.rlib" "/nix/store/fgi9gjhkcp8jjphf5z1qi24sc9zcy361-rust-stable-2024-04-09/lib/rustlib/aarch64-apple-darwin/lib/libminiz_oxide-3839cef552c2783c.rlib" "/nix/store/fgi9gjhkcp8jjphf5z1qi24sc9zcy361-rust-stable-2024-04-09/lib/rustlib/aarch64-apple-darwin/lib/libadler-130a17e70576817a.rlib" "/nix/store/fgi9gjhkcp8jjphf5z1qi24sc9zcy361-rust-stable-2024-04-09/lib/rustlib/aarch64-apple-darwin/lib/libunwind-f7bc4dcd41ebfabc.rlib" "/nix/store/fgi9gjhkcp8jjphf5z1qi24sc9zcy361-rust-stable-2024-04-09/lib/rustlib/aarch64-apple-darwin/lib/libcfg_if-3b8c9f0215d4bce7.rlib" "/nix/store/fgi9gjhkcp8jjphf5z1qi24sc9zcy361-rust-stable-2024-04-09/lib/rustlib/aarch64-apple-darwin/lib/liblibc-8e6430dafe1e0d1f.rlib" "/nix/store/fgi9gjhkcp8jjphf5z1qi24sc9zcy361-rust-stable-2024-04-09/lib/rustlib/aarch64-apple-darwin/lib/liballoc-9d92a40a452d227c.rlib" "/nix/store/fgi9gjhkcp8jjphf5z1qi24sc9zcy361-rust-stable-2024-04-09/lib/rustlib/aarch64-apple-darwin/lib/librustc_std_workspace_core-fb23eb00feddf1cb.rlib" "/nix/store/fgi9gjhkcp8jjphf5z1qi24sc9zcy361-rust-stable-2024-04-09/lib/rustlib/aarch64-apple-darwin/lib/libcore-c6577f5d4f5dcd9a.rlib" "/nix/store/fgi9gjhkcp8jjphf5z1qi24sc9zcy361-rust-stable-2024-04-09/lib/rustlib/aarch64-apple-darwin/lib/libcompiler_builtins-6d556b0e8bf6f23e.rlib" "-lc" "-lm" "-liconv" "-lSystem" "-lc" "-lm" "-L" "/nix/store/4yqg7kka35j1zayghs6d4vrzbahak3yv-rust-stable-2024-04-09/lib/rustlib/aarch64-apple-darwin/lib" "-o" "/private/tmp/nix-build-cargo-pgrx-deps-0.12.0-alpha.1.drv-0/source/target/release/build/bzip2-sys-d7a03512998fb2e6/build_script_build-d7a03512998fb2e6" "-Wl,-dead_strip" "-nodefaultlibs" "-Wl,-undefined,dynamic_lookup"
       >   = note: ld: library not found for -liconv
       >           clang-16: error: linker command failed with exit code 1 (use -v to see invocation)
       >           
       >
       > error: could not compile `bzip2-sys` (build script) due to 1 previous error
       > warning: build failed, waiting for other jobs to finish...
       > error: linking with `cc` failed: exit status: 1
       >   |
       >   = note: env -u IPHONEOS_DEPLOYMENT_TARGET -u TVOS_DEPLOYMENT_TARGET LC_ALL="C" PATH="/nix/store/4yqg7kka35j1zayghs6d4vrzbahak3yv-rust-stable-2024-04-09/lib/rustlib/aarch64-apple-darwin/bin:/nix/store/3l8pzzkvvihqj5z1bymn5zcsm1a3gmp9-pkg-config-wrapper-0.29.2/bin:/nix/store/4yqg7kka35j1zayghs6d4vrzbahak3yv-rust-stable-2024-04-09/bin:/nix/store/lmn0856fjg2h00dbkgd0yi7dg2i1czrq-rsync-3.2.7/bin:/nix/store/vbgzzan67ycvwn6in3kpy9hkfckkkwyj-zstd-1.5.6-bin/bin:/nix/store/q95gkmqc1lb69dcclz3cxxhw79hsyrh5-zstd-1.5.6/bin:/nix/store/v4p0piwwk3a9gwrhvxa8b04ljd1arviz-clang-wrapper-16.0.6/bin:/nix/store/kq25mdy9byl6pgv3n0vsa85p6807zaqy-clang-16.0.6/bin:/nix/store/ssqkq33b9jb441g7baplb87z8vnyp34i-coreutils-9.5/bin:/nix/store/3b25yj6dyrjy76sq953a6sy1xb22lgv1-cctools-binutils-darwin-wrapper-16.0.6-973.0.1/bin:/nix/store/73x46ri7fbdfl062vnxv1dq10isyh4jh-cctools-binutils-darwin-16.0.6-973.0.1/bin:/nix/store/n8xzpnjww9iqlh7h9mdm6kx3lbqkpa50-openssl-3.0.13-bin/bin:/nix/store/ssqkq33b9jb441g7baplb87z8vnyp34i-coreutils-9.5/bin:/nix/store/f2zkblkcbxvgczjdxa53xn8d0652d4x0-findutils-4.9.0/bin:/nix/store/l9k0z4wc8lhkpdfalhgb1wd4950vb08p-diffutils-3.10/bin:/nix/store/7bv9z3svwrqc9jlxbk5mamnahfvpm2vp-gnused-4.9/bin:/nix/store/w57dxm682rl3b7ayf7ay8lsy9lkzmh7z-gnugrep-3.11/bin:/nix/store/33g5y7bqsrlpidlk43b8gc518wc784q9-gawk-5.2.2/bin:/nix/store/f8pcjixa8bq9558vhycbvv9sm27hmxad-gnutar-1.35/bin:/nix/store/qvfwvhllwqrnybcvzqrn0694bzwqvb66-gzip-1.13/bin:/nix/store/7gqdnz03xicalizs8fwn9c28lahclg8a-bzip2-1.0.8-bin/bin:/nix/store/1cjkrg6qi2hqvl2j9arrhda5ik3dw707-gnumake-4.4.1/bin:/nix/store/lp3ginchcanhcj4dgw6yzdgv8bgdkm1v-bash-5.2p26/bin:/nix/store/pxz0p3jywa3jnf29pm3hxgrhkd33f2q7-patch-2.7.6/bin:/nix/store/ywxnlqjizsxcz0q0gygwfazrglhd1s8v-xz-5.4.6-bin/bin:/nix/store/7pjzfb020206fayckw22z29nvsz4r7ks-file-5.45/bin" VSLANG="1033" ZERO_AR_DATE="1" "cc" "-arch" "arm64" "/private/tmp/nix-build-cargo-pgrx-deps-0.12.0-alpha.1.drv-0/rustcP1hL1g/symbols.o" "/private/tmp/nix-build-cargo-pgrx-deps-0.12.0-alpha.1.drv-0/source/target/release/build/ring-1484f7d9333b717b/build_script_build-1484f7d9333b717b.build_script_build.e0674a3a45294900-cgu.0.rcgu.o" "/private/tmp/nix-build-cargo-pgrx-deps-0.12.0-alpha.1.drv-0/source/target/release/build/ring-1484f7d9333b717b/build_script_build-1484f7d9333b717b.build_script_build.e0674a3a45294900-cgu.1.rcgu.o" "/private/tmp/nix-build-cargo-pgrx-deps-0.12.0-alpha.1.drv-0/source/target/release/build/ring-1484f7d9333b717b/build_script_build-1484f7d9333b717b.build_script_build.e0674a3a45294900-cgu.2.rcgu.o" "/private/tmp/nix-build-cargo-pgrx-deps-0.12.0-alpha.1.drv-0/source/target/release/build/ring-1484f7d9333b717b/build_script_build-1484f7d9333b717b.build_script_build.e0674a3a45294900-cgu.3.rcgu.o" "/private/tmp/nix-build-cargo-pgrx-deps-0.12.0-alpha.1.drv-0/source/target/release/build/ring-1484f7d9333b717b/build_script_build-1484f7d9333b717b.build_script_build.e0674a3a45294900-cgu.4.rcgu.o" "/private/tmp/nix-build-cargo-pgrx-deps-0.12.0-alpha.1.drv-0/source/target/release/build/ring-1484f7d9333b717b/build_script_build-1484f7d9333b717b.build_script_build.e0674a3a45294900-cgu.5.rcgu.o" "/private/tmp/nix-build-cargo-pgrx-deps-0.12.0-alpha.1.drv-0/source/target/release/build/ring-1484f7d9333b717b/build_script_build-1484f7d9333b717b.3h4rrxooxoiwc60m.rcgu.o" "-L" "/private/tmp/nix-build-cargo-pgrx-deps-0.12.0-alpha.1.drv-0/source/target/release/deps" "-L" "/nix/store/4yqg7kka35j1zayghs6d4vrzbahak3yv-rust-stable-2024-04-09/lib/rustlib/aarch64-apple-darwin/lib" "/private/tmp/nix-build-cargo-pgrx-deps-0.12.0-alpha.1.drv-0/source/target/release/deps/libcc-5799af08f211fc33.rlib" "/private/tmp/nix-build-cargo-pgrx-deps-0.12.0-alpha.1.drv-0/source/target/release/deps/liblibc-753c7acb4e5b4024.rlib" "/nix/store/fgi9gjhkcp8jjphf5z1qi24sc9zcy361-rust-stable-2024-04-09/lib/rustlib/aarch64-apple-darwin/lib/libstd-b7bbc4a3799f91ec.rlib" "/nix/store/fgi9gjhkcp8jjphf5z1qi24sc9zcy361-rust-stable-2024-04-09/lib/rustlib/aarch64-apple-darwin/lib/libpanic_unwind-9a832f29e113f2ac.rlib" "/nix/store/fgi9gjhkcp8jjphf5z1qi24sc9zcy361-rust-stable-2024-04-09/lib/rustlib/aarch64-apple-darwin/lib/libobject-187acb73fb221979.rlib" "/nix/store/fgi9gjhkcp8jjphf5z1qi24sc9zcy361-rust-stable-2024-04-09/lib/rustlib/aarch64-apple-darwin/lib/libmemchr-f379d77720ea5d52.rlib" "/nix/store/fgi9gjhkcp8jjphf5z1qi24sc9zcy361-rust-stable-2024-04-09/lib/rustlib/aarch64-apple-darwin/lib/libaddr2line-5f995b6402184362.rlib" "/nix/store/fgi9gjhkcp8jjphf5z1qi24sc9zcy361-rust-stable-2024-04-09/lib/rustlib/aarch64-apple-darwin/lib/libgimli-6d4646231255d040.rlib" "/nix/store/fgi9gjhkcp8jjphf5z1qi24sc9zcy361-rust-stable-2024-04-09/lib/rustlib/aarch64-apple-darwin/lib/librustc_demangle-ddf92ea3297b7931.rlib" "/nix/store/fgi9gjhkcp8jjphf5z1qi24sc9zcy361-rust-stable-2024-04-09/lib/rustlib/aarch64-apple-darwin/lib/libstd_detect-4bd9fc9ff7289783.rlib" "/nix/store/fgi9gjhkcp8jjphf5z1qi24sc9zcy361-rust-stable-2024-04-09/lib/rustlib/aarch64-apple-darwin/lib/libhashbrown-bbf01e0821f9af8a.rlib" "/nix/store/fgi9gjhkcp8jjphf5z1qi24sc9zcy361-rust-stable-2024-04-09/lib/rustlib/aarch64-apple-darwin/lib/librustc_std_workspace_alloc-df3ad4119d36f143.rlib" "/nix/store/fgi9gjhkcp8jjphf5z1qi24sc9zcy361-rust-stable-2024-04-09/lib/rustlib/aarch64-apple-darwin/lib/libminiz_oxide-3839cef552c2783c.rlib" "/nix/store/fgi9gjhkcp8jjphf5z1qi24sc9zcy361-rust-stable-2024-04-09/lib/rustlib/aarch64-apple-darwin/lib/libadler-130a17e70576817a.rlib" "/nix/store/fgi9gjhkcp8jjphf5z1qi24sc9zcy361-rust-stable-2024-04-09/lib/rustlib/aarch64-apple-darwin/lib/libunwind-f7bc4dcd41ebfabc.rlib" "/nix/store/fgi9gjhkcp8jjphf5z1qi24sc9zcy361-rust-stable-2024-04-09/lib/rustlib/aarch64-apple-darwin/lib/libcfg_if-3b8c9f0215d4bce7.rlib" "/nix/store/fgi9gjhkcp8jjphf5z1qi24sc9zcy361-rust-stable-2024-04-09/lib/rustlib/aarch64-apple-darwin/lib/liblibc-8e6430dafe1e0d1f.rlib" "/nix/store/fgi9gjhkcp8jjphf5z1qi24sc9zcy361-rust-stable-2024-04-09/lib/rustlib/aarch64-apple-darwin/lib/liballoc-9d92a40a452d227c.rlib" "/nix/store/fgi9gjhkcp8jjphf5z1qi24sc9zcy361-rust-stable-2024-04-09/lib/rustlib/aarch64-apple-darwin/lib/librustc_std_workspace_core-fb23eb00feddf1cb.rlib" "/nix/store/fgi9gjhkcp8jjphf5z1qi24sc9zcy361-rust-stable-2024-04-09/lib/rustlib/aarch64-apple-darwin/lib/libcore-c6577f5d4f5dcd9a.rlib" "/nix/store/fgi9gjhkcp8jjphf5z1qi24sc9zcy361-rust-stable-2024-04-09/lib/rustlib/aarch64-apple-darwin/lib/libcompiler_builtins-6d556b0e8bf6f23e.rlib" "-lc" "-lm" "-liconv" "-lSystem" "-lc" "-lm" "-L" "/nix/store/4yqg7kka35j1zayghs6d4vrzbahak3yv-rust-stable-2024-04-09/lib/rustlib/aarch64-apple-darwin/lib" "-o" "/private/tmp/nix-build-cargo-pgrx-deps-0.12.0-alpha.1.drv-0/source/target/release/build/ring-1484f7d9333b717b/build_script_build-1484f7d9333b717b" "-Wl,-dead_strip" "-nodefaultlibs" "-Wl,-undefined,dynamic_lookup"
       >   = note: ld: library not found for -liconv
       >           clang-16: error: linker command failed with exit code 1 (use -v to see invocation)
       >           
       >
       > error: could not compile `ring` (build script) due to 1 previous error
       For full logs, run 'nix log /nix/store/dcipgim0myrpaz0hv9j8lbf2hwxhq08p-cargo-pgrx-deps-0.12.0-alpha.1.drv'.
error: 1 dependencies of derivation '/nix/store/7hhna806byipaq04dvkls3w1ic245pbi-cargo-pgrx-0.12.0-alpha.1.drv' failed to build

@justinrubek
Copy link
Author

@justinrubek You asked me on the pgrx discord to post this on this PR:

I saw you had an example repo (pgrx-nix-example), and gave it a spin. I ran nix develop and got this error:

error: flake 'git+file:///home/x/code/x/pgrx-nix-example' does not provide attribute
 'devShells.aarch64-linux.default', 'devShell.aarch64-linux', 'packages.aarch64-linux.default'
  or 'defaultPackage.aarch64-linux'
       Did you mean devShells?

Happy to provide additional debug info if you'd like.

That example doesn't provide a devShell so nix develop won't work. You should be able to do nix build .#pgrx-arrays from that repo and have the build succeed. If not, then it'll need to be addressed. I figured a devShell wouldn't be necessary for that particular example because it's primarily to show that the build works.

Sidenote: I've not been active on the discord, so it wasn't me that sent you here. Nevertheless, I will provide assistance as best as I can.

@justinrubek
Copy link
Author

@justinrubek if I build on aarch64-darwin I see the following error

nix build .#cargo-pgrx
error:
       … while calling the 'derivationStrict' builtin
         at <nix/derivation-internal.nix>:9:12:
            8|
            9|   strict = derivationStrict drvAttrs;
             |            ^
           10|

       … while evaluating derivation 'cargo-pgrx-0.12.0-alpha.1'
         whose name attribute is located at /nix/store/370qy3d3wg9zhbn5a3dcv6k1q1iigfh4-source/pkgs/stdenv/generic/make-derivation.nix:331:7

       … while evaluating attribute 'buildInputs' of derivation 'cargo-pgrx-0.12.0-alpha.1'
         at /nix/store/370qy3d3wg9zhbn5a3dcv6k1q1iigfh4-source/pkgs/stdenv/generic/make-derivation.nix:378:7:
          377|       depsHostHost                = elemAt (elemAt dependencies 1) 0;
          378|       buildInputs                 = elemAt (elemAt dependencies 1) 1;
             |       ^
          379|       depsTargetTarget            = elemAt (elemAt dependencies 2) 0;

       error: attribute 'Security' missing
       at /nix/store/pqvlaf0ga3czljdf3yc14kmyc6i2a6gv-source/flake.nix:38:81:
           37|             nativeBuildInputs = [pkgs.pkg-config];
           38|             buildInputs = [pkgs.openssl] ++ lib.optionals pkgs.stdenv.isDarwin [pkgs.Security];
             |                                                                                 ^
           39|             # fixes to enable running pgrx tests

I think you will actually need this

diff --git a/flake.nix b/flake.nix
index d9cc60bf..164686ee 100644
--- a/flake.nix
+++ b/flake.nix
@@ -35,7 +35,7 @@
             inherit (craneLib.crateNameFromCargoToml {cargoToml = ./cargo-pgrx/Cargo.toml;}) pname version;
             cargoExtraArgs = "--package cargo-pgrx";
             nativeBuildInputs = [pkgs.pkg-config];
-            buildInputs = [pkgs.openssl] ++ lib.optionals pkgs.stdenv.isDarwin [pkgs.Security];
+            buildInputs = [pkgs.openssl] ++ lib.optionals pkgs.stdenv.isDarwin [pkgs.darwin.apple_sdk.frameworks.Security];
             # fixes to enable running pgrx tests
             preCheck = ''
               export PGRX_HOME=$(mktemp -d)

However, even with that patch, which stops the nix build from erroring, I am now running into the same issue I see on our supabase extenions when building on aarch64-darwin which is related to linking failures

nix build .#cargo-pgrx
warning: Git tree '/Users/samrose/pgrx' is dirty
error: builder for '/nix/store/dcipgim0myrpaz0hv9j8lbf2hwxhq08p-cargo-pgrx-deps-0.12.0-alpha.1.drv' failed with exit code 101;
       last 25 log lines:
       >    Compiling camino v1.1.6
       >    Compiling ring v0.17.7
       >    Compiling semver v1.0.21
       >     Checking colorchoice v1.0.0
       >     Checking anstyle v1.0.4
       >    Compiling bzip2-sys v0.1.11+1.0.8
       >     Checking terminal_size v0.3.0
       >     Checking anstream v0.6.11
       > error: linking with `cc` failed: exit status: 1
       >   |
       >   = note: env -u IPHONEOS_DEPLOYMENT_TARGET -u TVOS_DEPLOYMENT_TARGET LC_ALL="C" PATH="/nix/store/4yqg7kka35j1zayghs6d4vrzbahak3yv-rust-stable-2024-04-09/lib/rustlib/aarch64-apple-darwin/bin:/nix/store/3l8pzzkvvihqj5z1bymn5zcsm1a3gmp9-pkg-config-wrapper-0.29.2/bin:/nix/store/4yqg7kka35j1zayghs6d4vrzbahak3yv-rust-stable-2024-04-09/bin:/nix/store/lmn0856fjg2h00dbkgd0yi7dg2i1czrq-rsync-3.2.7/bin:/nix/store/vbgzzan67ycvwn6in3kpy9hkfckkkwyj-zstd-1.5.6-bin/bin:/nix/store/q95gkmqc1lb69dcclz3cxxhw79hsyrh5-zstd-1.5.6/bin:/nix/store/v4p0piwwk3a9gwrhvxa8b04ljd1arviz-clang-wrapper-16.0.6/bin:/nix/store/kq25mdy9byl6pgv3n0vsa85p6807zaqy-clang-16.0.6/bin:/nix/store/ssqkq33b9jb441g7baplb87z8vnyp34i-coreutils-9.5/bin:/nix/store/3b25yj6dyrjy76sq953a6sy1xb22lgv1-cctools-binutils-darwin-wrapper-16.0.6-973.0.1/bin:/nix/store/73x46ri7fbdfl062vnxv1dq10isyh4jh-cctools-binutils-darwin-16.0.6-973.0.1/bin:/nix/store/n8xzpnjww9iqlh7h9mdm6kx3lbqkpa50-openssl-3.0.13-bin/bin:/nix/store/ssqkq33b9jb441g7baplb87z8vnyp34i-coreutils-9.5/bin:/nix/store/f2zkblkcbxvgczjdxa53xn8d0652d4x0-findutils-4.9.0/bin:/nix/store/l9k0z4wc8lhkpdfalhgb1wd4950vb08p-diffutils-3.10/bin:/nix/store/7bv9z3svwrqc9jlxbk5mamnahfvpm2vp-gnused-4.9/bin:/nix/store/w57dxm682rl3b7ayf7ay8lsy9lkzmh7z-gnugrep-3.11/bin:/nix/store/33g5y7bqsrlpidlk43b8gc518wc784q9-gawk-5.2.2/bin:/nix/store/f8pcjixa8bq9558vhycbvv9sm27hmxad-gnutar-1.35/bin:/nix/store/qvfwvhllwqrnybcvzqrn0694bzwqvb66-gzip-1.13/bin:/nix/store/7gqdnz03xicalizs8fwn9c28lahclg8a-bzip2-1.0.8-bin/bin:/nix/store/1cjkrg6qi2hqvl2j9arrhda5ik3dw707-gnumake-4.4.1/bin:/nix/store/lp3ginchcanhcj4dgw6yzdgv8bgdkm1v-bash-5.2p26/bin:/nix/store/pxz0p3jywa3jnf29pm3hxgrhkd33f2q7-patch-2.7.6/bin:/nix/store/ywxnlqjizsxcz0q0gygwfazrglhd1s8v-xz-5.4.6-bin/bin:/nix/store/7pjzfb020206fayckw22z29nvsz4r7ks-file-5.45/bin" VSLANG="1033" ZERO_AR_DATE="1" "cc" "-arch" "arm64" "/private/tmp/nix-build-cargo-pgrx-deps-0.12.0-alpha.1.drv-0/rustc3VbzXd/symbols.o" "/private/tmp/nix-build-cargo-pgrx-deps-0.12.0-alpha.1.drv-0/source/target/release/build/bzip2-sys-d7a03512998fb2e6/build_script_build-d7a03512998fb2e6.build_script_build.51ec6b185fc5d53e-cgu.0.rcgu.o" "/private/tmp/nix-build-cargo-pgrx-deps-0.12.0-alpha.1.drv-0/source/target/release/build/bzip2-sys-d7a03512998fb2e6/build_script_build-d7a03512998fb2e6.wof29p7it4g8gow.rcgu.o" "-L" "/private/tmp/nix-build-cargo-pgrx-deps-0.12.0-alpha.1.drv-0/source/target/release/deps" "-L" "/nix/store/4yqg7kka35j1zayghs6d4vrzbahak3yv-rust-stable-2024-04-09/lib/rustlib/aarch64-apple-darwin/lib" "/private/tmp/nix-build-cargo-pgrx-deps-0.12.0-alpha.1.drv-0/source/target/release/deps/libpkg_config-a41bef66e297552e.rlib" "/private/tmp/nix-build-cargo-pgrx-deps-0.12.0-alpha.1.drv-0/source/target/release/deps/libcc-5799af08f211fc33.rlib" "/private/tmp/nix-build-cargo-pgrx-deps-0.12.0-alpha.1.drv-0/source/target/release/deps/liblibc-753c7acb4e5b4024.rlib" "/nix/store/fgi9gjhkcp8jjphf5z1qi24sc9zcy361-rust-stable-2024-04-09/lib/rustlib/aarch64-apple-darwin/lib/libstd-b7bbc4a3799f91ec.rlib" "/nix/store/fgi9gjhkcp8jjphf5z1qi24sc9zcy361-rust-stable-2024-04-09/lib/rustlib/aarch64-apple-darwin/lib/libpanic_unwind-9a832f29e113f2ac.rlib" "/nix/store/fgi9gjhkcp8jjphf5z1qi24sc9zcy361-rust-stable-2024-04-09/lib/rustlib/aarch64-apple-darwin/lib/libobject-187acb73fb221979.rlib" "/nix/store/fgi9gjhkcp8jjphf5z1qi24sc9zcy361-rust-stable-2024-04-09/lib/rustlib/aarch64-apple-darwin/lib/libmemchr-f379d77720ea5d52.rlib" "/nix/store/fgi9gjhkcp8jjphf5z1qi24sc9zcy361-rust-stable-2024-04-09/lib/rustlib/aarch64-apple-darwin/lib/libaddr2line-5f995b6402184362.rlib" "/nix/store/fgi9gjhkcp8jjphf5z1qi24sc9zcy361-rust-stable-2024-04-09/lib/rustlib/aarch64-apple-darwin/lib/libgimli-6d4646231255d040.rlib" "/nix/store/fgi9gjhkcp8jjphf5z1qi24sc9zcy361-rust-stable-2024-04-09/lib/rustlib/aarch64-apple-darwin/lib/librustc_demangle-ddf92ea3297b7931.rlib" "/nix/store/fgi9gjhkcp8jjphf5z1qi24sc9zcy361-rust-stable-2024-04-09/lib/rustlib/aarch64-apple-darwin/lib/libstd_detect-4bd9fc9ff7289783.rlib" "/nix/store/fgi9gjhkcp8jjphf5z1qi24sc9zcy361-rust-stable-2024-04-09/lib/rustlib/aarch64-apple-darwin/lib/libhashbrown-bbf01e0821f9af8a.rlib" "/nix/store/fgi9gjhkcp8jjphf5z1qi24sc9zcy361-rust-stable-2024-04-09/lib/rustlib/aarch64-apple-darwin/lib/librustc_std_workspace_alloc-df3ad4119d36f143.rlib" "/nix/store/fgi9gjhkcp8jjphf5z1qi24sc9zcy361-rust-stable-2024-04-09/lib/rustlib/aarch64-apple-darwin/lib/libminiz_oxide-3839cef552c2783c.rlib" "/nix/store/fgi9gjhkcp8jjphf5z1qi24sc9zcy361-rust-stable-2024-04-09/lib/rustlib/aarch64-apple-darwin/lib/libadler-130a17e70576817a.rlib" "/nix/store/fgi9gjhkcp8jjphf5z1qi24sc9zcy361-rust-stable-2024-04-09/lib/rustlib/aarch64-apple-darwin/lib/libunwind-f7bc4dcd41ebfabc.rlib" "/nix/store/fgi9gjhkcp8jjphf5z1qi24sc9zcy361-rust-stable-2024-04-09/lib/rustlib/aarch64-apple-darwin/lib/libcfg_if-3b8c9f0215d4bce7.rlib" "/nix/store/fgi9gjhkcp8jjphf5z1qi24sc9zcy361-rust-stable-2024-04-09/lib/rustlib/aarch64-apple-darwin/lib/liblibc-8e6430dafe1e0d1f.rlib" "/nix/store/fgi9gjhkcp8jjphf5z1qi24sc9zcy361-rust-stable-2024-04-09/lib/rustlib/aarch64-apple-darwin/lib/liballoc-9d92a40a452d227c.rlib" "/nix/store/fgi9gjhkcp8jjphf5z1qi24sc9zcy361-rust-stable-2024-04-09/lib/rustlib/aarch64-apple-darwin/lib/librustc_std_workspace_core-fb23eb00feddf1cb.rlib" "/nix/store/fgi9gjhkcp8jjphf5z1qi24sc9zcy361-rust-stable-2024-04-09/lib/rustlib/aarch64-apple-darwin/lib/libcore-c6577f5d4f5dcd9a.rlib" "/nix/store/fgi9gjhkcp8jjphf5z1qi24sc9zcy361-rust-stable-2024-04-09/lib/rustlib/aarch64-apple-darwin/lib/libcompiler_builtins-6d556b0e8bf6f23e.rlib" "-lc" "-lm" "-liconv" "-lSystem" "-lc" "-lm" "-L" "/nix/store/4yqg7kka35j1zayghs6d4vrzbahak3yv-rust-stable-2024-04-09/lib/rustlib/aarch64-apple-darwin/lib" "-o" "/private/tmp/nix-build-cargo-pgrx-deps-0.12.0-alpha.1.drv-0/source/target/release/build/bzip2-sys-d7a03512998fb2e6/build_script_build-d7a03512998fb2e6" "-Wl,-dead_strip" "-nodefaultlibs" "-Wl,-undefined,dynamic_lookup"
       >   = note: ld: library not found for -liconv
       >           clang-16: error: linker command failed with exit code 1 (use -v to see invocation)
       >           
       >
       > error: could not compile `bzip2-sys` (build script) due to 1 previous error
       > warning: build failed, waiting for other jobs to finish...
       > error: linking with `cc` failed: exit status: 1
       >   |
       >   = note: env -u IPHONEOS_DEPLOYMENT_TARGET -u TVOS_DEPLOYMENT_TARGET LC_ALL="C" PATH="/nix/store/4yqg7kka35j1zayghs6d4vrzbahak3yv-rust-stable-2024-04-09/lib/rustlib/aarch64-apple-darwin/bin:/nix/store/3l8pzzkvvihqj5z1bymn5zcsm1a3gmp9-pkg-config-wrapper-0.29.2/bin:/nix/store/4yqg7kka35j1zayghs6d4vrzbahak3yv-rust-stable-2024-04-09/bin:/nix/store/lmn0856fjg2h00dbkgd0yi7dg2i1czrq-rsync-3.2.7/bin:/nix/store/vbgzzan67ycvwn6in3kpy9hkfckkkwyj-zstd-1.5.6-bin/bin:/nix/store/q95gkmqc1lb69dcclz3cxxhw79hsyrh5-zstd-1.5.6/bin:/nix/store/v4p0piwwk3a9gwrhvxa8b04ljd1arviz-clang-wrapper-16.0.6/bin:/nix/store/kq25mdy9byl6pgv3n0vsa85p6807zaqy-clang-16.0.6/bin:/nix/store/ssqkq33b9jb441g7baplb87z8vnyp34i-coreutils-9.5/bin:/nix/store/3b25yj6dyrjy76sq953a6sy1xb22lgv1-cctools-binutils-darwin-wrapper-16.0.6-973.0.1/bin:/nix/store/73x46ri7fbdfl062vnxv1dq10isyh4jh-cctools-binutils-darwin-16.0.6-973.0.1/bin:/nix/store/n8xzpnjww9iqlh7h9mdm6kx3lbqkpa50-openssl-3.0.13-bin/bin:/nix/store/ssqkq33b9jb441g7baplb87z8vnyp34i-coreutils-9.5/bin:/nix/store/f2zkblkcbxvgczjdxa53xn8d0652d4x0-findutils-4.9.0/bin:/nix/store/l9k0z4wc8lhkpdfalhgb1wd4950vb08p-diffutils-3.10/bin:/nix/store/7bv9z3svwrqc9jlxbk5mamnahfvpm2vp-gnused-4.9/bin:/nix/store/w57dxm682rl3b7ayf7ay8lsy9lkzmh7z-gnugrep-3.11/bin:/nix/store/33g5y7bqsrlpidlk43b8gc518wc784q9-gawk-5.2.2/bin:/nix/store/f8pcjixa8bq9558vhycbvv9sm27hmxad-gnutar-1.35/bin:/nix/store/qvfwvhllwqrnybcvzqrn0694bzwqvb66-gzip-1.13/bin:/nix/store/7gqdnz03xicalizs8fwn9c28lahclg8a-bzip2-1.0.8-bin/bin:/nix/store/1cjkrg6qi2hqvl2j9arrhda5ik3dw707-gnumake-4.4.1/bin:/nix/store/lp3ginchcanhcj4dgw6yzdgv8bgdkm1v-bash-5.2p26/bin:/nix/store/pxz0p3jywa3jnf29pm3hxgrhkd33f2q7-patch-2.7.6/bin:/nix/store/ywxnlqjizsxcz0q0gygwfazrglhd1s8v-xz-5.4.6-bin/bin:/nix/store/7pjzfb020206fayckw22z29nvsz4r7ks-file-5.45/bin" VSLANG="1033" ZERO_AR_DATE="1" "cc" "-arch" "arm64" "/private/tmp/nix-build-cargo-pgrx-deps-0.12.0-alpha.1.drv-0/rustcP1hL1g/symbols.o" "/private/tmp/nix-build-cargo-pgrx-deps-0.12.0-alpha.1.drv-0/source/target/release/build/ring-1484f7d9333b717b/build_script_build-1484f7d9333b717b.build_script_build.e0674a3a45294900-cgu.0.rcgu.o" "/private/tmp/nix-build-cargo-pgrx-deps-0.12.0-alpha.1.drv-0/source/target/release/build/ring-1484f7d9333b717b/build_script_build-1484f7d9333b717b.build_script_build.e0674a3a45294900-cgu.1.rcgu.o" "/private/tmp/nix-build-cargo-pgrx-deps-0.12.0-alpha.1.drv-0/source/target/release/build/ring-1484f7d9333b717b/build_script_build-1484f7d9333b717b.build_script_build.e0674a3a45294900-cgu.2.rcgu.o" "/private/tmp/nix-build-cargo-pgrx-deps-0.12.0-alpha.1.drv-0/source/target/release/build/ring-1484f7d9333b717b/build_script_build-1484f7d9333b717b.build_script_build.e0674a3a45294900-cgu.3.rcgu.o" "/private/tmp/nix-build-cargo-pgrx-deps-0.12.0-alpha.1.drv-0/source/target/release/build/ring-1484f7d9333b717b/build_script_build-1484f7d9333b717b.build_script_build.e0674a3a45294900-cgu.4.rcgu.o" "/private/tmp/nix-build-cargo-pgrx-deps-0.12.0-alpha.1.drv-0/source/target/release/build/ring-1484f7d9333b717b/build_script_build-1484f7d9333b717b.build_script_build.e0674a3a45294900-cgu.5.rcgu.o" "/private/tmp/nix-build-cargo-pgrx-deps-0.12.0-alpha.1.drv-0/source/target/release/build/ring-1484f7d9333b717b/build_script_build-1484f7d9333b717b.3h4rrxooxoiwc60m.rcgu.o" "-L" "/private/tmp/nix-build-cargo-pgrx-deps-0.12.0-alpha.1.drv-0/source/target/release/deps" "-L" "/nix/store/4yqg7kka35j1zayghs6d4vrzbahak3yv-rust-stable-2024-04-09/lib/rustlib/aarch64-apple-darwin/lib" "/private/tmp/nix-build-cargo-pgrx-deps-0.12.0-alpha.1.drv-0/source/target/release/deps/libcc-5799af08f211fc33.rlib" "/private/tmp/nix-build-cargo-pgrx-deps-0.12.0-alpha.1.drv-0/source/target/release/deps/liblibc-753c7acb4e5b4024.rlib" "/nix/store/fgi9gjhkcp8jjphf5z1qi24sc9zcy361-rust-stable-2024-04-09/lib/rustlib/aarch64-apple-darwin/lib/libstd-b7bbc4a3799f91ec.rlib" "/nix/store/fgi9gjhkcp8jjphf5z1qi24sc9zcy361-rust-stable-2024-04-09/lib/rustlib/aarch64-apple-darwin/lib/libpanic_unwind-9a832f29e113f2ac.rlib" "/nix/store/fgi9gjhkcp8jjphf5z1qi24sc9zcy361-rust-stable-2024-04-09/lib/rustlib/aarch64-apple-darwin/lib/libobject-187acb73fb221979.rlib" "/nix/store/fgi9gjhkcp8jjphf5z1qi24sc9zcy361-rust-stable-2024-04-09/lib/rustlib/aarch64-apple-darwin/lib/libmemchr-f379d77720ea5d52.rlib" "/nix/store/fgi9gjhkcp8jjphf5z1qi24sc9zcy361-rust-stable-2024-04-09/lib/rustlib/aarch64-apple-darwin/lib/libaddr2line-5f995b6402184362.rlib" "/nix/store/fgi9gjhkcp8jjphf5z1qi24sc9zcy361-rust-stable-2024-04-09/lib/rustlib/aarch64-apple-darwin/lib/libgimli-6d4646231255d040.rlib" "/nix/store/fgi9gjhkcp8jjphf5z1qi24sc9zcy361-rust-stable-2024-04-09/lib/rustlib/aarch64-apple-darwin/lib/librustc_demangle-ddf92ea3297b7931.rlib" "/nix/store/fgi9gjhkcp8jjphf5z1qi24sc9zcy361-rust-stable-2024-04-09/lib/rustlib/aarch64-apple-darwin/lib/libstd_detect-4bd9fc9ff7289783.rlib" "/nix/store/fgi9gjhkcp8jjphf5z1qi24sc9zcy361-rust-stable-2024-04-09/lib/rustlib/aarch64-apple-darwin/lib/libhashbrown-bbf01e0821f9af8a.rlib" "/nix/store/fgi9gjhkcp8jjphf5z1qi24sc9zcy361-rust-stable-2024-04-09/lib/rustlib/aarch64-apple-darwin/lib/librustc_std_workspace_alloc-df3ad4119d36f143.rlib" "/nix/store/fgi9gjhkcp8jjphf5z1qi24sc9zcy361-rust-stable-2024-04-09/lib/rustlib/aarch64-apple-darwin/lib/libminiz_oxide-3839cef552c2783c.rlib" "/nix/store/fgi9gjhkcp8jjphf5z1qi24sc9zcy361-rust-stable-2024-04-09/lib/rustlib/aarch64-apple-darwin/lib/libadler-130a17e70576817a.rlib" "/nix/store/fgi9gjhkcp8jjphf5z1qi24sc9zcy361-rust-stable-2024-04-09/lib/rustlib/aarch64-apple-darwin/lib/libunwind-f7bc4dcd41ebfabc.rlib" "/nix/store/fgi9gjhkcp8jjphf5z1qi24sc9zcy361-rust-stable-2024-04-09/lib/rustlib/aarch64-apple-darwin/lib/libcfg_if-3b8c9f0215d4bce7.rlib" "/nix/store/fgi9gjhkcp8jjphf5z1qi24sc9zcy361-rust-stable-2024-04-09/lib/rustlib/aarch64-apple-darwin/lib/liblibc-8e6430dafe1e0d1f.rlib" "/nix/store/fgi9gjhkcp8jjphf5z1qi24sc9zcy361-rust-stable-2024-04-09/lib/rustlib/aarch64-apple-darwin/lib/liballoc-9d92a40a452d227c.rlib" "/nix/store/fgi9gjhkcp8jjphf5z1qi24sc9zcy361-rust-stable-2024-04-09/lib/rustlib/aarch64-apple-darwin/lib/librustc_std_workspace_core-fb23eb00feddf1cb.rlib" "/nix/store/fgi9gjhkcp8jjphf5z1qi24sc9zcy361-rust-stable-2024-04-09/lib/rustlib/aarch64-apple-darwin/lib/libcore-c6577f5d4f5dcd9a.rlib" "/nix/store/fgi9gjhkcp8jjphf5z1qi24sc9zcy361-rust-stable-2024-04-09/lib/rustlib/aarch64-apple-darwin/lib/libcompiler_builtins-6d556b0e8bf6f23e.rlib" "-lc" "-lm" "-liconv" "-lSystem" "-lc" "-lm" "-L" "/nix/store/4yqg7kka35j1zayghs6d4vrzbahak3yv-rust-stable-2024-04-09/lib/rustlib/aarch64-apple-darwin/lib" "-o" "/private/tmp/nix-build-cargo-pgrx-deps-0.12.0-alpha.1.drv-0/source/target/release/build/ring-1484f7d9333b717b/build_script_build-1484f7d9333b717b" "-Wl,-dead_strip" "-nodefaultlibs" "-Wl,-undefined,dynamic_lookup"
       >   = note: ld: library not found for -liconv
       >           clang-16: error: linker command failed with exit code 1 (use -v to see invocation)
       >           
       >
       > error: could not compile `ring` (build script) due to 1 previous error
       For full logs, run 'nix log /nix/store/dcipgim0myrpaz0hv9j8lbf2hwxhq08p-cargo-pgrx-deps-0.12.0-alpha.1.drv'.
error: 1 dependencies of derivation '/nix/store/7hhna806byipaq04dvkls3w1ic245pbi-cargo-pgrx-0.12.0-alpha.1.drv' failed to build

It's hard for me to test darwin builds, but I believe that the optional darwin portion needs pkgs.libiconv as well. If you could add that and see if other issues persist, I'd appreciate it. I'll get those changes in soon, but don't have a way to test it currently.

@samrose
Copy link

samrose commented Jun 10, 2024

@justinrubek yaeh sure, I have an aarch64-darwin machine right here, count me in on helping you with this I'll try that let you know and keep trying to build this for you too

@samrose
Copy link

samrose commented Jun 10, 2024

@justinrubek that did it for aarch64-darwin!

diff --git a/flake.nix b/flake.nix
index d9cc60bf..4a00c9be 100644
--- a/flake.nix
+++ b/flake.nix
@@ -35,7 +35,7 @@
             inherit (craneLib.crateNameFromCargoToml {cargoToml = ./cargo-pgrx/Cargo.toml;}) pname version;
             cargoExtraArgs = "--package cargo-pgrx";
             nativeBuildInputs = [pkgs.pkg-config];
-            buildInputs = [pkgs.openssl] ++ lib.optionals pkgs.stdenv.isDarwin [pkgs.Security];
+            buildInputs = [pkgs.openssl] ++ lib.optionals pkgs.stdenv.isDarwin [pkgs.darwin.apple_sdk.frameworks.Security pkgs.libiconv];
             # fixes to enable running pgrx tests
             preCheck = ''
               export PGRX_HOME=$(mktemp -d)

builds successfully with those changes on aarch64-darwin

@samrose
Copy link

samrose commented Jun 10, 2024

tested and confirmed project builds on aarch64-linux too

@samrose
Copy link

samrose commented Jun 10, 2024

@justinrubek justinrubek#1

@ahacop
Copy link

ahacop commented Jun 10, 2024

That example doesn't provide a devShell so nix develop won't work. You should be able to do nix build .#pgrx-arrays from that repo and have the build succeed.

@justinrubek OK, thanks for the explanation. Yes, it worked perfectly. Sorry for the distraction!

@samrose
Copy link

samrose commented Jul 2, 2024

@justinrubek @workingjubilee I'd love to try and help move this forward if possible. Let me know if there are things I can try to take on beyond testing on aarch64-darwin

@justinrubek
Copy link
Author

@justinrubek @workingjubilee I'd love to try and help move this forward if possible. Let me know if there are things I can try to take on beyond testing on aarch64-darwin

The main thing left would be to address the request from this comment #1683 (comment)

We need to provide enough information for the maintainers to feel comfortable having this code without it decaying. Things like updating the flake inputs and a test case with the example project. I've been particularly busy since opening this so I haven't started on it. I'm not sure where the mentioned book is. Those things would be good to take on.

@samrose
Copy link

samrose commented Jul 2, 2024

@justinrubek thanks. I am also trying to specifically build an aarch64-darwin build of the pgrx-nix-example running into issues with it, but once I have that working I can connect and see how that can be integrated, too.

@justinrubek
Copy link
Author

@samrose Just to be clear, that example project isn't going to be integrated into this project. They would want the extension generated using cargo pgrx new foo to work. I don't think it's bad to make my example repo work, but that isn't something that will become official. I ripped that out from one of the examples, so it's good for debugging, but ultimately, it won't help with this PR.

@samrose
Copy link

samrose commented Jul 2, 2024

@justinrubek makes sense. I would need to make this PR work, plus make your example work using the builder buildPgrxExtension on aarch64-darwin in order to get what I need out of this work.

I may gain some insights by trying to use the builder on different systems that could help this PR I believe.

But I'll also help here with #1683 (comment)

@samrose
Copy link

samrose commented Nov 2, 2024

Coming back to this now. I believe the hanging tasks here were #1683 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants