Skip to content

Instantly share code, notes, and snippets.

@aabccd021
Created October 27, 2024 06:02
Show Gist options
  • Save aabccd021/abd68502e6b1e56d5a2c7076c2cdad9b to your computer and use it in GitHub Desktop.
Save aabccd021/abd68502e6b1e56d5a2c7076c2cdad9b to your computer and use it in GitHub Desktop.
Nix + bun install
{
packageLock = builtins.fromJSON (builtins.readFile ./package-lock.json);
cleanPackages = builtins.attrValues (builtins.removeAttrs packageLock.packages [ "" ]);
fetchedPackages = builtins.map
(package:
let
basename = builtins.baseNameOf package.resolved;
downloaded = pkgs.fetchurl {
url = package.resolved;
sha512 = package.integrity;
# downloadToTemp = true;
# postFetch = ''
# ls -la
# resolved=$(echo ${package.resolved} | sed 's|https://||')
# resolved_dir=$(dirname $resolved)
# mkdir -p $out/$resolved_dir
# cp $downloadedFile $out/$resolved
# '';
};
in
pkgs.runCommandNoCC "fetchedPackages-${basename}" { } ''
resolved=$(echo ${package.resolved} | sed 's|https://||')
resolved_dir=$(dirname $resolved)
mkdir -p $out/$resolved_dir
ln -s ${downloaded} $out/$resolved_dir/${basename}
''
)
cleanPackages;
joinedPackages = pkgs.symlinkJoin {
name = "joinedPackages";
paths = fetchedPackages;
};
nodeModules = pkgs.runCommandNoCC "bunNodeModules" { } ''
ln -s ${joinedPackages}/* .
cp ${./package-lock.json} ./package-lock.json
sed -i "s|https://registry.npmjs.org|http://localhost:8080|g" package-lock.json
cp ${./package.json} ./package.json
ls ./registry.npmjs.org/@aws-crypto/crc32/-/crc32-5.2.0.tgz
timeout 10 ${pkgs.static-server}/bin/static-server ./registry.npmjs.org &
chmod -R 777 .
${bun}/bin/bun install --backend copyfile
ls
mkdir -p $out
mv node_modules/* $out
chmod -R 777 $out/*
'';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment