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
|
||||
yarn eleventy
|
||||
find _site -name "*.html" -exec htmlbeautifier {} \;
|
||||
|
|
61
default.nix
61
default.nix
|
@ -1,52 +1,15 @@
|
|||
{
|
||||
pkgs ? import <nixpkgs> { },
|
||||
}:
|
||||
|
||||
(import
|
||||
(
|
||||
let
|
||||
# Input source files
|
||||
src = ./.;
|
||||
nodeDeps = import ./node-deps.nix { inherit pkgs; };
|
||||
inherit (nodeDeps) packageJSON nodeModules;
|
||||
lock = builtins.fromJSON (builtins.readFile ./flake.lock);
|
||||
flake-compat = fetchTarball {
|
||||
url = "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz";
|
||||
sha256 = lock.nodes.flake-compat.locked.narHash;
|
||||
};
|
||||
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; [
|
||||
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
|
||||
'';
|
||||
flake-compat
|
||||
)
|
||||
{
|
||||
src = ./.;
|
||||
}
|
||||
).defaultNix.packages.${builtins.currentSystem}.site
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
"systems": "systems"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1731533236,
|
||||
"narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=",
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
|
@ -13,8 +12,10 @@
|
|||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=",
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
"rev": "11707dc2f618dd54ca8739b309ec4fc024de578b",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
|
|
74
flake.nix
74
flake.nix
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
description = "renegade-solar.co.uk";
|
||||
description = "vegan-prestwich";
|
||||
inputs = {
|
||||
flake-utils.url = "github:numtide/flake-utils";
|
||||
flake-utils.url = "github:numtide/flake-utils/11707dc2f618dd54ca8739b309ec4fc024de578b?narHash=sha256-l0KFg5HjrsfsO/JpG%2Br7fRrqm12kzFHyUHqHCVpMMbI%3D";
|
||||
};
|
||||
outputs =
|
||||
{
|
||||
|
@ -12,30 +12,69 @@
|
|||
flake-utils.lib.eachDefaultSystem (
|
||||
system:
|
||||
let
|
||||
pkgs = import nixpkgs { inherit system; };
|
||||
nodeDeps = import ./node-deps.nix { inherit pkgs; };
|
||||
inherit (nodeDeps) packageJSON nodeModules;
|
||||
projectName = builtins.baseNameOf ./.;
|
||||
|
||||
pkgs = import nixpkgs {
|
||||
inherit system;
|
||||
};
|
||||
|
||||
# Common build inputs
|
||||
commonBuildInputs = with pkgs; [
|
||||
djlint
|
||||
rubyPackages_3_4.htmlbeautifier
|
||||
sass
|
||||
vscode-langservers-extracted
|
||||
yarn
|
||||
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 =
|
||||
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 {
|
||||
|
@ -45,13 +84,11 @@
|
|||
postBuild = "wrapProgram $out/bin/${name} --prefix PATH : $out/bin";
|
||||
};
|
||||
|
||||
# Script names
|
||||
scripts = [
|
||||
"build"
|
||||
"serve"
|
||||
];
|
||||
|
||||
# Generate all packages
|
||||
scriptPackages = builtins.listToAttrs (
|
||||
map (name: {
|
||||
inherit name;
|
||||
|
@ -60,19 +97,18 @@
|
|||
);
|
||||
|
||||
in
|
||||
rec {
|
||||
defaultPackage = packages.serve;
|
||||
packages = scriptPackages;
|
||||
{
|
||||
defaultPackage = siteDrv;
|
||||
packages = scriptPackages // {
|
||||
site = siteDrv;
|
||||
};
|
||||
|
||||
devShells = rec {
|
||||
default = dev;
|
||||
dev = pkgs.mkShell {
|
||||
buildInputs = commonBuildInputs ++ (builtins.attrValues packages);
|
||||
buildInputs = commonBuildInputs ++ (builtins.attrValues scriptPackages);
|
||||
shellHook = ''
|
||||
rm -rf node_modules
|
||||
rm -rf package.json
|
||||
ln -sf ${packageJSON} package.json
|
||||
ln -sf ${nodeModules}/node_modules .
|
||||
${setupNodeModules}
|
||||
echo "Development environment ready!"
|
||||
echo "Run 'serve' to start development server"
|
||||
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