Created
April 13, 2022 20:08
-
-
Save RamKromberg/a73db192c2b9b0e4e4c344179cc23a02 to your computer and use it in GitHub Desktop.
ect and pdfsizeopt for nixos's home-manager
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ stdenv, lib, fetchgit, cmake, nasm, boost }: | |
stdenv.mkDerivation rec { | |
pname = "ect"; | |
version = "unstable-2020-09-08"; | |
src = fetchgit { | |
url = "https://github.com/fhanau/Efficient-Compression-Tool"; | |
rev = "777dcb8548640eba9d4b7c8337b01caefecdf5cf"; | |
sha256 = "1pd176nqdy7a544dkk8065hl5y4pgb85qqz4p01qdy7kvc9sd1x1"; | |
#sha256 = lib.fakeSha256; | |
#deepClone = false; | |
fetchSubmodules = true; | |
} + "/src"; | |
cmakeFlags = [ "-DECT_FOLDER_SUPPORT=ON" ]; | |
nativeBuildInputs = [ cmake ]; | |
buildInputs = [ nasm boost ]; | |
postInstall = '' | |
ln -s $out/bin/ect $out/bin/ECT | |
''; | |
meta = with lib; { | |
description = "Losslessly optimizes GZIP, ZIP, JPEG and PNG images"; | |
homepage = https://github.com/fhanau/Efficient-Compression-Tool; | |
license = licenses.asl20; | |
maintainers = with maintainers; [ ]; | |
mainProgram = "ect"; | |
}; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ stdenv, lib, fetchFromGitHub, fetchurl, makeWrapper, python2 | |
, ghostscript, pkg-config, autoconf | |
, advancecomp, jbig2enc, pngout, optipng, ect, zopfli | |
, adoptopenjdk-jre-bin | |
, perl, zip, netpbm, libjpeg_turbo, libtiff, libpng | |
}: | |
let | |
tif22pnm = stdenv.mkDerivation rec { | |
pname = "tif22pnm"; | |
version = "0.12"; | |
src = fetchFromGitHub { | |
sha256 = "13p3vraw3r0gi649kdfhshrav3q4a6xymyp5a93r1qds4yssgihn"; | |
rev = "22217c1a3ea355a899e9c7c79903488ca13d1dfe"; | |
repo = "tif22pnm"; | |
owner = "pts"; | |
}; | |
patchPhase = '' | |
patchShebangs do.sh | |
''; | |
buildInputs = [ libtiff libpng ]; | |
configureFlags = [ | |
"--with-libtiff-ldir=${libtiff.out}/lib" | |
"--with-libtiff-idir=${libtiff.dev}/include" | |
"--with-libpng-ldir=${libpng}/lib" | |
"--with-libpng-idir=${libpng.dev}/include" | |
]; | |
installPhase = '' | |
mkdir -p $out/bin | |
install -Dm755 tif22pnm $out/bin/tif22pnm | |
install -Dm755 png22pnm $out/bin/png22pnm | |
''; | |
meta = with lib; { | |
description = "TIFF-to-PNM and PNG-to-PNM converters"; | |
homepage = https://github.com/pts/tif22pnm; | |
license = licenses.gpl2; | |
maintainers = with maintainers; [ ]; | |
}; | |
}; | |
lzw_codec = stdenv.mkDerivation rec { | |
pname = "lzw_codec"; | |
version = "0.11"; | |
src = fetchFromGitHub { | |
sha256 = "1dqqi56n0aa9m60w39kx6hx3kqj830qz5mcgpx10mpmmss0vm2w1"; | |
rev = "54be8e96e64bf56525996b1c41b424b827728a00"; | |
repo = "lzw_codec"; | |
owner = "pts"; | |
}; | |
installPhase = '' | |
mkdir -p $out/bin | |
install -Dm755 lzw_codec $out/bin/lzw_codec | |
''; | |
meta = with lib; { | |
description = "LZW compressor and decompressor"; | |
homepage = https://github.com/pts/lzw_codec; | |
license = licenses.gpl2; | |
maintainers = with maintainers; [ ]; | |
mainProgram = "lzw_codec"; | |
}; | |
}; | |
sam2p = stdenv.mkDerivation rec { | |
pname = "sam2p"; | |
version = "unstable-2021-05-04"; | |
src = fetchFromGitHub { | |
sha256 = "0q23zd6z48gyadg0k06x2z7pdwqv82d3gpwfwz384y2ljgja0m8w"; | |
#sha256 = lib.fakeSha256; | |
rev = "f3e9cc0a2df1880a63f9f37c96e3595bca890cfa"; | |
repo = "sam2p"; | |
owner = "pts"; | |
}; | |
configureFlags = [ "--enable-gif" "--enable-lzw" ]; | |
buildInputs = [ perl makeWrapper lzw_codec tif22pnm | |
zip netpbm libjpeg_turbo ghostedscript ]; | |
installPhase = '' | |
mkdir -p $out/bin | |
install -Dm755 sam2p $out/share/sam2p/sam2p.unwrapped | |
makeWrapper $out/share/sam2p/sam2p.unwrapped $out/bin/sam2p \ | |
--prefix PATH : "${zip}/bin:${lzw_codec}/bin:${tif22pnm}/bin:${netpbm}/bin:${libjpeg_turbo}/bin:${ghostedscript}/bin:" | |
''; | |
meta = with lib; { | |
description = "raster to PostScript/PDF image conversion program"; | |
homepage = https://github.com/pts/sam2p; | |
license = licenses.gpl2; | |
maintainers = with maintainers; [ ]; | |
mainProgram = "sam2p"; | |
}; | |
}; | |
#old insecure version best left for pdfsizeopt's exclusive usage | |
ghostedscript = stdenv.mkDerivation rec { | |
pname = "ghostedscript"; | |
version = "9.05.0"; | |
src = fetchurl { | |
url = "https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/ghostscript/ghostscript-9.05.tar.bz2"; | |
sha256 = "1b6fi76x6pn9dmr9k9lh8kimn968dmh91k824fmm59d5ycm22h8g"; | |
}; | |
#a few modern config scripts off newer ghostscript | |
postUnpack = '' | |
tar --strip-components 1 -xf ${ghostscript.src} "ghostscript-${ghostscript.version}/config.guess" "ghostscript-${ghostscript.version}/config.sub" | |
''; | |
postPatch = '' | |
substituteInPlace base/gs.mak \ | |
--replace '$(EXP)$(ECHOGS_XE) -a $(gconfigd_h) -x 23 define -s -u GS_DOCDIR -x 2022 $(GS_DOCDIR) -x 22' '$(EXP)$(ECHOGS_XE) -a $(gconfigd_h) -x 23 define -s -u GS_DOCDIR -x 2022 /no-path-to-docs -x 22' | |
''; | |
outputs = [ "out" "man" ]; | |
enableParallelBuilding = true; | |
nativeBuildInputs = [ pkg-config autoconf ]; | |
preConfigure = '' | |
# https://ghostscript.com/doc/current/Make.htm | |
export CCAUX=$CC_FOR_BUILD | |
sed "s@if ( test -f \$(INCLUDE)[^ ]* )@if ( true )@; s@INCLUDE=/usr/include@INCLUDE=/no-such-path@" -i base/unix-aux.mak | |
autoupdate | |
autoconf | |
''; | |
configureFlags = [ | |
"--enable-dynamic" | |
]; | |
# make check does nothing useful | |
doCheck = false; | |
# don't build/install statically linked bin/gs | |
buildFlags = [ "so" ]; | |
installTargets = [ "soinstall" ]; | |
postInstall = '' | |
ln -s $out/bin/gsc $out/bin/gs | |
''; | |
meta = with lib; { | |
homepage = "https://www.ghostscript.com/"; | |
description = "PostScript interpreter (undead version)"; | |
license = lib.licenses.agpl3; | |
platforms = lib.platforms.all; | |
maintainers = with maintainers; [ ]; | |
mainProgram = "gs"; | |
}; | |
}; | |
#pdfsizeopt works around its buggy image handling | |
#see github regarding licensing issues | |
multivalent-pdf-tools = stdenv.mkDerivation rec { | |
pname = "multivalent-pdf-tools"; | |
version = "unstable-2006-01-02"; | |
src = fetchFromGitHub { | |
sha256 = "1wq3z3l9hxbq4r7qp3pqkpd561nzpasgwha0c0diggh06drw03dh"; | |
#sha256 = lib.fakeSha256; | |
rev = "09b6b5f784466daa66d3217e171e94aca86ccad2"; | |
repo = "multivalent-tools"; | |
owner = "tsibley"; | |
}; | |
buildInputs = [ makeWrapper ]; | |
installPhase = '' | |
mkdir -p $out/bin | |
install -Dm644 Multivalent20060102.jar $out/share/Multivalent20060102/Multivalent20060102.jar | |
makeWrapper ${adoptopenjdk-jre-bin}/bin/java $out/bin/Multivalent20060102 \ | |
--add-flags "-classpath $out/share/Multivalent20060102/Multivalent20060102.jar" | |
''; | |
meta = with lib; { | |
description = "PDF operations"; | |
homepage = https://github.com/tsibley/multivalent-tools; | |
license = licenses.gpl2; | |
maintainers = with maintainers; [ ]; | |
mainProgram = "Multivalent20060102"; | |
}; | |
}; | |
in | |
stdenv.mkDerivation rec { | |
pname = "pdfsizeopt"; | |
version = "unstable-2021-03-09"; | |
src = fetchFromGitHub { | |
sha256 = "1cvqpzwd69y3zkvqq8k2bvyaab35dqzfck3jvabmbm9hz07khndd"; | |
#sha256 = lib.fakeSha256; | |
rev = "e0b00eb65991bc6bdf196b3e6a005e7c86ac7123"; | |
repo = "pdfsizeopt"; | |
owner = "rbrito"; | |
}; | |
postPatch = '' | |
patchShebangs mksingle.py | |
sed -i 's/os.chdir(os.path.dirname(__file__))/#out/g' mksingle.py | |
sed -i 's/time.localtime()[:6]/(1980, 1, 1, 0, 0, 0)/g' mksingle.py | |
substituteInPlace mksingle.py \ | |
--replace "time.localtime(os.stat('lib/' + file_name).st_mtime)[:6]" "(1980, 1, 1, 0, 0, 0)" | |
''; | |
buildInputs = [ python2 makeWrapper advancecomp ]; | |
buildPhase = '' | |
python2 mksingle.py | |
''; | |
installPhase = '' | |
install -D -m 755 pdfsizeopt.single $out/lib/pdfsizeopt/pdfsizeopt.single | |
makeWrapper ${python2}/bin/python2 $out/bin/pdfsizeopt \ | |
--prefix PATH : "${ghostedscript}/bin:${zopfli}/bin:${pngout}/bin:${jbig2enc}/bin:${sam2p}/bin:${ect}/bin:${advancecomp}/bin:${optipng}/bin:${adoptopenjdk-jre-bin}/bin:${multivalent-pdf-tools}/share/Multivalent20060102:" \ | |
--add-flags "$out/lib/pdfsizeopt/pdfsizeopt.single" | |
''; | |
meta = with lib; { | |
description = "convert large PDF files to small ones"; | |
homepage = https://github.com/pts/pdfsizeopt; | |
license = licenses.gpl2; | |
maintainers = with maintainers; [ ]; | |
mainProgram = "pdfsizeopt"; | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment