NixOS / nixpkgs

Nix Packages collection & NixOS
MIT License
17.33k stars 13.57k forks source link

soft-serve is embedding nix paths that don't get upgraded #272128

Closed dcarosone closed 1 month ago

dcarosone commented 9 months ago

Describe the bug

soft-serve sets up a bunch of git hooks, presumably on repo creation. These embed the current nix store path to soft-serve, and don't get updated for new builds

Steps To Reproduce

Steps to reproduce the behavior:

  1. Install soft-serve, set up some repositories
  2. Wait some time, upgrade some versions
  3. Wait some more time, garbage-collect some old versions
  4. Get git hook errors on (for example) git push failing to find old store paths

Expected behavior

git push to work as normal

Screenshots

❯ git push
Enumerating objects: 5, done.
Counting objects: 100% (5/5), done.
Delta compression using up to 4 threads
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 910 bytes | 455.00 KiB/s, done.
Total 3 (delta 2), reused 0 (delta 0), pack-reused 0
remote: ./hooks/pre-receive.d/soft-serve: line 7: /nix/store/p14yny0kx19njhlz6j1lrwk438gbd2na-soft-serve-0.6.2/bin/.soft-wrapped: No such file or directory
To ssh://soft-serve:23231/geek/nixos
 ! [remote rejected] flake -> flake (pre-receive hook declined)
error: failed to push some refs to 'ssh://soft-serve:23231/geek/nixos'

Additional context

the contents of the hook script failing above:

#!/usr/bin/env bash
# AUTO GENERATED BY SOFT SERVE, DO NOT MODIFY
if [ -z "$SOFT_SERVE_REPO_NAME" ]; then
        echo "Warning: SOFT_SERVE_REPO_NAME not defined. Skipping hooks."
        exit 0
fi
/nix/store/p14yny0kx19njhlz6j1lrwk438gbd2na-soft-serve-0.6.2/bin/.soft-wrapped hook pre-receive

That store path is old and now gone, soft-serve appears to be up to 0.7.3, and have had intermediate upgrades for 0.7.1 and 0.7.2 which still exist as store paths, not yet gc'd.

In addition to failing now, it has presumably been using the wrong, old version for the intermediate time, which expains why it wasn't noticed sooner.

To fix this probably requires some internal changes to the soft-serve code to pick the right paths when generating the hooks, but also some method to remediate existing hooks on-disk.

Notify maintainers

@penguwin

Metadata

Please run nix-shell -p nix-info --run "nix-info -m" and paste the result.


Add a :+1: reaction to issues you find important.

dcarosone commented 9 months ago

The wrapper is created in the package

  postInstall = ''
    # Soft-serve generates git-hooks at run-time.
    # The scripts require git and bash inside the path.
    wrapProgram $out/bin/soft \
      --prefix PATH : "${lib.makeBinPath [ git bash ]}"
  '';

but unfortunately the versioned wrapper expires, even if it's very simple and probably hasn't changed between versions (edit: I misread, it's not a shell wrapper, it's an updated binary, so versions will matter)

blurgyy commented 9 months ago

Sharing my solution here, I had to patch the source to make it relative so that soft-serve creates new hooks using the soft binary:

https://github.com/blurgyy/flames/blob/main/packages/soft-serve-relative-binary-path-in-hooks/executable-name.patch

To make it work at runtime, soft-serve's runtime environment has to contain soft in its PATH.

The path in already created hooks have to be updated manually.

dcarosone commented 7 months ago

Looking forward to the upstream fix landing, that looks much better

philipwilk commented 1 month ago

Its been over 6mo I think it's sensible to find working commit and just do a dated release on unstable