Skip to content

Commit

Permalink
Create role to build & install Ioesvka font
Browse files Browse the repository at this point in the history
  • Loading branch information
kdkasad committed Jul 17, 2024
1 parent f4aceca commit e9f74f1
Show file tree
Hide file tree
Showing 5 changed files with 118 additions and 0 deletions.
3 changes: 3 additions & 0 deletions ci/config_overrides.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,6 @@ homebrew_cask_apps_file: "{{ undef() }}"
homebrew_cask_apps:
- iterm2
- vscodium

# Don't build Iosevka fonts
iosevka_enabled: false
9 changes: 9 additions & 0 deletions config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,12 @@ vscodium_extensions_list_path: ~/.config/setup/vscode-extensions.txt
# Don't modify ~/.*shrc to include NVM, since I already do that in the .zshrc
# file installed by my dotfiles.
nvm_modify_shellrc: no

# Iosevka settings
iosevka_repo_ref: v30.3.2
iosevka_local_repo_path: ~/Miscellaneous/Iosevka
iosevka_private_build_plan: ~/.config/setup/iosevka-build-plan.toml
iosevka_targets:
- iosevka
- iosevka-term
- iosevka-fixed
9 changes: 9 additions & 0 deletions main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,12 @@
PATH: "{{ new_path }}"
tags:
- nvm

- name: Build & install Iosevka font
when: iosevka_enabled
ansible.builtin.import_role:
name: iosevka
environment:
PATH: "{{ new_path }}"
tags:
- iosevka
18 changes: 18 additions & 0 deletions roles/iosevka/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
# Whether or not to build Iosevka
iosevka_enabled: yes

# Iosevka Git repo information
iosevka_repo_url: https://github.com/be5invis/Iosevka.git
iosevka_repo_ref: main
iosevka_local_repo_path: ~/Downloads/Iosevka

# Build configuration
iosevka_private_build_plan: ~/.config/setup/iosevka-build-plan.toml
iosevka_targets:
- iosevka
- iosevka-term
- iosevka-fixed

# Installation configuration
iosevka_install_dir: ~/Library/Fonts
79 changes: 79 additions & 0 deletions roles/iosevka/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
---

# In this role, I use ansible.builtin.shell in several places where
# ansible.builtin.command would normally be preferred. However, using npm
# requires nvm to be initialized, which my dotfiles only set up for zsh. Thus we
# need to use zsh to execute the npm commands, which cannot be done with
# ansible.builtin.command.

- name: Ensure fontconfig is installed
community.general.homebrew:
name: fontconfig
state: present

- name: Check if Iosevka font exists
ansible.builtin.command:
cmd: fc-list -q Iosevka
register: fc_list
changed_when: false
failed_when: fc_list.rc not in [0, 1]

- name: Build & install Iosevka
when: fc_list.rc != 0
block:
- name: Ensure NPM is found
ansible.builtin.shell:
cmd: npm --version
executable: /bin/zsh
changed_when: false

- name: Clone Iosevka sources
ansible.builtin.git:
repo: "{{ iosevka_repo_url }}"
version: "{{ iosevka_repo_ref }}"
dest: "{{ iosevka_local_repo_path }}"
depth: 1
recursive: no

- name: Install build dependencies
ansible.builtin.shell:
cmd: npm ci
chdir: "{{ iosevka_local_repo_path }}"
executable: /bin/zsh
changed_when: true

- name: Copy build plans
ansible.builtin.copy:
src: "{{ iosevka_private_build_plan }}"
dest: "{{ [iosevka_local_repo_path, 'private-build-plans.toml'] | path_join }}"
remote_src: yes
mode: '0644'

- name: Compile Iosevka
ansible.builtin.shell:
cmd: "{{ (['npm', 'run', 'build'] + (iosevka_targets | map('regex_replace', '^', 'ttf::'))) | map('quote') | join(' ') }}"
chdir: "{{ iosevka_local_repo_path }}"
executable: /bin/zsh
changed_when: true

- name: Find compiled font files
ansible.builtin.find:
paths: "{{ [] | zip_longest(subdirs, fillvalue=distdir) | map('path_join') }}"
file_type: file
pattern: "*.ttf"
use_regex: no
# ansible.builtin.debug:
# msg: "{{ [] | zip_longest(subdirs, fillvalue=distdir) | map('path_join') }}"
vars:
subdirs: "{{ iosevka_targets | zip_longest([], fillvalue='ttf') | map('path_join') }}"
distdir: "{{ [iosevka_local_repo_path, 'dist'] | path_join }}"
changed_when: false
register: find_compiled_fonts

- name: Install compiled font files
ansible.builtin.copy:
remote_src: yes
src: "{{ item }}"
dest: "{{ [iosevka_install_dir, (item | basename)] | path_join }}"
mode: '0644'
loop: "{{ find_compiled_fonts.files | map(attribute='path') }}"

0 comments on commit e9f74f1

Please sign in to comment.