Files
tultemplategen/flake.nix
2025-12-10 15:29:15 +01:00

67 lines
2.3 KiB
Nix

{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
utils.url = "github:numtide/flake-utils";
tultemplate2.url = "git+https://git.zumepro.cz/tul/tultemplate2?lfs=1";
};
outputs = { nixpkgs, utils, tultemplate2, ... }: (utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs { inherit system; };
autogenFile = "src/data/autogen.js";
packageRootDir = "tul-thesis";
studyProgrammeList = builtins.fetchurl {
name = "stag-raw_study_programmes";
url = "https://stag.tul.cz/StagPortletsJSR168/ProhlizeniPrint?stateClass=cz.zcu.stag.portlets168.prohlizeni.browser.BrowserFakultaSearchState&wservice=programy/getStudijniProgramy&outputFormat=CSV&pouzePlatne=true&lang=cs";
sha256 = "03az2gj7aqrjmasfc0h936h6b56mvbdcki21qmk6v83n4y8mac28";
};
upstreamBundle = ''
if [ ! -d $packageRootDir ]
then
cp -R ${tultemplate2.packages.${system}.bundle} $packageRootDir
chmod -R +w $packageRootDir
fi
if [ ! -f template.zip ]
then
${pkgs.zip}/bin/zip -r template.zip $packageRootDir
fi
'';
runBuild = ''
${upstreamBundle}
PATH="$PATH:${pkgs.csvkit}/bin:${pkgs.jq}/bin"
cat ${studyProgrammeList} | ${pkgs.bash}/bin/bash build/parse_programmes.sh > ${autogenFile}
${pkgs.bash}/bin/bash build/enumerate_templates.sh $packageRootDir >> ${autogenFile}
'';
tultemplategen = pkgs.stdenv.mkDerivation {
name = "tultemplategen";
src = ./.;
inherit packageRootDir;
buildPhase = toString runBuild;
installPhase = ''
mkdir -p $out
cp -R src lib assets index.html template.zip $out
'';
};
server = with pkgs; (writeShellScriptBin "tultemplategen-server" ''
cd ${tultemplategen}
${python3}/bin/python -m http.server --bind localhost 8080
'');
in
{
packages.default = tultemplategen;
apps.default = {
type = "app";
program = "${server}/bin/tultemplategen-server";
meta.description = "Tultemplategen Server";
};
devShell = with pkgs; mkShell {
buildInputs = [
jq csvkit bash nodejs typst gnumake
];
inherit packageRootDir;
shellHook = toString runBuild;
};
}
));
}