Merge Nix files together and add htmlbeautifier
This commit is contained in:
parent
24874d17cf
commit
fe9ac77d92
1
bin/build
Normal file → Executable file
1
bin/build
Normal file → Executable file
|
@ -2,3 +2,4 @@
|
||||||
|
|
||||||
sass --update style:_site/style --style compressed
|
sass --update style:_site/style --style compressed
|
||||||
yarn eleventy
|
yarn eleventy
|
||||||
|
find _site -name "*.html" -exec htmlbeautifier {} \;
|
||||||
|
|
61
default.nix
61
default.nix
|
@ -1,52 +1,15 @@
|
||||||
{
|
(import
|
||||||
pkgs ? import <nixpkgs> { },
|
(
|
||||||
}:
|
|
||||||
|
|
||||||
let
|
let
|
||||||
# Input source files
|
lock = builtins.fromJSON (builtins.readFile ./flake.lock);
|
||||||
src = ./.;
|
flake-compat = fetchTarball {
|
||||||
nodeDeps = import ./node-deps.nix { inherit pkgs; };
|
url = "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz";
|
||||||
inherit (nodeDeps) packageJSON nodeModules;
|
sha256 = lock.nodes.flake-compat.locked.narHash;
|
||||||
|
};
|
||||||
in
|
in
|
||||||
pkgs.stdenv.mkDerivation {
|
flake-compat
|
||||||
name = "veganprestwich-co-uk";
|
)
|
||||||
|
{
|
||||||
src = builtins.filterSource (
|
src = ./.;
|
||||||
path: type:
|
|
||||||
!(builtins.elem (baseNameOf path) [
|
|
||||||
"_site"
|
|
||||||
"node_modules"
|
|
||||||
".git"
|
|
||||||
])
|
|
||||||
) src;
|
|
||||||
|
|
||||||
nativeBuildInputs = with pkgs; [
|
|
||||||
cacert
|
|
||||||
lightningcss
|
|
||||||
sass
|
|
||||||
yarn
|
|
||||||
];
|
|
||||||
|
|
||||||
configurePhase = ''
|
|
||||||
export HOME=$TMPDIR
|
|
||||||
mkdir -p _site/style
|
|
||||||
|
|
||||||
cp -r ${nodeModules}/node_modules .
|
|
||||||
chmod -R +w node_modules
|
|
||||||
cp ${packageJSON} package.json
|
|
||||||
'';
|
|
||||||
|
|
||||||
buildPhase = ''
|
|
||||||
echo 'Building CSS'
|
|
||||||
sass --update style:_site/style --style compressed
|
|
||||||
|
|
||||||
echo 'Building site'
|
|
||||||
yarn --offline eleventy
|
|
||||||
'';
|
|
||||||
|
|
||||||
installPhase = ''
|
|
||||||
mkdir -p $out
|
|
||||||
cp -r _site/* $out/
|
|
||||||
rm -rf node_modules _site package.json
|
|
||||||
'';
|
|
||||||
}
|
}
|
||||||
|
).defaultNix.packages.${builtins.currentSystem}.site
|
||||||
|
|
|
@ -5,7 +5,6 @@
|
||||||
"systems": "systems"
|
"systems": "systems"
|
||||||
},
|
},
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1731533236,
|
|
||||||
"narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=",
|
"narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=",
|
||||||
"owner": "numtide",
|
"owner": "numtide",
|
||||||
"repo": "flake-utils",
|
"repo": "flake-utils",
|
||||||
|
@ -13,8 +12,10 @@
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
|
"narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=",
|
||||||
"owner": "numtide",
|
"owner": "numtide",
|
||||||
"repo": "flake-utils",
|
"repo": "flake-utils",
|
||||||
|
"rev": "11707dc2f618dd54ca8739b309ec4fc024de578b",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
74
flake.nix
74
flake.nix
|
@ -1,7 +1,7 @@
|
||||||
{
|
{
|
||||||
description = "renegade-solar.co.uk";
|
description = "vegan-prestwich";
|
||||||
inputs = {
|
inputs = {
|
||||||
flake-utils.url = "github:numtide/flake-utils";
|
flake-utils.url = "github:numtide/flake-utils/11707dc2f618dd54ca8739b309ec4fc024de578b?narHash=sha256-l0KFg5HjrsfsO/JpG%2Br7fRrqm12kzFHyUHqHCVpMMbI%3D";
|
||||||
};
|
};
|
||||||
outputs =
|
outputs =
|
||||||
{
|
{
|
||||||
|
@ -12,30 +12,69 @@
|
||||||
flake-utils.lib.eachDefaultSystem (
|
flake-utils.lib.eachDefaultSystem (
|
||||||
system:
|
system:
|
||||||
let
|
let
|
||||||
|
pkgs = import nixpkgs { inherit system; };
|
||||||
nodeDeps = import ./node-deps.nix { inherit pkgs; };
|
nodeDeps = import ./node-deps.nix { inherit pkgs; };
|
||||||
inherit (nodeDeps) packageJSON nodeModules;
|
inherit (nodeDeps) packageJSON nodeModules;
|
||||||
|
projectName = builtins.baseNameOf ./.;
|
||||||
|
|
||||||
pkgs = import nixpkgs {
|
|
||||||
inherit system;
|
|
||||||
};
|
|
||||||
|
|
||||||
# Common build inputs
|
|
||||||
commonBuildInputs = with pkgs; [
|
commonBuildInputs = with pkgs; [
|
||||||
djlint
|
djlint
|
||||||
|
rubyPackages_3_4.htmlbeautifier
|
||||||
sass
|
sass
|
||||||
vscode-langservers-extracted
|
vscode-langservers-extracted
|
||||||
yarn
|
yarn
|
||||||
yarn2nix
|
yarn2nix
|
||||||
];
|
];
|
||||||
|
|
||||||
# Helper function to create scripts
|
setupNodeModules = ''
|
||||||
|
rm -rf node_modules package.json
|
||||||
|
ln -sf ${packageJSON} package.json
|
||||||
|
ln -sf ${nodeModules}/node_modules .
|
||||||
|
'';
|
||||||
|
|
||||||
|
siteDrv = pkgs.stdenv.mkDerivation {
|
||||||
|
name = projectName;
|
||||||
|
|
||||||
|
src = builtins.filterSource (
|
||||||
|
path: type:
|
||||||
|
!(builtins.elem (baseNameOf path) [
|
||||||
|
"_site"
|
||||||
|
"node_modules"
|
||||||
|
".git"
|
||||||
|
])
|
||||||
|
) ./.;
|
||||||
|
|
||||||
|
nativeBuildInputs =
|
||||||
|
with pkgs;
|
||||||
|
[
|
||||||
|
cacert
|
||||||
|
lightningcss
|
||||||
|
]
|
||||||
|
++ commonBuildInputs;
|
||||||
|
|
||||||
|
configurePhase = ''
|
||||||
|
export HOME=$TMPDIR
|
||||||
|
mkdir -p _site/style
|
||||||
|
${setupNodeModules}
|
||||||
|
'';
|
||||||
|
|
||||||
|
buildPhase = ''
|
||||||
|
${./bin/build}
|
||||||
|
'';
|
||||||
|
|
||||||
|
installPhase = ''
|
||||||
|
mkdir -p $out
|
||||||
|
cp -r _site/* $out/
|
||||||
|
rm -rf node_modules _site package.json
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
mkScript =
|
mkScript =
|
||||||
name:
|
name:
|
||||||
(pkgs.writeScriptBin name (builtins.readFile ./bin/${name})).overrideAttrs (old: {
|
(pkgs.writeScriptBin name (builtins.readFile ./bin/${name})).overrideAttrs (old: {
|
||||||
buildCommand = "${old.buildCommand}\n patchShebangs $out";
|
buildCommand = "${old.buildCommand}\n patchShebangs $out";
|
||||||
});
|
});
|
||||||
|
|
||||||
# Helper function to create packages
|
|
||||||
mkPackage =
|
mkPackage =
|
||||||
name:
|
name:
|
||||||
pkgs.symlinkJoin {
|
pkgs.symlinkJoin {
|
||||||
|
@ -45,13 +84,11 @@
|
||||||
postBuild = "wrapProgram $out/bin/${name} --prefix PATH : $out/bin";
|
postBuild = "wrapProgram $out/bin/${name} --prefix PATH : $out/bin";
|
||||||
};
|
};
|
||||||
|
|
||||||
# Script names
|
|
||||||
scripts = [
|
scripts = [
|
||||||
"build"
|
"build"
|
||||||
"serve"
|
"serve"
|
||||||
];
|
];
|
||||||
|
|
||||||
# Generate all packages
|
|
||||||
scriptPackages = builtins.listToAttrs (
|
scriptPackages = builtins.listToAttrs (
|
||||||
map (name: {
|
map (name: {
|
||||||
inherit name;
|
inherit name;
|
||||||
|
@ -60,19 +97,18 @@
|
||||||
);
|
);
|
||||||
|
|
||||||
in
|
in
|
||||||
rec {
|
{
|
||||||
defaultPackage = packages.serve;
|
defaultPackage = siteDrv;
|
||||||
packages = scriptPackages;
|
packages = scriptPackages // {
|
||||||
|
site = siteDrv;
|
||||||
|
};
|
||||||
|
|
||||||
devShells = rec {
|
devShells = rec {
|
||||||
default = dev;
|
default = dev;
|
||||||
dev = pkgs.mkShell {
|
dev = pkgs.mkShell {
|
||||||
buildInputs = commonBuildInputs ++ (builtins.attrValues packages);
|
buildInputs = commonBuildInputs ++ (builtins.attrValues scriptPackages);
|
||||||
shellHook = ''
|
shellHook = ''
|
||||||
rm -rf node_modules
|
${setupNodeModules}
|
||||||
rm -rf package.json
|
|
||||||
ln -sf ${packageJSON} package.json
|
|
||||||
ln -sf ${nodeModules}/node_modules .
|
|
||||||
echo "Development environment ready!"
|
echo "Development environment ready!"
|
||||||
echo "Run 'serve' to start development server"
|
echo "Run 'serve' to start development server"
|
||||||
echo "Run 'build' to build the site in the _site directory"
|
echo "Run 'build' to build the site in the _site directory"
|
||||||
|
|
94
shell.nix
94
shell.nix
|
@ -1,94 +0,0 @@
|
||||||
{
|
|
||||||
pkgs ? import <nixpkgs> { },
|
|
||||||
}:
|
|
||||||
|
|
||||||
let
|
|
||||||
nodeDeps = import ./node-deps.nix { inherit pkgs; };
|
|
||||||
inherit (nodeDeps) packageJSON nodeModules;
|
|
||||||
in
|
|
||||||
pkgs.mkShell {
|
|
||||||
buildInputs = with pkgs; [
|
|
||||||
yarn
|
|
||||||
sass
|
|
||||||
lightningcss
|
|
||||||
];
|
|
||||||
|
|
||||||
shellHook = ''
|
|
||||||
rm -rf node_modules
|
|
||||||
rm -rf package.json
|
|
||||||
|
|
||||||
git pull
|
|
||||||
|
|
||||||
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"}
|
|
||||||
|
|
||||||
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
|
|
||||||
export -f serve
|
|
||||||
|
|
||||||
cleanup() {
|
|
||||||
echo "Cleaning up..."
|
|
||||||
rm -rf node_modules _site package.json
|
|
||||||
}
|
|
||||||
|
|
||||||
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"
|
|
||||||
'';
|
|
||||||
}
|
|
Loading…
Reference in a new issue