Open Suyashtnt opened 1 year ago
@DavHau this is an illustrative example, why we need build flags for "pre-post-/install scripts" The build fails because "@sveltejs/kit@1.2.2" requires things such as
if (!fs.existsSync('package.json')) continue;
if (!fs.existsSync('svelte.config.js')) continue;
-> https://unpkg.com/@sveltejs/kit@1.2.2/postinstall.js
But package.json
as well as svelte.config.js
do/would only exist in the main derivation. Not inside the dependency itself.
Fix: I must implement methods that allow granular overrides for such special cases.
@hsjobeki is there any temporary workaround for this? I need to build a Svelte app with nix
I‘ll have a look at it.
@cor this is my flake to build a svelte app.
This is a little hacky but should get the job done. Until i find time to fix the linked issue.
{
inputs.dream2nix.url = "github:nix-community/dream2nix";
outputs = inp:
inp.dream2nix.lib.makeFlakeOutputs {
systems = ["x86_64-linux"];
config.projectRoot = ./.;
source = ./.;
projects = ./projects.toml;
packageOverrides = {
"myapp" = {
# run the postinstall script manually
"runSvelteKitInstall" = {
preInstall = ''
node ./node_modules/@sveltejs/kit/postinstall.js
'';
};
};
# -> Disable the postinstall script
#
# we'll run this manually in the root project.
# Currently install-scripts cannot access package.json
# from your project. This is a known issue in dream2nix
"@sveltejs/kit" = {
"disableScripts" = {
# this should be preInstall but somehow didnt work.
# This is fine because sveltekit has no build script
# export isMain=true is currently a hack to disable the install scripts of a package
buildPhase = ''
export isMain=true
'';
postInstall = ''
export isMain=
'';
};
};
};
};
}
EDIT: Just saw that sveltekit needs the .svelte-kit folder. In particular it warns that tsconfig.ts is not found but still builds fine.
You'd want to include a script that generates the .svelte-kit
folder in the preBuild
phase of myapp
->
"myapp" = {
# generate the .svelte-kit folder
# I am not sure about the command.
"prepare-svelte" = {
preBuild = ''
npx svelte-kit sync
'';
};
};
rt repo: https://github.com/suyashtnt/personal-website