packages default all fonts, devShell tools for compiling fonts.

This commit is contained in:
Denis Knauf 2023-06-20 14:28:41 +02:00
parent 4b8974f7aa
commit 17bb7663ad
6 changed files with 187 additions and 128 deletions

18
collection.nix Normal file
View file

@ -0,0 +1,18 @@
# vim: set noet sw=2 ts=2 sts=2:
{lib, pkgs, fonts, ...}:
with pkgs;
stdenv.mkDerivation {
name = "fonts-collection";
nativeBuildInputs = [ coreutils ];
srcs = [ fonts.fira_code ];# lib.attrsets.attrValues fonts;
unpackPhase = " ";
installPhase = ''
mkdir -p "$out/share/"{fonts,doc}
for src in $srcs
do
cd $src
find * -type d -exec mkdir -p "$out/{}" \;
find * -not -type d -exec ln -s "$src/{}" "$out/{}" \;
done
'';
}

View file

@ -1,90 +1,91 @@
# vim: set noet sw=2 ts=2 sts=2: # vim: set noet sw=2 ts=2 sts=2:
{lib, nixpkgs, sfnt2woff-zopfli, ...}: {lib, pkgs, ...}:
{src ? null , srcs ? null, name ? "", pname ? "", version ? ""}: {src ? null , srcs ? null, name ? "", pname ? "", version ? ""}:
let with pkgs;
name_ = let
if "" != name name_ =
then name if "" != name
else "${pname}-v${version}"; then name
in stdenv.mkDerivation ({ else "${pname}-v${version}";
name = name_; in stdenv.mkDerivation ({
nativeBuildInputs = with nixpkgs; [ sfnt2woff-zopfli unzip coreutils fontconfig woff2 ]; name = name_;
unpackPhase = '' nativeBuildInputs = [ sfnt2woff-zopfli unzip coreutils fontconfig woff2 ];
source_dir="$TMPDIR/src" unpackPhase = ''
mkdir "$source_dir" source_dir="$TMPDIR/src"
cd "$source_dir" mkdir "$source_dir"
for s in $src $srcs cd "$source_dir"
do for s in $src $srcs
case "$s" in do
*.zip|*.tar|*.tar.gz|*.tgz|*.tar.xz|*.txz|*.tar.bz2|*.tbz2) case "$s" in
unpackFile "$s" *.zip|*.tar|*.tar.gz|*.tgz|*.tar.xz|*.txz|*.tar.bz2|*.tbz2)
;; unpackFile "$s"
*) ;;
cp -pr --reflink=auto -- "$s" "$(stripHash "$s")" *)
;; cp -pr --reflink=auto -- "$s" "$(stripHash "$s")"
esac ;;
done esac
''; done
buildPhase = '' '';
set -e buildPhase = ''
build_dir="$TMPDIR/build" set -e
mkdir "$build_dir" build_dir="$TMPDIR/build"
find "$source_dir" \( -name \*.otf -or -name \*.ttf -or -name \*.woff -or -name \*.woff2 \) -exec cp \{\} "$build_dir" \; mkdir "$build_dir"
cd "$build_dir" find "$source_dir" \( -name \*.otf -or -name \*.ttf -or -name \*.woff -or -name \*.woff2 \) -exec cp \{\} "$build_dir" \;
cd "$build_dir"
for s in *.otf *.ttf for s in *.otf *.ttf
do do
bn="''${s%.otf}" bn="''${s%.otf}"
bn="''${bn%.ttf}" bn="''${bn%.ttf}"
if ! [ -e "$bn.woff" ] if ! [ -e "$bn.woff" ]
then then
echo "sfnt2woff-zopfli $s => $bn.woff" echo "sfnt2woff-zopfli $s => $bn.woff"
sfnt2woff-zopfli "$s" sfnt2woff-zopfli "$s"
fi fi
if ! [ -e "$bn.woff2" ] if ! [ -e "$bn.woff2" ]
then then
echo "woff2_compress $s => $bn.woff2" echo "woff2_compress $s => $bn.woff2"
woff2_compress "$s" woff2_compress "$s"
fi fi
done done
for s in *.otf *.ttf *.woff for s in *.otf *.ttf *.woff
do do
fc="`dirname "$s"`/`basename "$s"`.fc" fc="`dirname "$s"`/`basename "$s"`.fc"
echo "fc-scan $s" echo "fc-scan $s"
LANG=C LC_NUMERIC=C fc-scan --format 'family=%{family} LANG=C LC_NUMERIC=C fc-scan --format 'family=%{family}
fullname=%{fullname} fullname=%{fullname}
postscriptname=%{postscriptname} postscriptname=%{postscriptname}
variable=%{variable} variable=%{variable}
slant=%{slant} slant=%{slant}
style=%{style} style=%{style}
weight=%{weight} weight=%{weight}
width=%{width} width=%{width}
' "$s" > "$fc" ' "$s" > "$fc"
done done
for s in *.woff2 for s in *.woff2
do do
o="`dirname "$s"`/`basename "$s" .woff2`.woff.fc" o="`dirname "$s"`/`basename "$s" .woff2`.woff.fc"
fc="`dirname "$s"`/`basename "$s"`.fc" fc="`dirname "$s"`/`basename "$s"`.fc"
cp "$o" "$fc" cp "$o" "$fc"
done done
''; '';
installPhase = '' installPhase = ''
cd "$TMPDIR" cd "$TMPDIR"
mkdir -p $out/share/{doc/${name_},fonts/{opentype,truetype,WOFF,WOFF2}{,/.fc}} mkdir -p $out/share/{doc/${name_},fonts/{opentype,truetype,WOFF,WOFF2}{,/.fc}}
find "$build_dir" -name \*.otf -exec cp \{\} $out/share/fonts/opentype \; find "$build_dir" -name \*.otf -exec cp \{\} $out/share/fonts/opentype \;
find "$build_dir" -name \*.ttf -exec cp \{\} $out/share/fonts/truetype \; find "$build_dir" -name \*.ttf -exec cp \{\} $out/share/fonts/truetype \;
find "$build_dir" -name \*.woff -exec cp \{\} $out/share/fonts/WOFF \; find "$build_dir" -name \*.woff -exec cp \{\} $out/share/fonts/WOFF \;
find "$build_dir" -name \*.woff2 -exec cp \{\} $out/share/fonts/WOFF2 \; find "$build_dir" -name \*.woff2 -exec cp \{\} $out/share/fonts/WOFF2 \;
find "$build_dir" -name \*.otf.fc -exec cp \{\} $out/share/fonts/opentype/.fc \; find "$build_dir" -name \*.otf.fc -exec cp \{\} $out/share/fonts/opentype/.fc \;
find "$build_dir" -name \*.ttf.fc -exec cp \{\} $out/share/fonts/truetype/.fc \; find "$build_dir" -name \*.ttf.fc -exec cp \{\} $out/share/fonts/truetype/.fc \;
find "$build_dir" -name \*.woff.fc -exec cp \{\} $out/share/fonts/WOFF/.fc \; find "$build_dir" -name \*.woff.fc -exec cp \{\} $out/share/fonts/WOFF/.fc \;
find "$build_dir" -name \*.woff2.fc -exec cp \{\} $out/share/fonts/WOFF2/.fc \; find "$build_dir" -name \*.woff2.fc -exec cp \{\} $out/share/fonts/WOFF2/.fc \;
find "$source_dir" -name \*.txt -exec cp \{\} $out/share/doc/${name_} \; find "$source_dir" -name \*.txt -exec cp \{\} $out/share/doc/${name_} \;
find "$source_dir" -name \*.md -exec cp \{\} $out/share/doc/${name_} \; find "$source_dir" -name \*.md -exec cp \{\} $out/share/doc/${name_} \;
find "$source_dir" -name \*.adoc -exec cp \{\} $out/share/doc/${name_} \; find "$source_dir" -name \*.adoc -exec cp \{\} $out/share/doc/${name_} \;
find "$source_dir" -name \*.html -exec cp \{\} $out/share/doc/${name_} \; find "$source_dir" -name \*.html -exec cp \{\} $out/share/doc/${name_} \;
find "$source_dir" -name \*.css -exec cp \{\} $out/share/doc/${name_} \; find "$source_dir" -name \*.css -exec cp \{\} $out/share/doc/${name_} \;
''; '';
} // (if null != src then { src = src; } else { srcs = srcs; })); } // (if null != src then { src = src; } else { srcs = srcs; }))

27
flake.lock Normal file
View file

@ -0,0 +1,27 @@
{
"nodes": {
"nixpkgs": {
"locked": {
"lastModified": 1686926720,
"narHash": "sha256-S49KAii1WiYGAYza+ZJR8Nem142YJ4Nkt4gMvZiovS0=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "b1bdd38ad9c3b67c25101b87906f6cc3b628317d",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixos-23.05-small",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"nixpkgs": "nixpkgs"
}
}
},
"root": "root",
"version": 7
}

View file

@ -1,23 +1,33 @@
# vim: set noet sw=2 ts=2 sts=2: # vim: set et sw=2 ts=2 sts=2:
{ {
description = "fonts"; description = "fonts";
inputs.nixpkgs.url = github:NixOS/nixpkgs/nixos-23.05-small; inputs.nixpkgs.url = github:NixOS/nixpkgs/nixos-23.05-small;
outputs = { self, nixpkgs }: outputs = { self, nixpkgs }:
let let
sfnt2woff-zopfli = callPackage ./sfnt2woff-zopfli.nix {}; allSystems = [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin" ];
fetchfont = callPackage ./fetchfont.nix {sfnt2woff-zopfli = sfnt2woff-zopfli; }; forAllSystems = f: (nixpkgs.lib.genAttrs allSystems (system: f {
fonts = callPackage ./fonts.nix {fetchfont = fetchfont; }; pkgs = import nixpkgs { inherit system; };
allSystems = [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin" ]; }));
forAllSystems = f: nixpkgs.lib.genAttrs allSystems (system: f { in rec {
pkgs = import nixpkgs { inherit system; }; #lib = {
}); # fetchfont = fetchfont;
in { #};
lib = { packages = forAllSystems ({pkgs}:
fetchfont = fetchfont; with pkgs;
}; let
packages = forAllSystems {pkgs}: { fetchfont = callPackage ./fetchfont.nix { pkgs = pkgs // { inherit sfnt2woff-zopfli; }; };
default = fonts // { sfnt2woff-zopfli = sfnt2woff-zopfli; }; sfnt2woff-zopfli = callPackage ./sfnt2woff-zopfli.nix {};
}; fonts = callPackage ./fonts.nix { fetchfont = fetchfont; };
}; default = callPackage ./collection.nix { fonts = fonts; };
in
fonts // { inherit sfnt2woff-zopfli default; }
);
devShell = forAllSystems ({pkgs}:
pkgs.mkShell {
name = "fonts-dev";
nativeBuildInputs = [ packages.${pkgs.system}.sfnt2woff-zopfli pkgs.woff2 ];
}
);
};
} }

View file

@ -1,51 +1,54 @@
# vim: set noet sw=2 ts=2 sts=2: # vim: set noet sw=2 ts=2 sts=2:
{lib, nixpkgs, fetchfont, ...}: {lib, pkgs, fetchfont, ...}:
with nixpkgs; { with pkgs;
let
github = path: "https://github.com/${path}";
in {
libre_barcode = libre_barcode =
fetchfont rec { fetchfont rec {
pname = "LibreBarcode"; pname = "LibreBarcode";
version = "1.008"; version = "1.008";
src = fetchurl { name = "${pname}-${version}.zip"; hash = "sha256-47ntjMcZR4j5ybGU2UAA5t4FTPvyAvTiDSKYGEdRDQU="; url = "https://github.com/graphicore/librebarcode/releases/download/v${version}/${pname}_v${version}.zip"; }; src = fetchurl { name = "${pname}-${version}.zip"; hash = "sha256-47ntjMcZR4j5ybGU2UAA5t4FTPvyAvTiDSKYGEdRDQU="; url = github "graphicore/librebarcode/releases/download/v${version}/${pname}_v${version}.zip"; };
}; };
fira_code = fira_code =
fetchfont rec { fetchfont rec {
pname = "FiraCode"; pname = "FiraCode";
version = "6.2"; version = "6.2";
src = fetchurl { name = "${pname}-${version}.zip"; hash = "sha256-CUmRW6jrJNif2T0Qp/9iP0KDDXxf/D7L+WDk7K0+Pnk="; url = "https://github.com/tonsky/FiraCode/releases/download/${version}/Fira_Code_v${version}.zip"; }; src = fetchurl { name = "${pname}-${version}.zip"; hash = "sha256-CUmRW6jrJNif2T0Qp/9iP0KDDXxf/D7L+WDk7K0+Pnk="; url = github "tonsky/FiraCode/releases/download/${version}/Fira_Code_v${version}.zip"; };
}; };
fira_mono = fira_mono =
fetchfont rec { fetchfont rec {
pname = "FiraMono"; pname = "FiraMono";
version = "4.202"; version = "4.202";
src = fetchurl { name = "${pname}-${version}.tar.gz"; hash = "sha256-2GJpZXOH8UTXe6EgERJPMPQj9wZy4VdtwW+Ri7Ft3+Q="; url = "https://github.com/mozilla/Fira/archive/refs/tags/${version}.tar.gz"; }; src = fetchurl { name = "${pname}-${version}.tar.gz"; hash = "sha256-2GJpZXOH8UTXe6EgERJPMPQj9wZy4VdtwW+Ri7Ft3+Q="; url = github "mozilla/Fira/archive/refs/tags/${version}.tar.gz"; };
}; };
alegreya = alegreya =
fetchfont rec { fetchfont rec {
pname = "Alegreya"; pname = "Alegreya";
version = "2.008"; version = "2.008";
src = fetchurl { name = "${pname}-${version}.tar.gz"; hash = "sha256-RNrL48S2DCA7HWDwpV6/bBOYI/g/0jT5sHjs58sVZ24="; url = "https://github.com/huertatipografica/${pname}/archive/refs/tags/v${version}.tar.gz"; }; src = fetchurl { name = "${pname}-${version}.tar.gz"; hash = "sha256-RNrL48S2DCA7HWDwpV6/bBOYI/g/0jT5sHjs58sVZ24="; url = github "huertatipografica/${pname}/archive/refs/tags/v${version}.tar.gz"; };
}; };
alegreya_sans = alegreya_sans =
fetchfont rec { fetchfont rec {
pname = "Alegreya-Sans"; pname = "Alegreya-Sans";
version = "2.008"; version = "2.008";
src = fetchurl { name = "${pname}-${version}.tar.gz"; hash = "sha256-6lRVctSeGOZ11rcqZ1TaNE4kucrMPSt2wesr+a5zpAI="; url = "https://github.com/huertatipografica/${pname}/archive/refs/tags/v${version}.tar.gz"; }; src = fetchurl { name = "${pname}-${version}.tar.gz"; hash = "sha256-6lRVctSeGOZ11rcqZ1TaNE4kucrMPSt2wesr+a5zpAI="; url = github "huertatipografica/${pname}/archive/refs/tags/v${version}.tar.gz"; };
}; };
inconsolata = inconsolata =
fetchfont rec { fetchfont rec {
pname = "Inconsolata"; pname = "Inconsolata";
version = "3.000"; version = "3.000";
src = fetchurl { name = "${pname}-${version}.tar.gz"; hash = "sha256-8tjYumyqeFqWbvF5loIqsUupHsQjQxop4bbEsUvEzaU="; url = "https://github.com/googlefonts/${pname}/archive/refs/tags/v${version}.tar.gz"; }; src = fetchurl { name = "${pname}-${version}.tar.gz"; hash = "sha256-8tjYumyqeFqWbvF5loIqsUupHsQjQxop4bbEsUvEzaU="; url = github "googlefonts/${pname}/archive/refs/tags/v${version}.tar.gz"; };
}; };
rubik_dirt = #rubik_dirt =
fetchfont rec { # fetchfont rec {
pname = "RubikDirt"; # pname = "RubikDirt";
version = "2"; # version = "2";
srcs = let baseurl = "https://github.com/NaN-xyz/Rubik-Filtered/raw/7f47b7f79f903e1d6af9883da43a84928e02b816/dirt/fonts"; # srcs =
in [ # let baseurl = github "NaN-xyz/Rubik-Filtered/raw/7f47b7f79f903e1d6af9883da43a84928e02b816/dirt/fonts";
(fetchurl { name = "${pname}-Regular.ttf"; hash = "sha256-nePZKOQ0pH7IXXWQEsig6/6rCGAHbupOOYmkfF4hMSM="; url = "${baseurl}/ttf/${pname}-Regular.ttf"; }) # in [
(fetchurl { name = "${pname}-Regular.woff2"; hash = "sha256-xh1jUaN5FRaU/omXT7U9T9Qhu+Cl/YddAJnSpgCOqYk="; url = "${baseurl}/webfonts/${pname}-Regular.woff2"; }) # (fetchurl { name = "${pname}-Regular.ttf"; hash = "sha256-nePZKOQ0pH7IXXWQEsig6/6rCGAHbupOOYmkfF4hMSM="; url = "${baseurl}/ttf/${pname}-Regular.ttf"; })
]; # (fetchurl { name = "${pname}-Regular.woff2"; hash = "sha256-xh1jUaN5FRaU/omXT7U9T9Qhu+Cl/YddAJnSpgCOqYk="; url = "${baseurl}/webfonts/${pname}-Regular.woff2"; })
}; # ];
}; # };
}; }

View file

@ -1,6 +1,6 @@
# vim: set noet sw=2 ts=2 sts=2: # vim: set noet sw=2 ts=2 sts=2:
{lib, nixpkgs, ...}: {lib, pkgs, ...}:
with nixpkgs; with pkgs;
stdenv.mkDerivation rec{ stdenv.mkDerivation rec{
pname = "sfnt2woff-zopfli"; pname = "sfnt2woff-zopfli";
version = "1.3.1"; version = "1.3.1";
@ -17,4 +17,4 @@ stdenv.mkDerivation rec{
mkdir -p $out/bin mkdir -p $out/bin
cp sfnt2woff-zopfli $out/bin cp sfnt2woff-zopfli $out/bin
''; '';
}; }