44 schedule :
55 - cron : ' 0 0 * * *'
66 workflow_dispatch :
7- # ⭐ 新增: 在推送到 main 分支时运行工作流
7+ # 在推送到 main 分支时运行工作流
88 push :
99 branches :
1010 - main
@@ -16,34 +16,45 @@ jobs:
1616 permissions :
1717 contents : write
1818
19- # 设置 NIX_CONFIG 环境变量,启用实验性功能
19+ # 设置 NIX_CONFIG 环境变量,启用实验性功能(对所有 Nix 命令有效)
2020 env :
2121 NIX_CONFIG : " extra-experimental-features = nix-command flakes"
2222
2323 steps :
2424 - name : Check out repository
2525 uses : actions/checkout@v4
2626
27- - name : Install Nix (Manual Script)
28- # 使用安装脚本以确保获取到最新的 Nix 版本
27+ # ⭐ 已移除 nix_version: '2.20.4'。Action 将自动安装最新稳定版本。
28+ - name : Install Nix and Setup Caching
29+ uses : cachix/install-nix-action@v22
30+ with :
31+ # 启用 GitHub Actions 缓存,加速后续构建并节省磁盘空间
32+ cache-nix-paths : true
33+ # 使用不稳定的 channel
34+ nix_path : nixpkgs=channel:nixos-unstable
35+
36+ # 清理步骤仍然保留,以在关键构建前最大限度释放运行器空间
37+ - name : Free up Disk Space
2938 run : |
30- curl -L https://nixos.org/nix/install | sh
31- # 将 Nix profile 路径添加到 PATH 中,以供后续步骤使用
32- echo "$HOME/.nix-profile/bin" >> $GITHUB_PATH
33- # 重新加载环境,确保 'nix' 可用
34- . $HOME/.nix-profile/etc/profile.d/nix.sh
39+ echo "Disk space before cleanup:"
40+ df -h /
41+ # 清理 apt 缓存和不再需要的系统依赖
42+ sudo apt-get autoremove --purge -y
43+ sudo apt-get clean
44+ # 运行 Nix 垃圾回收,删除所有不再被任何根目录引用的路径
45+ nix-collect-garbage -d
46+ echo "Disk space after cleanup:"
47+ df -h /
3548
36- - name : Install and Configure Cachix
49+ - name : Configure Personal Cachix (zerokaze420)
3750 run : |
38- # 1. 安装 Cachix CLI 工具
39- nix-env -iA cachix -f https://cachix.org/api/v1/install
51+ # Action 已经安装了 Cachix CLI,此处直接配置缓存
4052
41- # 2. 配置您的个人缓存 (zerokaze420)。这会自动设置拉取所需的公共密钥。
42- # 官方 NixOS 缓存(cache.nixos.org)通常会被 Nix 安装脚本自动配置。
53+ # 1. 配置您的个人缓存 (zerokaze420)。这会自动设置拉取所需的公共密钥。
4354 echo "Setting up personal cache (zerokaze420) for pushing/pulling..."
4455 cachix use zerokaze420
4556
46- # 3 . 认证:使用 GitHub Secrets 提供的令牌进行身份验证,以便推送到您的缓存
57+ # 2 . 认证:使用 GitHub Secrets 提供的令牌进行身份验证,以便推送到您的缓存
4758 cachix authtoken ${{ secrets.CACHIX_AUTH_TOKEN }}
4859
4960 - name : Update flake lock
@@ -54,11 +65,12 @@ jobs:
5465 run : nix build .#nixosConfigurations.nixos.config.system.build.toplevel
5566
5667 - name : Push Build Results to Cachix (zerokaze420)
57- # 'nix-store -qR result' 找到整个系统依赖树的闭包
68+ # 找到整个系统依赖树的闭包并推送到您的缓存
5869 run : |
5970 nix-store -qR result | cachix push zerokaze420
6071
6172 - name : Commit changes
6273 uses : stefanzweifel/git-auto-commit-action@v4
6374 with :
6475 commit_message : " chore: update flake.lock"
76+
0 commit comments