Skip to content

[Feature]: Alter dynamic linking to be more portable #584

@rob-mur

Description

@rob-mur

Is your feature request related to a problem? Please describe.
Currently on nixos backlog.md doesn't work without writing a derivation to wrap it due to hardcoded dynamic library paths in the bundled executable (such as libc).

I would prefer to be able to just install via npm and have the library work without this derivation (whilst I can package it to nixpkgs it makes versioning harder).

Describe the solution you'd like
Some ideas as it looks like you aren't the one hardcoding the paths but bun is when you do bun --compile:

  • in cli.js, if the spawn fails due to missing interpreter, fallback to the users bun or node installation
  • don't compile at all if not necessary? I'm unsure what the performance constraints are so may not be possible
  • use musl/statically linked compilation

Additional context
Here for reference is a nix derivation that seems to work at least for me

# Derivation for backlog.md CLI (https://github.com/MrLesk/backlog.md)
#
# backlog.md ships a pre-built native binary per platform via npm optional
# dependencies. This derivation fetches the linux-x64 binary tarball directly
# from the npm registry and patches it with autoPatchelfHook so it works on
# NixOS.
{ pkgs ? import <nixpkgs> {} }:

pkgs.stdenv.mkDerivation rec {
  pname = "backlog-md";
  version = "1.44.0";

  src = pkgs.fetchurl {
    url = "https://registry.npmjs.org/backlog.md-linux-x64/-/backlog.md-linux-x64-${version}.tgz";
    sha256 = "1zc2kfzpw5m80gjnjnp8x9hpqxrldghls1p8a64hiana9j7b45zy";
  };

  nativeBuildInputs = [ pkgs.autoPatchelfHook ];
  buildInputs = [ pkgs.glibc pkgs.gcc-unwrapped.lib pkgs.zlib ];

  # The tarball unpacks to ./package/
  sourceRoot = "package";

  dontBuild = true;
  dontConfigure = true;

  # CRITICAL: Bun-compiled binaries append a zip payload containing the application code 
  # to the end of the executable. The default Nix `strip` phase will remove this payload, 
  # breaking the application and causing it to fall back to the default Bun REPL.
  dontStrip = true;

  installPhase = ''
    mkdir -p $out/bin
    install -Dm755 backlog $out/bin/backlog
  '';

  meta = with pkgs.lib; {
    description = "Backlog.md — git-native AI-friendly task management CLI";
    homepage = "https://github.com/MrLesk/backlog.md";
    license = licenses.mit;
    platforms = [ "x86_64-linux" ];
    mainProgram = "backlog";
  };
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions