Skip to content

Commit

Permalink
update nix
Browse files Browse the repository at this point in the history
  • Loading branch information
Cryolitia committed Apr 8, 2024
1 parent 7599e39 commit 210a177
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 64 deletions.
86 changes: 23 additions & 63 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,80 +33,40 @@ jobs:
with:
fetch-depth: 0

- name: Setup pnpm
uses: pnpm/action-setup@v3
- name: Install nix
uses: cachix/install-nix-action@v26
with:
version: latest
run_install: true
nix_path: "${{ matrix.nixPath }}"
extra_nix_config: |
experimental-features = nix-command flakes
access-tokens = github.com=${{ secrets.GITHUB_TOKEN }}
- uses: actions/setup-node@v4
with:
cache: pnpm
node-version: current

- name: Install
run: pnpm install

- name: Install mdBook
uses: baptiste0928/cargo-install@v2
with:
crate: mdbook
git: https://github.com/rust-lang/mdBook

- name: Install mdbook-epub
uses: baptiste0928/cargo-install@v2
with:
crate: mdbook-epub
git: https://github.com/Michael-F-Bryan/mdbook-epub
- name: Show nixpkgs version
run: nix-instantiate --eval -E '(import <nixpkgs> {}).lib.version'

- name: Install mdbook-typst-pdf
uses: baptiste0928/cargo-install@v2
- name: Setup cachix
uses: cachix/cachix-action@v14
with:
crate: mdbook-typst-pdf
git: https://github.com/KaiserY/mdbook-typst-pdf
name: cryolitia
extraPullNames: nix-community

- name: Install fonts
run: |
mkdir -p ~/.local/share/fonts/
curl -sL -o Noto_Sans.zip https://fonts.google.com/download?family=Noto%20Sans
unzip Noto_Sans.zip -d ~/.local/share/fonts/Noto_Sans
curl -sL -o Noto_Sans_SC.zip https://fonts.google.com/download?family=Noto%20Sans%20SC
unzip Noto_Sans_SC.zip -d ~/.local/share/fonts/Noto_Sans_SC
curl -sL -o Noto_Sans_Mono.zip https://fonts.google.com/download?family=Noto%20Sans%20Mono
unzip Noto_Sans_Mono.zip -d ~/.local/share/fonts/Noto_Sans_Mono
rm -fv ~/.local/share/fonts/Noto_Sans_Mono/NotoSansMono-VariableFont_wdth,wght.ttf
curl -sL -o Noto_Sans_KR.zip https://fonts.google.com/download?family=Noto%20Sans%20KR
unzip Noto_Sans_KR.zip -d ~/.local/share/fonts/Noto_Sans_KR
curl -sL -o Noto_Sans_Thai.zip https://fonts.google.com/download?family=Noto%20Sans%20Thai
unzip Noto_Sans_Thai.zip -d ~/.local/share/fonts/Noto_Sans_Thai
rm -fv ~/.local/share/fonts/Noto_Sans_Thai/NotoSansThai-VariableFont_wdth,wght.ttf
curl -sL -o Noto_Sans_Arabic.zip https://fonts.google.com/download?family=Noto%20Sans%20Arabic
unzip Noto_Sans_Arabic.zip -d ~/.local/share/fonts/Noto_Sans_Arabic
curl -sL -o Noto_Sans_Hebrew.zip https://fonts.google.com/download?family=Noto%20Sans%20Hebrew
unzip Noto_Sans_Hebrew.zip -d ~/.local/share/fonts/Noto_Sans_Hebrew
curl -sL -o Noto_Sans_Devanagari.zip https://fonts.google.com/download?family=Noto%20Sans%20Devanagari
unzip Noto_Sans_Devanagari.zip -d ~/.local/share/fonts/Noto_Sans_Devanagari
rm -fv ~/.local/share/fonts/Noto_Sans_Devanagari/NotoSansDevanagari-VariableFont_wdth,wght.ttf
curl -sL -o Noto_Emoji.zip https://fonts.google.com/download?family=Noto%20Emoji
unzip Noto_Emoji.zip -d ~/.local/share/fonts/Noto_Emoji
curl -sL -o times_sans_serif.zip https://dl.dafont.com/dl/?f=times_sans_serif
unzip times_sans_serif.zip -d ~/.local/share/fonts/times_sans_serif
fc-cache -rv
- name: Install Calibre
run: |
sudo apt install -y libegl1 libopengl0 libxcb-cursor0
sudo -v && wget -nv -O- https://download.calibre-ebook.com/linux-installer.sh | sudo sh /dev/stdin
- name: Setup Github Caches
uses: DeterminateSystems/magic-nix-cache-action@v4

- name: Build
env:
NODE_OPTIONS: --max_old_space_size=4096
run: |
sed -e "s/BUILD_TIME/$(TZ=Asia/Shanghai date -Isecond)/" -e "s/COMMIT_SHA/${{ github.sha }}/" -i src/about.md
pnpm run build
NIXPKGS_ALLOW_UNFREE=1 nix build .# --impure -v -L
- uses: actions/upload-artifact@v4
with:
path: |
result/**/*.epub
result/**/*.pdf
result/**/*.mobi
- name: Release eBook
if: github.ref == 'refs/heads/main' && github.event_name != 'pull_request'
env:
GITHUB_TOKEN: ${{ github.token }}
run: pnpm exec semantic-release
run: exit0 || pnpm exec semantic-release
47 changes: 47 additions & 0 deletions .github/workflows/update-flake.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: "Update flake"
on:
workflow_dispatch:
schedule:
# rebuild everyday at 2:51
# TIP: Choose a random time here so not all repositories are build at once:
# https://www.random.org/clock-times/?num=1&earliest=01%3A00&latest=08%3A00&interval=5&format=html&rnd=new
- cron: '31 2 * * 5'

permissions:
contents: write

jobs:
sync-flake:
runs-on: ubuntu-latest

steps:
- name: Install nix
uses: cachix/install-nix-action@v26
with:
nix_path: nixpkgs=channel:nixpkgs-unstable
extra_nix_config: |
experimental-features = nix-command flakes
access-tokens = github.com=${{ secrets.GITHUB_TOKEN }}
- name: Checkout
uses: actions/checkout@v4
with:
show-progress: false

- name: Setup Git
run: |
git config --global user.name "$GITHUB_ACTOR"
git config --global user.email "[email protected]"
git show -s
- name: Update flake
run: |
nix flake update --accept-flake-config
nix flake info --accept-flake-config
- name: Update flake
run: |
git add .
git status
git commit -m "flake update: $(date +'%Y-%m-%dT%H:%M:%S')" || exit 0
git push
5 changes: 5 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
, mdbook-epub
, nur-cryolitia
, source-han-serif
, typst
}:

stdenvNoCC.mkDerivation
Expand All @@ -60,6 +61,7 @@
mdbook-epub
nur-cryolitia.mdbook-typst-pdf
source-han-serif
typst
];

buildPhase = ''
Expand All @@ -73,6 +75,9 @@
mkdir -p book/mobi
ebook-convert book/epub/药娘的天空.epub book/mobi/药娘的天空.mobi
export TYPST_FONT_PATHS=${source-han-serif}/share/fonts/opentype/source-han-serif
typst compile book/typst-pdf/药娘的天空.typ
runHook postBuild
'';

Expand Down
2 changes: 1 addition & 1 deletion theme/template.typ
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#set text(
lang: "zh",
font: (
"Source Han Serif",
"Source Han Serif SC",
),
)

Expand Down

0 comments on commit 210a177

Please sign in to comment.