Repository navigation
Allow custom base path for asset resolution #1049
Description
Here's the file structure of a project:
$ pwd
~/my/project
$ ls
src/ Cargo.toml style.css default.nix
$ cat style.css
@import "tailwindcss";The index.html file is generated with nix, and is located outside the project at /nix/store/9naz5isizpi8xyj55ba328pk3nxrfiaz-index.html. Currently it looks like this:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- Tailwind CSS -->
<link data-trunk data-integrity="sha512" rel="tailwind-css" href="style.css">
<!-- Leaflet -->
<link data-trunk data-integrity="sha512" data-no-minify data-target-path="leaflet" rel="css" href="/nix/store/sbal4dnkz83iqaqb31iwifvjk7yq29bv-leaflet-1.9.4/lib/node_modules/leaflet/dist/leaflet.css" />
<link data-trunk data-target-path="leaflet/images" rel="copy-dir" href="/nix/store/sbal4dnkz83iqaqb31iwifvjk7yq29bv-leaflet-1.9.4/lib/node_modules/leaflet/dist/images/" />
<script data-trunk data-integrity="sha512" data-no-minify data-target-path="leaflet" src="/nix/store/sbal4dnkz83iqaqb31iwifvjk7yq29bv-leaflet-1.9.4/lib/node_modules/leaflet/dist/leaflet.js"></script>
</head>
<body>
</body>
</html>When I try to build the project I get this error:
$ pwd
~/my/project
$ trunk build /nix/store/9naz5isizpi8xyj55ba328pk3nxrfiaz-index.html
2026-02-24T22:52:28.983576Z INFO 🚀 Starting trunk 0.21.14
2026-02-24T22:52:29.225321Z DEBUG spawning asset pipelines
2026-02-24T22:52:29.228025Z ERROR ❌ error
error from build pipeline
Caused by:
0: error getting canonical path for "/nix/store/style.css"
1: No such file or directory (os error 2)
2026-02-24T22:52:29.228089Z ERROR error from build pipeline
2026-02-24T22:52:29.228095Z INFO 1: error getting canonical path for "/nix/store/style.css"
2026-02-24T22:52:29.228100Z INFO 2: No such file or directory (os error 2)When digging a bit in the code it confirms that relative paths are relative to the location of the index.html file provided for the build.
My build fails because my index.css file is in another folder. A workaround is to wrap the build in a script to copy the html file prior to the build, and gitignore it:
cp /nix/store/9naz5isizpi8xyj55ba328pk3nxrfiaz-index.html index.html
trunk build index.htmlThat works, but it pollutes the directory in my opinion, I would like the project directory to only contain source files.
I was thinking of introducing a configuration flag to override the pre_target in
Line 145 in cbaadce
| let target_parent = target |
$ pwd
~/my/project
trunk build /nix/store/9naz5isizpi8xyj55ba328pk3nxrfiaz-index.html --pre_target $PWDIt could also be in the TOML file and as an env variable, of course.
Activity
ctron commentedon Feb 25, 2026
Yea, that is the current behavior. I guess it would be hard to change this. At least without breaking a lot.
Just looking at the code: you can provide
build.target, wouldn't that be close? If you provide a directory? Then maybe adding a--index <your-index.html>which would deviate from<build.target>/index.html?deadbaed commentedon Feb 27, 2026
I have a working patch which adds a new flag to use the working directory for assets resolution. It turns out the patch was not that hard, because the working directory is already known and is available to be used.
I'll make a PR to get the discussion going.
I have not thought of that, thank you for the suggestion! I'll experiment .