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

albyhub: init at 1.12.0 #368929

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft

albyhub: init at 1.12.0 #368929

wants to merge 1 commit into from

Conversation

bleetube
Copy link
Contributor

@bleetube bleetube commented Dec 28, 2024

#369196

This turns out to be yarn + Go + CGO + shared libraries Nix derivation. Much of this was new territory for me! I used the Dockerfile as a starting point for how this is supposed to be built.

  • I tried to use autoPatchelfHook to clean the RPATHs, but the resulting binary would still have forbidden references to /build/. So to clean the RPATHs I had to add a postInstall step with patchelf --set-rpath "${lib.makeLibraryPath buildInputs}" $out/bin/http.

Progress:

  • prebuild frontend artifacts
  • buildinput for precompiled ldk_node
  • buildinput for precompiled breez_sdk
  • buildinput for precompiled "glalby_bindings"
  • clean RPATHs
  • build and run http
  • minor cleanup
  • set up build imports, somehow
  • handle the LDK cargo.lock without including the whole thing
  • build breez sdk from source
  • build glalby from source glalby is no longer supported and will be removed
  • rename the binary name from http to albyhub
  • test aarch64 build
  • verify the submodule licenses

Things done

  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandboxing enabled in nix.conf? (See Nix manual)
    • sandbox = relaxed
    • sandbox = true
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • 25.05 Release Notes (or backporting 24.11 and 25.05 Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
  • Fits CONTRIBUTING.md.

Add a 👍 reaction to pull requests you find important.

@bleetube
Copy link
Contributor Author

Here's my discovery notes on ldk-node-go, which is "Experimental Go bindings for LDK-node"

repository at a glance:

$ tree
.
├── go.mod
├── ldk_node
│   ├── aarch64-unknown-linux-gnu
│   │   └── libldk_node.so
│   ├── arm-unknown-linux-gnueabihf
│   │   └── libldk_node.so
│   ├── cgo.go
│   ├── ldk_node.c
│   ├── ldk_node.go
│   ├── ldk_node.h
│   ├── universal-macos
│   │   └── libldk_node.dylib
│   ├── x86_64-pc-windows-gnu
│   │   └── ldk_node.dll
│   ├── x86_64-pc-windows-msvc
│   │   └── ldk_node.dll
│   └── x86_64-unknown-linux-gnu
│       └── libldk_node.so
└── README.md

8 directories, 12 files

The repository structure includes pre-compiled shared libraries (.so, .dll, .dylib) for different architectures and operating systems.
The cgo.go file sets up the necessary CGo directives to link against these pre-compiled libraries based on the target platform.
The ldk_node.c and ldk_node.h files provide the C interface to the Rust library.
The ldk_node.go file contains the Go code that wraps the C interface, making it usable from Go.

In github.com/getAlby/hub the ldk_node package is imported as follows

lnclient/ldk/ldk.go:

head -n37 /home/blee/src/hub/lnclient/ldk/ldk.go
package ldk

import (
        "context"
        "crypto/sha256"
        "database/sql"
        "errors"
        "fmt"
        "math"
        "os"
        "path/filepath"
        "slices"
        "sort"
        "strconv"
        "strings"
        "time"

        "github.com/getAlby/ldk-node-go/ldk_node"
        "github.com/tyler-smith/go-bip32"

        // "github.com/getAlby/hub/ldk_node"

        "encoding/hex"
        "encoding/json"

        decodepay "github.com/nbd-wtf/ln-decodepay"
        "github.com/sirupsen/logrus"

        "github.com/getAlby/hub/config"
        "github.com/getAlby/hub/events"
        "github.com/getAlby/hub/lnclient"
        "github.com/getAlby/hub/logger"
        "github.com/getAlby/hub/lsp"
        "github.com/getAlby/hub/service/keys"
        "github.com/getAlby/hub/utils"
)

Then in github.com/getAlby/hub there's a Dockerfile that essentially runs go build cmd/http/main.go and then runs build/docker/copy_dylibs.sh:

#!/usr/bin/env bash
if [[ "$ARCH" == "amd64" ]]; then
    cp "$(go list -m -f "{{.Dir}}" github.com/breez/breez-sdk-go)"/breez_sdk/lib/linux-amd64/libbreez_sdk_bindings.so ./
    cp "$(go list -m -f "{{.Dir}}" github.com/getAlby/glalby-go)"/glalby/x86_64-unknown-linux-gnu/libglalby_bindings.so ./
    cp "$(go list -m -f "{{.Dir}}" github.com/getAlby/ldk-node-go)"/ldk_node/x86_64-unknown-linux-gnu/libldk_node.so ./
elif [[ "$ARCH" == "arm64" ]]; then
    cp "$(go list -m -f "{{.Dir}}" github.com/breez/breez-sdk-go)"/breez_sdk/lib/linux-aarch64/libbreez_sdk_bindings.so ./
    cp "$(go list -m -f "{{.Dir}}" github.com/getAlby/glalby-go)"/glalby/aarch64-unknown-linux-gnu/libglalby_bindings.so ./
    cp "$(go list -m -f "{{.Dir}}" github.com/getAlby/ldk-node-go)"/ldk_node/aarch64-unknown-linux-gnu/libldk_node.so ./
else
    echo "Invalid ARCH value"
    exit 1
fi

It appears that the repository "github.com/getAlby/ldk-node-go" is providing Go bindings for a Rust library called LDK (Lightning Development Kit).

Thus, albyhub/ldk-node-go/default.nix is used as a buildinput for albyhub/package.nix

@bleetube

This comment was marked as outdated.

@bleetube bleetube force-pushed the albyhub branch 2 times, most recently from 4793875 to f30b509 Compare December 28, 2024 23:02
@bleetube

This comment was marked as outdated.

@bleetube bleetube force-pushed the albyhub branch 5 times, most recently from 4936cdb to e55c6e2 Compare December 29, 2024 05:01
@bleetube

This comment was marked as resolved.

@bleetube bleetube force-pushed the albyhub branch 3 times, most recently from e3e4277 to 88d0fe1 Compare December 29, 2024 17:42
@bleetube bleetube marked this pull request as ready for review December 29, 2024 17:56
@ofborg ofborg bot added 8.has: package (new) This PR adds a new package 11.by: package-maintainer This PR was created by the maintainer of the package it changes 10.rebuild-darwin: 1 10.rebuild-linux: 1 labels Dec 30, 2024
@nixos-discourse
Copy link

This pull request has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/prs-ready-for-review/3032/5058

@bleetube

This comment was marked as outdated.

@bleetube bleetube marked this pull request as draft March 8, 2025 17:26
@bleetube bleetube force-pushed the albyhub branch 2 times, most recently from 0fe427c to e7b6a37 Compare March 11, 2025 02:56
@bleetube bleetube force-pushed the albyhub branch 2 times, most recently from 810b647 to a57e322 Compare March 11, 2025 06:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants