iosevka: Simplify custom build process

Although hopefully this can eventually be added to nodePackages, it uses
some devDependencies to build custom fonts. Node2nix doesn't currently
support enabling devDependencies for a single package.

- Got rid of redundant let-in statements.
- node-packages.json now only pulls in Iosevka.
- generate.sh
  * Uses a nix-shell shebang to ensure it builds using the current
    version of node2nix (the old version caused some issues due to the
    19.03 release version being 1.6.0 instead of 1.7.0).
  * Builds in development mode to fix the devDependencies issue.
- Use the tree of the built node package as sourceRoot instead of
  installing node dependencies manually. This means the source will have
  to be updated in both node-packages.json and default.nix, but to make
  things easier the derivation inherits the version number.
- Disparate build options now all live under privateBuildPlan, which is
  converted first with builtins.toJSON and then to TOML using remarshal
  (Unfortunately there is not currently a builtins.toTOML).
- Extra parameters can also be provided that will be converted to JSON
  then TOML. This will overwrite the default parameters.toml file.
This commit is contained in:
Riley Inman 2019-09-21 12:39:15 -04:00
parent c545e85de8
commit 98a7d7990e
4 changed files with 574 additions and 1106 deletions

View File

@ -1,83 +1,60 @@
{ { stdenv, lib, pkgs
stdenv, lib, pkgs, , nodejs, remarshal, ttfautohint-nox, otfcc
fetchFromGitHub, fetchurl,
nodejs, ttfautohint-nox, otfcc,
# Custom font set options. # Custom font set options.
# See https://github.com/be5invis/Iosevka#build-your-own-style # See https://github.com/be5invis/Iosevka#build-your-own-style
design ? [], upright ? [], italic ? [], oblique ? [], , privateBuildPlan ? null
family ? null, weights ? [], # Extra parameters. Can be used for ligature mapping.
# Custom font set name. Required if any custom settings above. , extraParameters ? null
set ? null, # Custom font set name. Required if any custom settings above.
# Extra parameters. Can be used for ligature mapping. , set ? null
extraParameters ? null
}: }:
assert (design != []) -> set != null; assert (privateBuildPlan != null) -> set != null;
assert (upright != []) -> set != null;
assert (italic != []) -> set != null;
assert (oblique != []) -> set != null;
assert (family != null) -> set != null;
assert (weights != []) -> set != null;
let let
system = builtins.currentSystem; nodePackages = import ./node-packages.nix {
nodePackages = import ./node-packages.nix { inherit pkgs system nodejs; }; inherit pkgs nodejs;
in inherit (stdenv.hostPlatform) system;
let pname = if set != null then "iosevka-${set}" else "iosevka"; in
let
version = "2.3.0";
name = "${pname}-${version}";
src = fetchFromGitHub {
owner = "be5invis";
repo ="Iosevka";
rev = "v${version}";
sha256 = "1qnbxhx9wvij9zia226mc3sy8j7bfsw5v1cvxvsbbwjskwqdamvv";
}; };
in in
stdenv.mkDerivation rec {
pname =
if set != null
then "iosevka-${set}"
else "iosevka";
with lib; inherit (src) version;
let quote = str: "\"" + str + "\""; in
let toTomlList = list: "[" + (concatMapStringsSep ", " quote list) +"]"; in
let unlines = concatStringsSep "\n"; in
let src = nodePackages."iosevka-https://github.com/be5invis/Iosevka/archive/v2.3.0.tar.gz";
param = name: options: sourceRoot = "${src.name}/lib/node_modules/iosevka";
if options != [] then "${name}=${toTomlList options}" else null;
config = unlines (lib.filter (x: x != null) [
"[buildPlans.${pname}]"
(param "design" design)
(param "upright" upright)
(param "italic" italic)
(param "oblique" oblique)
(if family != null then "family=\"${family}\"" else null)
(param "weights" weights)
]);
installNodeModules = unlines (lib.mapAttrsToList
(name: value: "mkdir -p node_modules/${name}\n cp -r ${value.outPath}/lib/node_modules/. node_modules")
nodePackages);
in
stdenv.mkDerivation { nativeBuildInputs = [
inherit name pname version src; nodejs
remarshal
otfcc
ttfautohint-nox
];
nativeBuildInputs = [ nodejs ttfautohint-nox otfcc ]; privateBuildPlanJSON = builtins.toJSON { buildPlans.${pname} = privateBuildPlan; };
extraParametersJSON = builtins.toJSON { ${pname} = extraParameters; };
passAsFile = [ "config" "extraParameters" ]; passAsFile = [ "privateBuildPlanJSON" "extraParametersJSON" ];
config = config;
extraParameters = extraParameters;
configurePhase = '' configurePhase = ''
mkdir -p node_modules/.bin runHook preConfigure
${installNodeModules} ${lib.optionalString (privateBuildPlan != null) ''
${optionalString (set != null) ''mv "$configPath" private-build-plans.toml''} remarshal -i "$privateBuildPlanJSONPath" -o private-build-plans.toml -if json -of toml
${optionalString (extraParameters != null) ''cat "$extraParametersPath" >> parameters.toml''} ''}
${lib.optionalString (extraParameters != null) ''
remarshal -i "$extraParametersJSONPath" -o parameters.toml -if json -of toml
''}
runHook postConfigure
''; '';
buildPhase = '' buildPhase = ''
npm run build -- ttf::${pname} runHook preBuild
npm run build -- ttf::$pname
runHook postBuild
''; '';
installPhase = '' installPhase = ''
@ -89,8 +66,8 @@ stdenv.mkDerivation {
enableParallelBuilding = true; enableParallelBuilding = true;
meta = with stdenv.lib; { meta = with stdenv.lib; {
homepage = https://be5invis.github.io/Iosevka/; homepage = https://be5invis.github.io/Iosevka;
downloadPage = "https://github.com/be5invis/Iosevka/releases"; downloadPage = https://github.com/be5invis/Iosevka/releases;
description = '' description = ''
Slender monospace sans-serif and slab-serif typeface inspired by Pragmata Slender monospace sans-serif and slab-serif typeface inspired by Pragmata
Pro, M+ and PF DIN Mono, designed to be the ideal font for programming. Pro, M+ and PF DIN Mono, designed to be the ideal font for programming.

14
pkgs/data/fonts/iosevka/generate.sh Normal file → Executable file
View File

@ -1,6 +1,10 @@
#!/bin/sh #!/usr/bin/env nix-shell
#! nix-shell -I nixpkgs=../../../.. -i bash -p nodePackages.node2nix
node2nix --nodejs-10 --input node-packages.json \ node2nix \
--output node-packages-generated.nix \ --nodejs-10 \
--composition node-packages.nix \ --input node-packages.json \
--node-env ./../../../development/node-packages/node-env.nix --output node-packages-generated.nix \
--composition node-packages.nix \
--node-env ./../../../development/node-packages/node-env.nix \
--development

File diff suppressed because it is too large Load Diff

View File

@ -1,20 +1,3 @@
[ [
"caryll-shapeops", { "iosevka": "https://github.com/be5invis/Iosevka/archive/v2.3.0.tar.gz" }
"libspiro-js",
"megaminx",
"object-assign",
"otfcc-ttcize",
"primitive-quadify-off-curves",
"toml",
"topsort",
"ttf2woff",
"ttf2woff2",
"unorm",
"verda",
"yargs",
"colors",
"patel",
"patrisika-scopes",
"eslint",
"stylus"
] ]