Switch to Flake builds

This commit is contained in:
stefan burke 2025-01-08 22:34:47 +00:00
parent 26fc0424d3
commit 0570e86605
9 changed files with 176 additions and 22 deletions

2
.envrc
View file

@ -1 +1 @@
use nix use flake

1
.gitignore vendored
View file

@ -1,5 +1,6 @@
.DS_Store .DS_Store
.aider* .aider*
.direnv
.env .env
.eleventy.js.swp .eleventy.js.swp
.sass-cache .sass-cache

View file

@ -4,10 +4,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1" /> <meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="robots" content="max-image-preview:large" /> <meta name="robots" content="max-image-preview:large" />
<meta name="generator" content="Eleventy" /> <meta name="generator" content="Eleventy" />
{% capture styles %} {% include "../_site/style/style.css" %} {% endcapture %} <link rel="stylesheet" href="/style/style.css">
<style>
{{ styles }}
</style>
<title> <title>
{%- if metaTitle %} {{ metaTitle | escape }} {%- elsif name %} {{ name | {%- if metaTitle %} {{ metaTitle | escape }} {%- elsif name %} {{ name |
escape }}, Prestwich {%- elsif title %} {{ title | escape }}, Prestwich {%- escape }}, Prestwich {%- elsif title %} {{ title | escape }}, Prestwich {%-

View file

@ -1,7 +1,6 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="{{ page.lang | default: site.lang | default: "en" }}"> <html lang="{{ page.lang | default: site.lang | default: "en" }}">
{% include "head.html" %}
{% include "head.html" %}
<body> <body>

4
bin/build Normal file
View file

@ -0,0 +1,4 @@
#!/usr/bin/env bash
sass --update style:_site/style --style compressed
yarn eleventy

17
bin/serve Normal file
View file

@ -0,0 +1,17 @@
#!/usr/bin/env bash
yarn eleventy --serve &
ELEVENTY_PID=$!
sass --watch style:_site/style --style compressed &
SASS_PID=$!
cleanup_serve() {
echo "Cleaning up serve processes..."
kill $ELEVENTY_PID 2>/dev/null
wait $ELEVENTY_PID 2>/dev/null
kill $SASS_PID 2>/dev/null
wait $SASS_PID 2>/dev/null
}
trap cleanup_serve EXIT INT TERM
wait -n
cleanup_serve
trap - EXIT INT TERM

View file

@ -1,26 +1,27 @@
{ pkgs ? import <nixpkgs> {} }: {
pkgs ? import <nixpkgs> { },
}:
let let
# Input source files # Input source files
src = ./.; src = ./.;
nodeDeps = import ./node-deps.nix { inherit pkgs; }; nodeDeps = import ./node-deps.nix { inherit pkgs; };
inherit (nodeDeps) packageJSON nodeModules; inherit (nodeDeps) packageJSON nodeModules;
in in
pkgs.stdenv.mkDerivation { pkgs.stdenv.mkDerivation {
name = "veganprestwich-co-uk"; name = "veganprestwich-co-uk";
src = builtins.filterSource src = builtins.filterSource (
(path: type: !(builtins.elem (baseNameOf path) [ path: type:
!(builtins.elem (baseNameOf path) [
"_site" "_site"
"node_modules" "node_modules"
".git" ".git"
])) ])
src; ) src;
nativeBuildInputs = with pkgs; [ nativeBuildInputs = with pkgs; [
cacert cacert
minify
lightningcss lightningcss
sass sass
yarn yarn
@ -36,17 +37,11 @@ pkgs.stdenv.mkDerivation {
''; '';
buildPhase = '' buildPhase = ''
echo 'Compiling SCSS' echo 'Building CSS'
sass style/style.scss _site/style/style.css sass --update style:_site/css --style compressed
echo 'Minifying CSS'
lightningcss --minify --targets '> 0.25%, not IE 11' _site/style/*.css -o _site/style/*.css
echo 'Building site' echo 'Building site'
yarn --offline eleventy yarn --offline eleventy
echo 'Minifying HTML'
minify --all --recursive --output . _site
''; '';
installPhase = '' installPhase = ''

57
flake.lock Normal file
View file

@ -0,0 +1,57 @@
{
"nodes": {
"flake-utils": {
"inputs": {
"systems": "systems"
},
"locked": {
"lastModified": 1731533236,
"narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "11707dc2f618dd54ca8739b309ec4fc024de578b",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 0,
"narHash": "sha256-5fNndbndxSx5d+C/D0p/VF32xDiJCJzyOqorOYW4JEo=",
"path": "/nix/store/0xbni69flk8380w0apw4h640n37wn1i9-source",
"type": "path"
},
"original": {
"id": "nixpkgs",
"type": "indirect"
}
},
"root": {
"inputs": {
"flake-utils": "flake-utils",
"nixpkgs": "nixpkgs"
}
},
"systems": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
}
},
"root": "root",
"version": 7
}

84
flake.nix Normal file
View file

@ -0,0 +1,84 @@
{
description = "renegade-solar.co.uk";
inputs = {
flake-utils.url = "github:numtide/flake-utils";
};
outputs =
{
self,
nixpkgs,
flake-utils,
}:
flake-utils.lib.eachDefaultSystem (
system:
let
nodeDeps = import ./node-deps.nix { inherit pkgs; };
inherit (nodeDeps) packageJSON nodeModules;
pkgs = import nixpkgs {
inherit system;
};
# Common build inputs
commonBuildInputs = with pkgs; [
djlint
sass
vscode-langservers-extracted
yarn
yarn2nix
];
# Helper function to create scripts
mkScript =
name:
(pkgs.writeScriptBin name (builtins.readFile ./bin/${name})).overrideAttrs (old: {
buildCommand = "${old.buildCommand}\n patchShebangs $out";
});
# Helper function to create packages
mkPackage =
name:
pkgs.symlinkJoin {
inherit name;
paths = [ (mkScript name) ] ++ commonBuildInputs;
buildInputs = [ pkgs.makeWrapper ];
postBuild = "wrapProgram $out/bin/${name} --prefix PATH : $out/bin";
};
# Script names
scripts = [
"build"
"serve"
];
# Generate all packages
scriptPackages = builtins.listToAttrs (
map (name: {
inherit name;
value = mkPackage name;
}) scripts
);
in
rec {
defaultPackage = packages.serve;
packages = scriptPackages;
devShells = rec {
default = dev;
dev = pkgs.mkShell {
buildInputs = commonBuildInputs ++ (builtins.attrValues packages);
shellHook = ''
rm -rf node_modules
rm -rf package.json
ln -sf ${packageJSON} package.json
ln -sf ${nodeModules}/node_modules .
echo "Development environment ready!"
echo "Run 'serve' to start development server"
echo "Run 'build' to build the site in the _site directory"
'';
};
};
}
);
}