summary refs log tree commit diff
path: root/pkgs/data/fonts/iosevka/default.nix
diff options
context:
space:
mode:
authorRiley Inman <rileyminman@gmail.com>2019-09-21 12:39:15 -0400
committerRiley Inman <rileyminman@gmail.com>2019-09-21 12:54:46 -0400
commit98a7d7990e6df67fc53fdb5f95fa841fa595fc95 (patch)
tree74dbcad65bf53f8f6fe6de14829ec4d4f0d87004 /pkgs/data/fonts/iosevka/default.nix
parentc545e85de875d54a71d15983cbdc4dba46a5eb44 (diff)
downloadnixpkgs-98a7d7990e6df67fc53fdb5f95fa841fa595fc95.tar
nixpkgs-98a7d7990e6df67fc53fdb5f95fa841fa595fc95.tar.gz
nixpkgs-98a7d7990e6df67fc53fdb5f95fa841fa595fc95.tar.bz2
nixpkgs-98a7d7990e6df67fc53fdb5f95fa841fa595fc95.tar.lz
nixpkgs-98a7d7990e6df67fc53fdb5f95fa841fa595fc95.tar.xz
nixpkgs-98a7d7990e6df67fc53fdb5f95fa841fa595fc95.tar.zst
nixpkgs-98a7d7990e6df67fc53fdb5f95fa841fa595fc95.zip
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.
Diffstat (limited to 'pkgs/data/fonts/iosevka/default.nix')
-rw-r--r--pkgs/data/fonts/iosevka/default.nix109
1 files changed, 43 insertions, 66 deletions
diff --git a/pkgs/data/fonts/iosevka/default.nix b/pkgs/data/fonts/iosevka/default.nix
index 4864edde71d..10b0a0fd8f0 100644
--- a/pkgs/data/fonts/iosevka/default.nix
+++ b/pkgs/data/fonts/iosevka/default.nix
@@ -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
-
-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
+  inherit (src) version;
 
-stdenv.mkDerivation {
-  inherit name pname version src;
+  src = nodePackages."iosevka-https://github.com/be5invis/Iosevka/archive/v2.3.0.tar.gz";
+  sourceRoot = "${src.name}/lib/node_modules/iosevka";
 
-  nativeBuildInputs = [ nodejs ttfautohint-nox otfcc ];
+  nativeBuildInputs = [
+    nodejs
+    remarshal
+    otfcc
+    ttfautohint-nox
+  ];
 
-  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.