Switch to Nix builds

This commit is contained in:
Stefan 2024-11-26 16:53:29 +00:00
parent b988568a9e
commit 69fce990f8
11 changed files with 1878 additions and 2106 deletions

1
.gitignore vendored
View file

@ -3,3 +3,4 @@
.sass-cache .sass-cache
_site _site
node_modules node_modules
result

View file

@ -1,28 +0,0 @@
#!/usr/bin/env bash
rm -rf _site
mkdir -p _site/style
nix-shell -p sass --pure --command "
echo 'Compiling SCSS'
sass style/style.scss _site/style/style.css
"
nix-shell -p lightningcss --pure --command "
echo 'Minifying CSS'
lightningcss --minify --targets '> 0.25%, not IE 11' _site/style/*.css -o _site/style/*.css
"
nix-shell -p nodePackages.pnpm nodejs_22 cacert curl glib --pure --command "
echo 'Testing npm registry'
curl -v https://registry.npmjs.org/
echo 'Building site'
pnpm add fast-glob @11ty/eleventy @11ty/eleventy-img
pnpm eleventy
"
nix-shell -p html-minifier --pure --command "
echo 'Minifying HTML'
html-minifier --input-dir _site --output-dir _site --collapse-whitespace --file-ext html
"

View file

@ -1,10 +0,0 @@
#!/usr/bin/env bash
nix-shell -p neocities-cli --command "
echo 'Pushing to Neocities'
set +x
export NEOCITIES_API_KEY=$(cat ~/.neocities/vegan-prestwich)
set -x
neocities push --prune _site
"

View file

@ -1,15 +0,0 @@
#!/usr/bin/env bash
rm -rf _site
mkdir -p _site/style
nix-shell -p sass --pure --command "
echo 'Compiling SCSS'
sass style/style.scss _site/style/style.css
"
nix-shell -p nodePackages.pnpm --command "
echo 'Serving site'
pnpm add fast-glob @11ty/eleventy @11ty/eleventy-img
pnpm eleventy --serve
"

View file

@ -1,7 +0,0 @@
#!/usr/bin/env bash
nix-shell -p nodePackages.pnpm --command "
echo 'Upgrading packages'
pnpm add -g pnpm
pnpm upgrade
"

View file

@ -1,36 +1,75 @@
{ pkgs ? import <nixpkgs> {} }: { pkgs ? import <nixpkgs> {} }:
pkgs.stdenv.mkDerivation { let
name = "your-website"; # Input source files
src = ./.; src = ./.;
nodeDeps = import ./node-deps.nix { inherit pkgs; };
inherit (nodeDeps) packageJSON nodeModules;
buildInputs = with pkgs; [ in
pkgs.stdenv.mkDerivation {
name = "veganprestwich-co-uk";
src = builtins.filterSource
(path: type: !(builtins.elem (baseNameOf path) [
"_site"
"node_modules"
".git"
]))
src;
nativeBuildInputs = with pkgs; [
sass sass
lightningcss lightningcss
nodejs nodejs_22
nodePackages.pnpm yarn
cacert
curl
glib
html-minifier html-minifier
]; ];
# Allow network access during build SSL_CERT_FILE = "${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt";
__noChroot = true; NIX_SSL_CERT_FILE = "${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt";
GIT_SSL_CAINFO = "${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt";
buildPhase = '' configurePhase = ''
export HOME=$TMPDIR
mkdir -p _site/style mkdir -p _site/style
# Copy node_modules instead of linking
cp -r ${nodeModules}/node_modules .
chmod -R +w node_modules
cp ${packageJSON} package.json
'';
buildPhase = ''
# Compile SCSS
echo 'Compiling SCSS'
sass style/style.scss _site/style/style.css sass style/style.scss _site/style/style.css
# Minify CSS
echo 'Minifying CSS'
lightningcss --minify --targets '> 0.25%, not IE 11' _site/style/*.css -o _site/style/*.css lightningcss --minify --targets '> 0.25%, not IE 11' _site/style/*.css -o _site/style/*.css
# Install dependencies # Build site with 11ty
pnpm install --offline echo 'Building site'
pnpm eleventy yarn eleventy
# Minify HTML
echo 'Minifying HTML'
html-minifier --input-dir _site --output-dir _site --collapse-whitespace --file-ext html html-minifier --input-dir _site --output-dir _site --collapse-whitespace --file-ext html
''; '';
installPhase = '' installPhase = ''
# Create output directory and copy files
mkdir -p $out mkdir -p $out
cp -r _site/* $out/ cp -r _site/* $out/
# Clean up
rm -rf node_modules _site package.json
''; '';
dontFixup = true;
dontPatch = true;
} }

28
node-deps.nix Normal file
View file

@ -0,0 +1,28 @@
# node-deps.nix
{ pkgs ? import <nixpkgs> {} }:
let
packageJSON = pkgs.writeTextFile {
name = "package.json";
text = builtins.toJSON {
name = "veganprestwich-co-uk";
version = "1.0.0";
dependencies = {
"fast-glob" = "^3.3.2";
"@11ty/eleventy" = "^3.0.0";
"@11ty/eleventy-img" = "^5.0.0";
};
};
};
nodeModules = pkgs.mkYarnModules {
pname = "veganprestwich-co-uk-deps";
version = "1.0.0";
packageJSON = packageJSON;
yarnLock = ./yarn.lock;
yarnFlags = ["--frozen-lockfile"];
};
in
{
inherit packageJSON nodeModules;
}

View file

@ -1,7 +0,0 @@
{
"dependencies": {
"@11ty/eleventy": "^3.0.0",
"@11ty/eleventy-img": "^5.0.0",
"fast-glob": "^3.3.2"
}
}

File diff suppressed because it is too large Load diff

67
shell.nix Normal file
View file

@ -0,0 +1,67 @@
{ pkgs ? import <nixpkgs> {} }:
let
nodeDeps = import ./node-deps.nix { inherit pkgs; };
inherit (nodeDeps) packageJSON nodeModules;
in
pkgs.mkShell {
buildInputs = with pkgs; [
yarn
nodejs_22
];
shellHook = ''
# Use the same package.json and node_modules as the build
rm -rf node_modules
rm -rf package.json
ln -sf ${packageJSON} package.json
ln -sf ${nodeModules}/node_modules .
upgrade_deps() {
local mode=''${1:-"minor"} # default to minor updates
case $mode in
"major")
echo "Upgrading to latest major versions..."
yarn upgrade --latest 2>/dev/null
;;
"minor")
echo "Upgrading to latest minor versions..."
yarn upgrade 2>/dev/null
;;
"patch")
echo "Upgrading patch versions only..."
yarn upgrade --pattern "*" --target patch 2>/dev/null
;;
*)
echo "Unknown mode: $mode"
echo "Usage: upgrade_deps [major|minor|patch]"
return 1
;;
esac
yarn install 2>/dev/null
echo "Done! Don't forget to commit the updated yarn.lock file."
exit 0
}
export -f upgrade_deps
# Cleanup function
cleanup() {
echo "Cleaning up..."
rm -rf node_modules package.json
}
# Register the cleanup function to run when the shell exits
trap cleanup EXIT
# If no arguments were passed, show the help message
if [ $# -eq 0 ]; then
echo "Development environment ready!"
echo "Run 'upgrade_deps [major|minor|patch]' to upgrade your dependencies"
fi
'';
}

1732
yarn.lock Normal file

File diff suppressed because it is too large Load diff