diff --git a/ci/config_overrides.yml b/ci/config_overrides.yml index 2a32e2334..e6e25288f 100644 --- a/ci/config_overrides.yml +++ b/ci/config_overrides.yml @@ -14,3 +14,6 @@ homebrew_cask_apps_file: "{{ undef() }}" homebrew_cask_apps: - iterm2 - vscodium + +# Don't build Iosevka fonts +iosevka_enabled: false diff --git a/config.yml b/config.yml index 1276f058f..b5c069380 100644 --- a/config.yml +++ b/config.yml @@ -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 diff --git a/main.yml b/main.yml index 5b5d86b48..0366493f4 100644 --- a/main.yml +++ b/main.yml @@ -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 diff --git a/roles/iosevka/defaults/main.yml b/roles/iosevka/defaults/main.yml new file mode 100644 index 000000000..224b96440 --- /dev/null +++ b/roles/iosevka/defaults/main.yml @@ -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 diff --git a/roles/iosevka/tasks/main.yml b/roles/iosevka/tasks/main.yml new file mode 100644 index 000000000..2bb0556e4 --- /dev/null +++ b/roles/iosevka/tasks/main.yml @@ -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') }}"