vegan-prestwich/flake.nix

136 lines
3.5 KiB
Nix
Raw Normal View History

2025-01-08 22:34:47 +00:00
{
description = "vegan-prestwich";
2025-01-08 22:34:47 +00:00
inputs = {
flake-utils.url = "github:numtide/flake-utils/11707dc2f618dd54ca8739b309ec4fc024de578b?narHash=sha256-l0KFg5HjrsfsO/JpG%2Br7fRrqm12kzFHyUHqHCVpMMbI%3D";
2025-01-08 22:34:47 +00:00
};
outputs =
{
self,
nixpkgs,
flake-utils,
}:
flake-utils.lib.eachDefaultSystem (
system:
let
pkgs = import nixpkgs { inherit system; };
2025-01-08 22:34:47 +00:00
nodeDeps = import ./node-deps.nix { inherit pkgs; };
inherit (nodeDeps) packageJSON nodeModules;
projectName = builtins.baseNameOf ./.;
2025-01-08 22:34:47 +00:00
commonBuildInputs = with pkgs; [
sass
yarn
yarn2nix
];
setupNodeModules = ''
rm -rf node_modules package.json
2025-01-09 23:24:43 +00:00
cp -r ${nodeModules}/node_modules .
chmod -R +w node_modules
cp ${packageJSON} package.json
'';
siteDrv = pkgs.stdenv.mkDerivation {
name = projectName;
2025-01-09 23:21:31 +00:00
XDG_CACHE_HOME = "/tmp/nix-cache";
2025-01-09 23:16:40 +00:00
src = builtins.filterSource (
path: type:
!(builtins.elem (baseNameOf path) [
"_site"
"node_modules"
".git"
])
) ./.;
nativeBuildInputs =
with pkgs;
[
2025-01-09 23:16:40 +00:00
bash
cacert
lightningcss
]
++ commonBuildInputs;
configurePhase = ''
2025-01-09 23:28:11 +00:00
set -x # Enable debug output
echo "Starting configure phase"
echo "TMPDIR=$TMPDIR"
echo "HOME=$HOME"
export HOME=$TMPDIR
2025-01-09 23:28:11 +00:00
echo "HOME is now $HOME"
mkdir -p _site/style
2025-01-09 23:28:11 +00:00
echo "Setting up node modules..."
rm -rf node_modules package.json
cp -r ${nodeModules}/node_modules .
chmod -R +w node_modules
cp ${packageJSON} package.json
echo "Listing current directory:"
ls -la
echo "Configure phase complete"
set +x
'';
buildPhase = ''
2025-01-09 23:16:40 +00:00
${pkgs.bash}/bin/bash ${./bin/build}
'';
installPhase = ''
mkdir -p $out
cp -r _site/* $out/
rm -rf node_modules _site package.json
'';
};
2025-01-08 22:34:47 +00:00
mkScript =
name:
(pkgs.writeScriptBin name (builtins.readFile ./bin/${name})).overrideAttrs (old: {
buildCommand = "${old.buildCommand}\n patchShebangs $out";
});
mkPackage =
name:
pkgs.symlinkJoin {
inherit name;
paths = [ (mkScript name) ] ++ commonBuildInputs;
buildInputs = [ pkgs.makeWrapper ];
postBuild = "wrapProgram $out/bin/${name} --prefix PATH : $out/bin";
};
scripts = [
"build"
"serve"
];
scriptPackages = builtins.listToAttrs (
map (name: {
inherit name;
value = mkPackage name;
}) scripts
);
in
{
defaultPackage = siteDrv;
packages = scriptPackages // {
site = siteDrv;
};
2025-01-08 22:34:47 +00:00
devShells = rec {
default = dev;
dev = pkgs.mkShell {
buildInputs = commonBuildInputs ++ (builtins.attrValues scriptPackages);
2025-01-08 22:34:47 +00:00
shellHook = ''
${setupNodeModules}
2025-01-08 22:34:47 +00:00
echo "Development environment ready!"
echo "Run 'serve' to start development server"
echo "Run 'build' to build the site in the _site directory"
'';
};
};
}
);
}