Export lib.mkJekyllSite

This commit is contained in:
stefan burke 2024-12-07 02:56:42 +00:00
parent 1a6f8ae45c
commit cb8b1cbb0b

View file

@ -1,25 +1,16 @@
{ {
description = "Jekyll site builder flake"; description = "Jekyll site builder flake";
inputs = { inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.11"; nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.11";
flake-utils.url = "github:numtide/flake-utils"; flake-utils.url = "github:numtide/flake-utils";
}; };
outputs = { self, nixpkgs, flake-utils }: {
outputs = { self, nixpkgs, flake-utils }: # Export mkJekyllSite directly at the top level
flake-utils.lib.eachDefaultSystem (system: lib = {
let mkJekyllSite = { pname, version ? "1.0.0", src, gemset ? ./gemset.nix, gemfile ? ./Gemfile, lockfile ? ./Gemfile.lock }:
pkgs = nixpkgs.legacyPackages.${system};
mkJekyllSite = {
pname,
version ? "1.0.0",
src,
gemset ? ./gemset.nix,
gemfile ? ./Gemfile,
lockfile ? ./Gemfile.lock
}:
let let
system = "x86_64-linux"; # Or make this an argument
pkgs = nixpkgs.legacyPackages.${system};
env = pkgs.bundlerEnv { env = pkgs.bundlerEnv {
name = pname; name = pname;
inherit (pkgs) ruby; inherit (pkgs) ruby;
@ -28,52 +19,42 @@
in in
pkgs.stdenv.mkDerivation { pkgs.stdenv.mkDerivation {
inherit pname version src; inherit pname version src;
nativeBuildInputs = with pkgs; [ nativeBuildInputs = with pkgs; [
ruby_3_3 ruby_3_3
minify minify
]; ];
configurePhase = '' configurePhase = ''
export HOME=$TMPDIR export HOME=$TMPDIR
mkdir -p _site mkdir -p _site
''; '';
buildPhase = '' buildPhase = ''
echo "Building site with Jekyll..." echo "Building site with Jekyll..."
JEKYLL_ENV=production ${env}/bin/jekyll build --source . --destination _site --trace JEKYLL_ENV=production ${env}/bin/jekyll build --source . --destination _site --trace
echo 'Minifying HTML' echo 'Minifying HTML'
minify --all --recursive --output . _site minify --all --recursive --output . _site
''; '';
installPhase = '' installPhase = ''
mkdir -p $out mkdir -p $out
cp -r _site/* $out/ cp -r _site/* $out/
''; '';
}; };
};
# Import tests # Keep the per-system outputs for compatibility
tests = import ./tests.nix { inherit pkgs mkJekyllSite; }; packages = flake-utils.lib.eachDefaultSystem (system: {
default = self.lib.mkJekyllSite {
in pname = "my-jekyll-site";
{ src = builtins.filterSource
packages.default = mkJekyllSite { (path: type: !(builtins.elem (baseNameOf path) [
pname = "my-jekyll-site"; "_site"
src = builtins.filterSource ".jekyll-cache"
(path: type: !(builtins.elem (baseNameOf path) [ ".git"
"_site" "node_modules"
".jekyll-cache" "result"
".git" "vendor"
"node_modules" ]))
"result" ./.;
"vendor" };
])) });
./.; };
};
lib.mkJekyllSite = mkJekyllSite;
inherit (tests) checks apps;
});
} }