I made an Eleventy & Nix static site template
I've had to create a new Eleventy site on NixOS a bunch of times lately, so I figured I make a template to save myself repeating the same steps over and over.
Hopefully this will come in helpful for anyone else who's attempting to build Eleventy (or any other npm-based site generator) on NixOS.
The source code for the template I made is here: git.chobble.com/chobble/empty-eleventy-nix-site
To get started just run git clone https://git.chobble.com/chobble/empty-eleventy-nix-site, then cd to the directory, run direnv allow or nix develop, and then serve to get a server running locally.
You can also run nix-build to reproducibly build the site using Nix - I call this from my NixOS site builder which powers the Chobble server.
To quote its README.md:
This template should let you get started with the Eleventy static site builder on NixOS / Nix, really easily.
Featuring Nix'y features like:
- direnv support via
flake.nix- rundirenv allow - or run
nix developif you don't have direnv nix-buildsupport usingflake-compatserveshell script to run Eleventy and SASS locallybuildshell script to build the site into_site
And Eleventy features like:
- Canonical URLs
- A directory to store favicon cruft
- A
_data/site.jsonmetadata store - An
collection.imagescollection of the files insrc/images
Changing Packages
If you want to change the packages in packages.json, here's the steps:
- Remove all
nodeModuleslines fromnode-deps.nixandflake.nix - Use
direnv reloadornix developto get a dev shell - Add the new packages to
node-deps.nixand rundirenv reloadto re-buildpackages.json - Run
yarn -lto create a newyard.lock - Re-add the
nodeModulelines tonode-deps.nixandflake.nix
Upgrading Packages
This is a little fiddlier:
- Remove all
nodeModuleslines fromnode-deps.nixandflake.nix - Copy the generated
package.jsonto your clipboard - Delete
package.jsonto remove the symbolic link - Paste your clipbard back into a new
package.json - Run
yarn upgradeto create a newyarn.lockand updatepackage.json - Copy those new version numbers from
package.jsontonode-deps.nix - Re-add the
nodeModulelines tonode-deps.nixandflake.nix
..I do intend to make those steps simpler some day. If you've got ideas of how I could, please contact me!
- ← Previous
Adding social preview images to my Eleventy blog - Next →
Spamming Works!*