djanatyn / ssbm-nix

Nix expressions for Super Smash Bros. Melee players.
31 stars 17 forks source link

where .slippi-netplay-wrapped come from? #12

Closed ursi closed 3 years ago

ursi commented 3 years ago

Where does slippi-ishiiruka-2.2.6-netplay/bin/.slippi-netplay-wrapped come from? I've searched this repo and I just can't find what creates or anything fetching a derivation that creates it.

djanatyn commented 3 years ago

Where does slippi-ishiiruka-2.2.6-netplay/bin/.slippi-netplay-wrapped come from?

This is a consequence of using wrapProgram from nixpkgs.

You can use nix show-derivation to see what was used to build .slippi-netplay-wrapped:

❯ nix show-derivation "/nix/store/r756nqdhdjcvvbxkra9j6qw1nkgfng5g-slippi-ishiiruka-2.2.6-netplay/bin/.slippi-netplay-wrapped" | jq '.[] | .env.installPhase' -r
wrapProgram "$out/dolphin-emu" \
  --set "GDK_BACKEND" "x11" \
  --prefix GIO_EXTRA_MODULES : "/nix/store/zlqwp1ich34nr3q8ckyf7z5rfcc1nxav-glib-networking-2.66.0/lib/gio/modules" \
  --prefix LD_LIBRARY_PATH : "/nix/store/mi44faayr5padcm331wcc4rmqa3bj9pg-vulkan-loader-1.2.162.0/lib"
ln -s $out/dolphin-emu $out/bin/slippi-netplay
ln -s /nix/store/0aag5wc8011gfg5a1p1kgb4nk85cq1yk-Slippi-Online.desktop/share/applications $out/share

Notice the call to wrapProgram.

wrapProgram is defined in pkgs/build-support/setup-hooks/make-wrapper.sh:

# Syntax: wrapProgram <PROGRAM> <MAKE-WRAPPER FLAGS...>
wrapProgram() {
    local prog="$1"
    local hidden

    assertExecutable "$prog"

    hidden="$(dirname "$prog")/.$(basename "$prog")"-wrapped
    while [ -e "$hidden" ]; do
      hidden="${hidden}_"
    done
    mv "$prog" "$hidden"
    # Silence warning about unexpanded $0:
    # shellcheck disable=SC2016
    makeWrapper "$hidden" "$prog" --argv0 '$0' "${@:2}"
}

This is the line that's constructing the filename, .slippi-netplay-wrapped:

hidden="$(dirname "$prog")/.$(basename "$prog")"-wrapped

When we execute the build, we're executing this function (wrapProgram) during the installPhase. You can see references to these paths in the GitHub Actions log:


This is a common pattern in nixpkgs you'll find elsewhere, too:

# how many files mention `wrapProgram` in nixpkgs?
❯ rg -l 'wrapProgram' /var/lib/nixpkgs  | wc -l
1040

# what files look like `.*-wrapped` in the nix store?
❯ fd -H '\.*-wrapped' /nix/store | head
/nix/store/w5lrxryda9dg2kr2ay8ms3bv4zy1zyyy-surf-2.0/bin/.surf-wrapped
/nix/store/if42z8hrjk7hkyg7ywbr4l7l15567j88-python3.8-PyJWT-1.7.1/bin/.pyjwt-wrapped
/nix/store/d3ccxmlgsd0zm8a0yfpnfglsbaknwmpq-kotatogram-desktop-1.2/bin/.kotatogram-desktop-wrapped
/nix/store/nspnm7mn8pbh46qap9qs7hbsbkqa4kkg-python3.7-ansible-lint-4.2.0/bin/.ansible-lint-wrapped
/nix/store/047vk65wdfaj2lj23d1cakla361kg8zs-tmuxp-1.7.2/bin/.tmuxp-wrapped
/nix/store/dyknvwk5wzf9qcwsv3dx8wzzbr5gyjlr-python3.8-black-20.8b1/bin/.blackd-wrapped
/nix/store/dyknvwk5wzf9qcwsv3dx8wzzbr5gyjlr-python3.8-black-20.8b1/bin/.black-primer-wrapped
/nix/store/dyknvwk5wzf9qcwsv3dx8wzzbr5gyjlr-python3.8-black-20.8b1/bin/.black-wrapped
/nix/store/gapj1i7n0v2zggfpnzw2mq3lz85c4vn7-smpeg2-svn412/bin/.smpeg2-config-wrapped
/nix/store/28qdfjjpjkz8qbwk4wd88mk0lwancxqf-pavucontrol-4.0/bin/.pavucontrol-wrapped
djanatyn commented 3 years ago

Closing because I think this answers the question in scope. Feel free to open issues (or reach out directly?) with more questions!