From a8b43aaa80ef3d27e20934af85a88acdffc0163c Mon Sep 17 00:00:00 2001 From: patrick-scho Date: Sun, 30 Nov 2025 23:30:17 +0100 Subject: add flake --- common.nix | 121 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ flake.nix | 50 +++++++++++++++++++++++++ 2 files changed, 171 insertions(+) create mode 100644 common.nix create mode 100644 flake.nix diff --git a/common.nix b/common.nix new file mode 100644 index 0000000..9cc41e6 --- /dev/null +++ b/common.nix @@ -0,0 +1,121 @@ +{ + pname, + version, + src, + gitSrc, + buildInputs ? [ ], + homepage, + description, + maintainers, + passthru ? { }, +}: + +{ + lib, + stdenv, + openssl, + zlib, + asciidoc, + libxml2, + libxslt, + docbook_xsl, + pkg-config, + coreutils, + gnused, + groff, + docutils, + gzip, + bzip2, + lzip, + xz, + zstd, + python3Packages, +}: + +stdenv.mkDerivation { + inherit + pname + version + src + gitSrc + passthru + ; + + separateDebugInfo = true; + + nativeBuildInputs = [ + pkg-config + asciidoc + ] + ++ (with python3Packages; [ + python + wrapPython + ]); + buildInputs = buildInputs ++ [ + openssl + zlib + libxml2 + libxslt + docbook_xsl + ]; + pythonPath = with python3Packages; [ + pygments + markdown + ]; + + postPatch = '' + sed -e 's|"gzip"|"${gzip}/bin/gzip"|' \ + -e 's|"bzip2"|"${bzip2.bin}/bin/bzip2"|' \ + -e 's|"lzip"|"${lzip}/bin/lzip"|' \ + -e 's|"xz"|"${xz.bin}/bin/xz"|' \ + -e 's|"zstd"|"${zstd}/bin/zstd"|' \ + -i ui-snapshot.c + + substituteInPlace filters/html-converters/man2html \ + --replace 'groff' '${groff}/bin/groff' + + substituteInPlace filters/html-converters/rst2html \ + --replace 'rst2html.py' '${docutils}/bin/rst2html.py' + ''; + + # Give cgit a git source tree and pass configuration parameters (as make + # variables). + preBuild = '' + mkdir -p git + tar --strip-components=1 -xf "$gitSrc" -C git + ''; + + makeFlags = [ + "prefix=$(out)" + "CGIT_SCRIPT_PATH=$(out)/cgit/" + "CC=${stdenv.cc.targetPrefix}cc" + "AR=${stdenv.cc.targetPrefix}ar" + ]; + + # Install manpage. + postInstall = '' + # xmllint fails: + #make install-man + + # bypassing xmllint works: + a2x --no-xmllint -f manpage cgitrc.5.txt + mkdir -p "$out/share/man/man5" + cp cgitrc.5 "$out/share/man/man5" + + wrapPythonProgramsIn "$out/lib/cgit/filters" "$out $pythonPath" + + for script in $out/lib/cgit/filters/*.sh $out/lib/cgit/filters/html-converters/txt2html; do + wrapProgram $script --prefix PATH : '${ + lib.makeBinPath [ + coreutils + gnused + ] + }' + done + ''; + + stripDebugList = [ "cgit" ]; + + enableParallelBuilding = true; +} + diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..a0d8c77 --- /dev/null +++ b/flake.nix @@ -0,0 +1,50 @@ +{ + description = "A Nix Flake for a fork of cgit"; + + inputs = { + nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; + }; + + outputs = { self, nixpkgs }: + let + forAllSystems = nixpkgs.lib.genAttrs [ + "x86_64-linux" + "aarch64-linux" + "x86_64-darwin" + "aarch64-darwin" + ]; + in + { + packages = forAllSystems (system: + let + pkgs = nixpkgs.legacyPackages.${system}; + in + { + default = pkgs.callPackage ({ lib, fetchurl, callPackage, luajit, nixosTests }: + # This logic was previously in package.nix + callPackage (import ./common.nix rec { + pname = "cgit-fork"; + version = "1.2.3"; + + src = ./.; + + # cgit needs the git source code to compile. + # Ensure this matches the version found in the Makefile of your fork. + gitSrc = fetchurl { + url = "mirror://kernel/software/scm/git/git-2.25.1.tar.xz"; + sha256 = "09lzwa183nblr6l8ib35g2xrjf9wm9yhk3szfvyzkwivdv69c9r2"; + }; + + buildInputs = [ luajit ]; + + passthru.tests = { inherit (nixosTests) cgit; }; + + homepage = "https://git.zx2c4.com/cgit/about/"; + description = "Web frontend for git repositories (Custom Fork)"; + maintainers = with lib.maintainers; [ ]; + }) { } + ) { }; + }); + }; +} + -- cgit v1.2.3