Skip to content

Commit cf0b33d

Browse files
committed
Merge branches 'gcurtis/packagefs' and 'gcurtis/patchpkg-lookpath' into gcurtis/go-patchelf
2 parents 21b9ab5 + 81a59d5 commit cf0b33d

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

internal/patchpkg/builder.go

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,7 @@ func (d *DerivationBuilder) build(ctx context.Context, pkg, out *packageFS) erro
7878
}
7979
}
8080

81-
bash := filepath.Join(os.Getenv("bash"), "bin/bash")
82-
cmd := exec.CommandContext(ctx, bash, "-s")
81+
cmd := exec.CommandContext(ctx, lookPath("bash"), "-s")
8382
cmd.Stdin = bytes.NewReader(glibcPatchScript)
8483
cmd.Stdout = os.Stdout
8584
cmd.Stderr = os.Stderr
@@ -192,5 +191,24 @@ func allFiles(fsys fs.FS, root string) iter.Seq2[string, fs.DirEntry] {
192191
}
193192
}
194193

194+
// lookPath is like [exec.lookPath], but first checks if there's an environment
195+
// variable with the name prog. If there is, it returns $prog/bin/prog instead
196+
// of consulting PATH.
197+
//
198+
// For example, lookPath would be able to find bash and patchelf in the
199+
// following derivation:
200+
//
201+
// derivation {
202+
// inherit (nixpkgs.legacyPackages.x86_64-linux) bash patchelf;
203+
// builder = devbox;
204+
// }
205+
func lookPath(prog string) string {
206+
pkgPath := os.Getenv(prog)
207+
if pkgPath == "" {
208+
return prog
209+
}
210+
return filepath.Join(pkgPath, "bin", prog)
211+
}
212+
195213
func isExecutable(mode fs.FileMode) bool { return mode&0o111 != 0 }
196214
func isSymlink(mode fs.FileMode) bool { return mode&fs.ModeSymlink != 0 }

0 commit comments

Comments
 (0)