diff --git a/default.nix b/default.nix index f3b4ed0..83fc4ba 100644 --- a/default.nix +++ b/default.nix @@ -19,57 +19,39 @@ pkgs.stdenv.mkDerivation { src; nativeBuildInputs = with pkgs; [ - sass - lightningcss - nodejs_22 - yarn cacert - curl - glib html-minifier + lightningcss + sass + yarn ]; - SSL_CERT_FILE = "${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt"; - NIX_SSL_CERT_FILE = "${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt"; - GIT_SSL_CAINFO = "${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt"; - configurePhase = '' export HOME=$TMPDIR 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 - # Minify CSS echo 'Minifying CSS' lightningcss --minify --targets '> 0.25%, not IE 11' _site/style/*.css -o _site/style/*.css - # Build site with 11ty echo 'Building site' - yarn eleventy + yarn --offline eleventy - # Minify HTML echo 'Minifying HTML' html-minifier --input-dir _site --output-dir _site --collapse-whitespace --file-ext html ''; installPhase = '' - # Create output directory and copy files mkdir -p $out cp -r _site/* $out/ - - # Clean up rm -rf node_modules _site package.json ''; - - dontFixup = true; - dontPatch = true; } diff --git a/shell.nix b/shell.nix index 4634f1c..3230160 100644 --- a/shell.nix +++ b/shell.nix @@ -7,19 +7,45 @@ in pkgs.mkShell { buildInputs = with pkgs; [ yarn - nodejs_22 + sass + lightningcss ]; 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 . + serve() { + mkdir -p _site/style + + sass --watch style/style.scss:_site/style/style.css & + SASS_PID=$! + + yarn eleventy --serve & + ELEVENTY_PID=$! + + cleanup_serve() { + echo "Cleaning up serve processes..." + kill $SASS_PID 2>/dev/null + kill $ELEVENTY_PID 2>/dev/null + wait $SASS_PID 2>/dev/null + wait $ELEVENTY_PID 2>/dev/null + } + + trap cleanup_serve EXIT INT TERM + + wait -n + + cleanup_serve + + trap - EXIT INT TERM + } + upgrade_deps() { - local mode=''${1:-"minor"} # default to minor updates + local mode=''${1:-"minor"} case $mode in "major") @@ -48,17 +74,17 @@ pkgs.mkShell { } export -f upgrade_deps + export -f serve - # Cleanup function cleanup() { echo "Cleaning up..." - rm -rf node_modules package.json + rm -rf node_modules _site package.json } - # Register the cleanup function to run when the shell exits trap cleanup EXIT echo "Development environment ready!" + echo "Run 'serve' to start development server" echo "Run 'upgrade_deps [major|minor|patch]' to upgrade your dependencies" ''; }