Storing command output in a variable?

Hi, I am trying to wrap an AppImage, without success. The bambu.nix file I have now is:

{ pkgs, lib, fetchurl, appimageTools, runCommandWith ? import <nixpkgs> {} }:
let
  pname = "bambu";
  version = "2.09.01.70";
  fullname = lib.readFile "${runCommandWith { name="flnm"; derivationArgs.nativebuildInputs = [ pkgs.curl pkgs.gnugrep ]; } "${pkgs.curl}/bin/curl -Ls https://github.com/bambulab/BambuStudio/releases/expanded_assets/v${version} | ${pkgs.gnugrep}/bin/grep -Eom1 'v${version}-[0-9]+' > $out"}";
  src = fetchurl {
    url = "https://github.com/bambulab/BambuStudio/releases/download/v${version}/BambuStudio_ubu24-${fullname}.AppImage";
    sha256 = "";
  };
in
appimageTools.wrapType2 rec {
  inherit pname version src;
  extraPkgs = pkgs: [ pkgs.webkitgtk_4_1 ];
}

and I call bambu in configuration.nix with (callPackage ./bambu.nix {}).

I suspect the main problem is storing the output of the command in fullname to be used in src, since nixos-rebuild does not show the file being downloaded at all (it must have failed before that). I have also had a whole host of problems relating to readFile and runCommand and runCommandWith. The command in fullname was modified from How to create a timestamp in a Nix expression? - #2 by AtnNn .

The current error is:

$ sudo nixos-rebuild switch                                        
building the system configuration...
building '/nix/store/a3b1h3daf94rrw8qgv70hglsy638h74f-flnm.drv'...
error:
       … while calling the 'derivationStrict' builtin
         at «nix-internal»/derivation-internal.nix:37:12:
           36|
           37|   strict = derivationStrict drvAttrs;
             |            ^
           38|

       … while evaluating derivation 'nixos-system-pyramid-26.11pre1105037.1c89083e451e'
         whose name attribute is located at /nix/store/rk6gj8gw2ibi5by79wlciv0wklkkfw5n-nixos/nixos/pkgs/stdenv/generic/make-derivation.nix:651:11

       … while evaluating attribute 'buildCommand' of derivation 'nixos-system-pyramid-26.11pre1105037.1c89083e451e'
         at /nix/store/rk6gj8gw2ibi5by79wlciv0wklkkfw5n-nixos/nixos/nixos/modules/system/activation/top-level.nix:63:7:
           62|       allowSubstitutes = false;
           63|       buildCommand = systemBuilder;
             |       ^
           64|

       (stack trace truncated; use '--show-trace' to show the full, detailed trace)

       error: Cannot build '/nix/store/a3b1h3daf94rrw8qgv70hglsy638h74f-flnm.drv'.
       Reason: builder failed with exit code 1.
       Output paths:
         /nix/store/pzsq8rhkcfg4wd275dlrk4qdsl5mvx22-flnm
Command 'nix-build '<nixpkgs/nixos>' --attr config.system.build.toplevel --no-out-link' returned non-zero exit status 100.

I have no idea what to do from here, since nix-store -l /nix/store/a3b1h3daf94rrw8qgv70hglsy638h74f-flnm.drv does not output anything at all, while ls -la /nix/store/pzsq8rhkcfg4wd275dlrk4qdsl5mvx22-flnm outputs -rw-r--r-- 1 nixbld1 nixbld 0 Nov 5 03:14 /nix/store/pzsq8rhkcfg4wd275dlrk4qdsl5mvx22-flnm - an empty folder.