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,
fetchFromGitHub, fetchurl,
nodejs, ttfautohint-nox, otfcc,
{ stdenv, lib, pkgs
, nodejs, remarshal, ttfautohint-nox, otfcc
# Custom font set options.
# See https://github.com/be5invis/Iosevka#build-your-own-style
design ? [], upright ? [], italic ? [], oblique ? [],
family ? null, weights ? [],
# Custom font set name. Required if any custom settings above.
set ? null,
# Extra parameters. Can be used for ligature mapping.
extraParameters ? null
# Custom font set options.
# See https://github.com/be5invis/Iosevka#build-your-own-style
, privateBuildPlan ? null
# Extra parameters. Can be used for ligature mapping.
, extraParameters ? null
# Custom font set name. Required if any custom settings above.
, set ? null
}:
assert (design != []) -> set != null;
assert (upright != []) -> set != null;
assert (italic != []) -> set != null;
assert (oblique != []) -> set != null;
assert (family != null) -> set != null;
assert (weights != []) -> set != null;
assert (privateBuildPlan != null) -> set != null;
let
system = builtins.currentSystem;
nodePackages = import ./node-packages.nix { inherit pkgs system nodejs; };
in
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";
nodePackages = import ./node-packages.nix {
inherit pkgs nodejs;
inherit (stdenv.hostPlatform) system;
};
in
stdenv.mkDerivation rec {
pname =
if set != null
then "iosevka-${set}"
else "iosevka";
with lib;
let quote = str: "\"" + str + "\""; in
let toTomlList = list: "[" + (concatMapStringsSep ", " quote list) +"]"; in
let unlines = concatStringsSep "\n"; in
inherit (src) version;
let
param = name: options:
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
src = nodePackages."iosevka-https://github.com/be5invis/Iosevka/archive/v2.3.0.tar.gz";
sourceRoot = "${src.name}/lib/node_modules/iosevka";
stdenv.mkDerivation {
inherit name pname version src;
nativeBuildInputs = [
nodejs
remarshal
otfcc
ttfautohint-nox
];
nativeBuildInputs = [ nodejs ttfautohint-nox otfcc ];
passAsFile = [ "config" "extraParameters" ];
config = config;
extraParameters = extraParameters;
privateBuildPlanJSON = builtins.toJSON { buildPlans.${pname} = privateBuildPlan; };
extraParametersJSON = builtins.toJSON { ${pname} = extraParameters; };
passAsFile = [ "privateBuildPlanJSON" "extraParametersJSON" ];
configurePhase = ''
mkdir -p node_modules/.bin
${installNodeModules}
${optionalString (set != null) ''mv "$configPath" private-build-plans.toml''}
${optionalString (extraParameters != null) ''cat "$extraParametersPath" >> parameters.toml''}
runHook preConfigure
${lib.optionalString (privateBuildPlan != null) ''
remarshal -i "$privateBuildPlanJSONPath" -o private-build-plans.toml -if json -of toml
''}
${lib.optionalString (extraParameters != null) ''
remarshal -i "$extraParametersJSONPath" -o parameters.toml -if json -of toml
''}
runHook postConfigure
'';
buildPhase = ''
npm run build -- ttf::${pname}
runHook preBuild
npm run build -- ttf::$pname
runHook postBuild
'';
installPhase = ''
@ -89,8 +66,8 @@ stdenv.mkDerivation {
enableParallelBuilding = true;
meta = with stdenv.lib; {
homepage = https://be5invis.github.io/Iosevka/;
downloadPage = "https://github.com/be5invis/Iosevka/releases";
homepage = https://be5invis.github.io/Iosevka;
downloadPage = https://github.com/be5invis/Iosevka/releases;
description = ''
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.

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 \
--output node-packages-generated.nix \
--composition node-packages.nix \
--node-env ./../../../development/node-packages/node-env.nix
node2nix \
--nodejs-10 \
--input node-packages.json \
--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",
"libspiro-js",
"megaminx",
"object-assign",
"otfcc-ttcize",
"primitive-quadify-off-curves",
"toml",
"topsort",
"ttf2woff",
"ttf2woff2",
"unorm",
"verda",
"yargs",
"colors",
"patel",
"patrisika-scopes",
"eslint",
"stylus"
{ "iosevka": "https://github.com/be5invis/Iosevka/archive/v2.3.0.tar.gz" }
]