2025-01-08 22:34:47 +00:00
|
|
|
{
|
2025-01-09 22:03:37 +00:00
|
|
|
description = "vegan-prestwich";
|
2025-01-08 22:34:47 +00:00
|
|
|
inputs = {
|
2025-01-09 22:03:37 +00:00
|
|
|
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
|
2025-01-09 22:03:37 +00:00
|
|
|
pkgs = import nixpkgs { inherit system; };
|
2025-01-08 22:34:47 +00:00
|
|
|
nodeDeps = import ./node-deps.nix { inherit pkgs; };
|
|
|
|
inherit (nodeDeps) packageJSON nodeModules;
|
2025-01-09 22:03:37 +00:00
|
|
|
projectName = builtins.baseNameOf ./.;
|
2025-01-08 22:34:47 +00:00
|
|
|
|
|
|
|
commonBuildInputs = with pkgs; [
|
|
|
|
sass
|
|
|
|
yarn
|
|
|
|
yarn2nix
|
|
|
|
];
|
|
|
|
|
2025-01-09 22:03:37 +00:00
|
|
|
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
|
2025-01-09 22:03:37 +00:00
|
|
|
'';
|
|
|
|
|
|
|
|
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
|
|
|
|
2025-01-09 22:03:37 +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
|
2025-01-09 22:03:37 +00:00
|
|
|
cacert
|
|
|
|
lightningcss
|
|
|
|
]
|
|
|
|
++ commonBuildInputs;
|
|
|
|
|
|
|
|
configurePhase = ''
|
|
|
|
export HOME=$TMPDIR
|
|
|
|
mkdir -p _site/style
|
|
|
|
${setupNodeModules}
|
|
|
|
'';
|
|
|
|
|
|
|
|
buildPhase = ''
|
2025-01-09 23:16:40 +00:00
|
|
|
${pkgs.bash}/bin/bash ${./bin/build}
|
2025-01-09 22:03:37 +00:00
|
|
|
'';
|
|
|
|
|
|
|
|
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
|
2025-01-09 22:03:37 +00:00
|
|
|
{
|
|
|
|
defaultPackage = siteDrv;
|
|
|
|
packages = scriptPackages // {
|
|
|
|
site = siteDrv;
|
|
|
|
};
|
2025-01-08 22:34:47 +00:00
|
|
|
|
|
|
|
devShells = rec {
|
|
|
|
default = dev;
|
|
|
|
dev = pkgs.mkShell {
|
2025-01-09 22:03:37 +00:00
|
|
|
buildInputs = commonBuildInputs ++ (builtins.attrValues scriptPackages);
|
2025-01-08 22:34:47 +00:00
|
|
|
shellHook = ''
|
2025-01-09 22:03:37 +00:00
|
|
|
${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"
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|