dream2nix
dream2nix copied to clipboard
sveltekit fails to build
rt repo: https://github.com/suyashtnt/personal-website
/home/tntman/projects/personal-website〉direnv reload 01/21/2023 05:05:34
direnv: loading ~/projects/personal-website/.envrc
direnv: using flake
warning: Git tree '/home/tntman/projects/personal-website' is dirty
[0/1 built, 0.0 MiB DL] querying nix-shell-env on https://nixpkgs-wayland.cachix.orgdirenv: ([direnv export json]) is taking a while to execute. Use CTRL-C to give up.
error: builder for '/nix/store/84gd04gqna6ys5yciw4vf8xr9ybcy3c8-__at__sveltejs__slash__kit-1.2.2.drv' failed with exit code 1;
last 10 log lines:
> code: 'ERR_MODULE_NOT_FOUND'
> }
> npm ERR! code ELIFECYCLE
> npm ERR! errno 1
> npm ERR! @sveltejs/[email protected] postinstall: `node postinstall.js`
> npm ERR! Exit status 1
> npm ERR!
> npm ERR! Failed at the @sveltejs/[email protected] postinstall script.
> npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
>
For full logs, run 'nix log /nix/store/84gd04gqna6ys5yciw4vf8xr9ybcy3c8-__at__sveltejs__slash__kit-1.2.2.drv'.
error: 1 dependencies of derivation '/nix/store/3qgl8ccq67zvjv6xdv5izw503jwx38x0-node-modules.drv' failed to build
error: 1 dependencies of derivation '/nix/store/0gndl28c5py74bmn1brd1i5av0cgqwcb-nix-shell-env.drv' failed to build
warning: Git tree '/home/tntman/projects/personal-website' is dirty
direnv: nix-direnv: renewed cache
direnv: export ~XDG_DATA_DIRS

@DavHau this is an illustrative example, why we need build flags for "pre-post-/install scripts" The build fails because "@sveltejs/[email protected]" requires things such as
if (!fs.existsSync('package.json')) continue;
if (!fs.existsSync('svelte.config.js')) continue;
-> https://unpkg.com/@sveltejs/[email protected]/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
'';
};
};