initial: org-garden
This commit is contained in:
147
flake.nix
Normal file
147
flake.nix
Normal file
@@ -0,0 +1,147 @@
|
||||
{
|
||||
description = "Org-garden — org-roam to website publishing pipeline";
|
||||
|
||||
inputs = {
|
||||
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
|
||||
flake-utils.url = "github:numtide/flake-utils";
|
||||
};
|
||||
|
||||
outputs = { self, nixpkgs, flake-utils }:
|
||||
flake-utils.lib.eachDefaultSystem (system:
|
||||
let
|
||||
pkgs = import nixpkgs { inherit system; };
|
||||
fs = pkgs.lib.fileset;
|
||||
|
||||
# =========================================================================
|
||||
# Emacs with ox-hugo
|
||||
# =========================================================================
|
||||
# Needed at runtime by the escript (export calls `emacs --batch` with ox-hugo)
|
||||
emacsWithOxHugo = (pkgs.emacsPackagesFor pkgs.emacs-nox).emacsWithPackages
|
||||
(epkgs: [ epkgs.ox-hugo ]);
|
||||
|
||||
# =========================================================================
|
||||
# Elixir Pipeline
|
||||
# =========================================================================
|
||||
|
||||
# Pre-fetched Hex/Mix dependencies
|
||||
mixDeps = pkgs.beamPackages.fetchMixDeps {
|
||||
pname = "org-garden-mix-deps";
|
||||
version = "0.1.0";
|
||||
src = fs.toSource {
|
||||
root = ./.;
|
||||
fileset = fs.unions [
|
||||
./mix.exs
|
||||
./mix.lock
|
||||
];
|
||||
};
|
||||
sha256 = "sha256-si7JAomY1HZ33m6ihUJP5i6PO39CE1clYvuMtn0CbPU=";
|
||||
};
|
||||
|
||||
# Compiled org-garden escript
|
||||
orgGardenEscript = pkgs.beamPackages.mixRelease {
|
||||
pname = "org-garden";
|
||||
version = "0.1.0";
|
||||
src = fs.toSource {
|
||||
root = ./.;
|
||||
fileset = fs.unions [
|
||||
./mix.exs
|
||||
./mix.lock
|
||||
./lib
|
||||
];
|
||||
};
|
||||
escriptBinName = "org_garden";
|
||||
mixFodDeps = mixDeps;
|
||||
stripDebug = true;
|
||||
};
|
||||
|
||||
# =========================================================================
|
||||
# Quartz (fetched from upstream, patched)
|
||||
# =========================================================================
|
||||
|
||||
# Pin to specific upstream commit
|
||||
quartzVersion = "4.5.2";
|
||||
quartzRev = "ec00a40aefca73596ab76e3ebe3a8e1129b43688";
|
||||
|
||||
# Fetch upstream Quartz source
|
||||
quartzSrc = pkgs.fetchFromGitHub {
|
||||
owner = "jackyzha0";
|
||||
repo = "quartz";
|
||||
rev = quartzRev;
|
||||
hash = "sha256-HdtQB5+SRWiypOvAJuJa3Nodl4JHehp2Mz6Rj5gOG0w=";
|
||||
};
|
||||
|
||||
# Apply our patches to Quartz
|
||||
quartzPatched = pkgs.runCommand "quartz-patched-${quartzVersion}" {
|
||||
src = quartzSrc;
|
||||
} ''
|
||||
cp -r $src $out
|
||||
chmod -R u+w $out
|
||||
cd $out
|
||||
patch -p1 < ${./patches/01-glob-gitignore.patch}
|
||||
patch -p1 < ${./patches/02-build-gitignore.patch}
|
||||
patch -p1 < ${./patches/03-static-hugo.patch}
|
||||
patch -p1 < ${./patches/04-oxhugofm-figure.patch}
|
||||
'';
|
||||
|
||||
# Pre-fetch Quartz npm dependencies
|
||||
quartzDeps = pkgs.buildNpmPackage {
|
||||
pname = "org-garden-quartz-deps";
|
||||
version = quartzVersion;
|
||||
src = quartzPatched;
|
||||
npmDepsHash = "sha256-7u+VlIx44B3/ivM9vLMIOn+e4TL4eS6B682vhS+Ikb4=";
|
||||
dontBuild = true;
|
||||
installPhase = ''
|
||||
mkdir -p $out
|
||||
cp -r node_modules $out/node_modules
|
||||
'';
|
||||
};
|
||||
|
||||
# =========================================================================
|
||||
# Combined Application
|
||||
# =========================================================================
|
||||
|
||||
# Wrapped org-garden with Quartz bundled
|
||||
orgGardenApp = pkgs.writeShellApplication {
|
||||
name = "org-garden";
|
||||
runtimeInputs = [ emacsWithOxHugo pkgs.inotify-tools pkgs.nodejs_22 ];
|
||||
text = ''
|
||||
# Set up Quartz working directory
|
||||
QUARTZ_WORK=$(mktemp -d)
|
||||
trap 'rm -rf "$QUARTZ_WORK"' EXIT
|
||||
|
||||
# Copy patched Quartz source
|
||||
cp -r ${quartzPatched}/. "$QUARTZ_WORK/"
|
||||
chmod -R u+w "$QUARTZ_WORK"
|
||||
|
||||
# Copy default config files
|
||||
cp ${./quartz-config/quartz.config.ts} "$QUARTZ_WORK/"
|
||||
cp ${./quartz-config/quartz.layout.ts} "$QUARTZ_WORK/"
|
||||
cp ${./quartz-config/globals.d.ts} "$QUARTZ_WORK/"
|
||||
cp ${./quartz-config/index.d.ts} "$QUARTZ_WORK/"
|
||||
|
||||
# Link pre-built node_modules
|
||||
ln -s ${quartzDeps}/node_modules "$QUARTZ_WORK/node_modules"
|
||||
|
||||
export QUARTZ_PATH="$QUARTZ_WORK"
|
||||
export NODE_PATH="${pkgs.nodejs_22}/bin/node"
|
||||
|
||||
exec ${orgGardenEscript}/bin/org_garden "$@"
|
||||
'';
|
||||
};
|
||||
|
||||
in
|
||||
{
|
||||
packages.default = orgGardenApp;
|
||||
packages.escript = orgGardenEscript;
|
||||
packages.quartz-patched = quartzPatched;
|
||||
|
||||
devShells.default = pkgs.mkShell {
|
||||
buildInputs = [
|
||||
pkgs.elixir
|
||||
pkgs.inotify-tools
|
||||
emacsWithOxHugo
|
||||
pkgs.nodejs_22
|
||||
];
|
||||
};
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user