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

Support arbitrary stores in Perl bindings #9863

Merged
merged 1 commit into from
Feb 8, 2024

Conversation

Ericson2314
Copy link
Member

Motivation

Fix #9859

Context

It's a breaking change but that's fine; we can just update Hydra to use the new bindings.

Priorities and Process

Add 👍 to pull requests you find important.

The Nix maintainer team uses a GitHub project board to schedule and track reviews.

CC @Ma27

perl/lib/Nix/Store.xs Outdated Show resolved Hide resolved
@Ericson2314 Ericson2314 marked this pull request as draft January 29, 2024 15:44
@Ericson2314
Copy link
Member Author

I'll keep this a draft until we have a draft of the Hydra changes ready to go, CC @Ma27.


use Nix::Store;

my $s = new Nix::Store("dummy://");
Copy link
Member

Choose a reason for hiding this comment

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

fwiw perlcritic complains about that and suggests to use Nix::Store->new() instead (noticed that while modifying Hydra for that).

Copy link
Member Author

Choose a reason for hiding this comment

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

Fine with me! I don't know Perl enough to disagree :)

Ma27 added a commit to Ma27/hydra that referenced this pull request Feb 7, 2024
Implements support for Nix's new Perl bindings[1]. The current state
basically does `openStore()`, but always uses `auto` and doesn't support
stores at other URIs.

Even though the stores are cached inside the Perl implementation, I
decided to instantiate those once in the Nix helper module. That way
store openings aren't cluttered across the entire codebase. Also, there
are two stores used later on - MACHINE_LOCAL_STORE for `auto`,
BINARY_CACHE_STORE for the one from `store_uri` in `hydra.conf` - and
using consistent names should make the intent clearer then.

This doesn't contain any behavioral changes, i.e. the build product
availability issue from NixOS#1352 isn't fixed. This patch only contains the
migration to the new API.

[1] NixOS/nix#9863
@Ericson2314
Copy link
Member Author

NixOS/hydra#1359 is here, so undrafting!

@Ericson2314 Ericson2314 marked this pull request as ready for review February 7, 2024 14:30
Copy link
Contributor

@tomberek tomberek left a comment

Choose a reason for hiding this comment

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

does newRV_noinc need to be available, got compiled away?

I'm getting:

$ perl -I ./result/lib/perl5/site_perl/5.36.0 -e 'use Nix::Store;'
Can't load './result/lib/perl5/site_perl/5.36.0/x86_64-linux-thread-multi/auto/Nix/Store/Store.so' for module Nix::Store: ./result/lib/perl5/site_perl/5.36.0/x86_64-linux-thread-multi/auto/Nix/Store/Store.so: undefined symbol: Perl_newRV_noinc at /nix/store/sjm6zhcjq1l6ghcal55vmpy48zd0rhm7-perl-5.38.2/lib/perl5/5.38.2/x86_64-linux-thread-multi/DynaLoader.pm line 206.
 at -e line 1.
Compilation failed in require at -e line 1.
BEGIN failed--compilation aborted at -e line 1.

(or i'm using perl wrong, very likely)

Fix NixOS#9859

It's a breaking change but that's fine; we can just update Hydra to use
the new bindings.
@Ericson2314
Copy link
Member Author

Not really sure @tomberek, I don't know it well either. I updated the pm file maybe that will make a difference.

Comment on lines +61 to +62
if (!libStoreInitialized) {
initLibStore();
Copy link
Member

Choose a reason for hiding this comment

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

initLibStore() internally already has a initLibStoreDone flag, so libStoreInitialized seems superfluous.

Copy link
Member Author

Choose a reason for hiding this comment

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

That seems to be for a slightly different purpose? It doesn't make it run one, it just makes sure you ran it at least once.

(It could work the way this does, but I rather do that in a follow-up PR.)

libStoreInitialized = true;
}
if (items == 1) {
_store = openStore();
Copy link
Member

@edolstra edolstra Feb 8, 2024

Choose a reason for hiding this comment

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

It's nicer to use the static initializer trick (because it's atomic), i.e.

    static auto _store = {( openStore(); )};
    RETVAL = new StoreWrapper {
        .store = ref<Store>{_store}
    };

Copy link
Member Author

Choose a reason for hiding this comment

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

Wouldn't that mean the default store is always opened?

@Ericson2314
Copy link
Member Author

Ericson2314 commented Feb 8, 2024

Because my two questions, I think it would be better to come back to those points in a follow-up PR.

@Ericson2314 Ericson2314 merged commit f2f54cf into NixOS:master Feb 8, 2024
8 checks passed
@Ericson2314 Ericson2314 deleted the perl-open-other-store branch February 8, 2024 14:30
Ma27 added a commit to Ma27/hydra that referenced this pull request Feb 12, 2024
Implements support for Nix's new Perl bindings[1]. The current state
basically does `openStore()`, but always uses `auto` and doesn't support
stores at other URIs.

Even though the stores are cached inside the Perl implementation, I
decided to instantiate those once in the Nix helper module. That way
store openings aren't cluttered across the entire codebase. Also, there
are two stores used later on - MACHINE_LOCAL_STORE for `auto`,
BINARY_CACHE_STORE for the one from `store_uri` in `hydra.conf` - and
using consistent names should make the intent clearer then.

This doesn't contain any behavioral changes, i.e. the build product
availability issue from NixOS#1352 isn't fixed. This patch only contains the
migration to the new API.

[1] NixOS/nix#9863
Ma27 added a commit to Ma27/hydra that referenced this pull request Feb 12, 2024
Implements support for Nix's new Perl bindings[1]. The current state
basically does `openStore()`, but always uses `auto` and doesn't support
stores at other URIs.

Even though the stores are cached inside the Perl implementation, I
decided to instantiate those once in the Nix helper module. That way
store openings aren't cluttered across the entire codebase. Also, there
are two stores used later on - MACHINE_LOCAL_STORE for `auto`,
BINARY_CACHE_STORE for the one from `store_uri` in `hydra.conf` - and
using consistent names should make the intent clearer then.

This doesn't contain any behavioral changes, i.e. the build product
availability issue from NixOS#1352 isn't fixed. This patch only contains the
migration to the new API.

[1] NixOS/nix#9863
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Allow Perl bindings to perform operations on arbitrary stores
4 participants