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.html
That 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
|
let target_parent = target |
to have it work something like this:
$ pwd
~/my/project
trunk build /nix/store/9naz5isizpi8xyj55ba328pk3nxrfiaz-index.html --pre_target $PWD
It could also be in the TOML file and as an env variable, of course.
Here's the file structure of a project:
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:When I try to build the project I get this error:
When digging a bit in the code it confirms that relative paths are relative to the location of the
index.htmlfile provided for the build.My build fails because my
index.cssfile 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:That 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_targetintrunk/src/config/rt/build.rs
Line 145 in cbaadce
It could also be in the TOML file and as an env variable, of course.