local zen browser pkg

This commit is contained in:
2026-03-09 15:32:03 +00:00
parent 4eb86aba19
commit fa847bdcda
5 changed files with 143 additions and 29 deletions
+113
View File
@@ -0,0 +1,113 @@
name: zen browser update
on:
schedule:
- cron: "20 6 * * *"
workflow_dispatch:
jobs:
update-zen-browser:
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: check latest zen browser release and update file
id: update
shell: bash
run: |
set -euo pipefail
FILE="modules/pkgs/zen-browser.nix"
current_version=$(python - <<'PY'
import re
s=open('modules/pkgs/zen-browser.nix').read()
m=re.search(r'version\s*=\s*"([^"]+)";', s)
print(m.group(1) if m else "")
PY
)
latest_version=$(python - <<'PY'
import json, urllib.request
url='https://api.github.com/repos/zen-browser/desktop/releases/latest'
with urllib.request.urlopen(url) as r:
data=json.load(r)
print(data.get('tag_name','').lstrip('v'))
PY
)
echo "current=$current_version"
echo "latest=$latest_version"
if [ -z "$latest_version" ] || [ "$latest_version" = "$current_version" ]; then
echo "updated=false" >> "$GITHUB_OUTPUT"
exit 0
fi
url="https://github.com/zen-browser/desktop/releases/download/${latest_version}/zen-x86_64.AppImage"
new_hash=$(nix store prefetch-file --json "$url" | python -c 'import json,sys; print(json.load(sys.stdin)["hash"])')
python - <<PY
import re
p='modules/pkgs/zen-browser.nix'
s=open(p).read()
s=re.sub(r'(version\s*=\s*")[^"]+(";)', r'\1${latest_version}\2', s, count=1)
s=re.sub(r'(hash\s*=\s*")[^"]+(";)', r'\1${new_hash}\2', s, count=1)
open(p,'w').write(s)
PY
echo "updated=true" >> "$GITHUB_OUTPUT"
echo "version=$latest_version" >> "$GITHUB_OUTPUT"
- name: create branch and commit
if: steps.update.outputs.updated == 'true'
shell: bash
run: |
set -euo pipefail
branch="bot/zen-browser-${{ steps.update.outputs.version }}"
git config user.name "gitea actions"
git config user.email "actions@localhost"
git checkout -B "$branch"
git add modules/pkgs/zen-browser.nix
git commit -m "update zen browser to ${{ steps.update.outputs.version }}"
git push --force origin "$branch"
- name: open pull request
if: steps.update.outputs.updated == 'true'
env:
GITEA_TOKEN: ${{ gitea.token }}
shell: bash
run: |
set -euo pipefail
api="${GITHUB_SERVER_URL}/api/v1/repos/${GITHUB_REPOSITORY}"
branch="bot/zen-browser-${{ steps.update.outputs.version }}"
existing=$(curl -fsS \
-H "Authorization: token ${GITEA_TOKEN}" \
"${api}/pulls?state=open" \
| python -c 'import json,sys; d=json.load(sys.stdin); b="'"$branch"'"; print(next((str(pr["number"]) for pr in d if pr.get("head",{}).get("ref")==b), ""))')
if [ -n "$existing" ]; then
echo "PR already exists: #$existing"
exit 0
fi
curl -fsS -X POST \
-H "Authorization: token ${GITEA_TOKEN}" \
-H "Content-Type: application/json" \
"${api}/pulls" \
-d "$(cat <<JSON
{
\"title\": \"update zen browser to ${{ steps.update.outputs.version }}\",
\"head\": \"${branch}\",
\"base\": \"${GITHUB_REF_NAME}\",
\"body\": \"automated update of zen browser appimage version and hash\"
}
JSON
)"
Generated
+1 -22
View File
@@ -55,28 +55,7 @@
"inputs": { "inputs": {
"flake-parts": "flake-parts", "flake-parts": "flake-parts",
"import-tree": "import-tree", "import-tree": "import-tree",
"nixpkgs": "nixpkgs", "nixpkgs": "nixpkgs"
"zen-browser": "zen-browser"
}
},
"zen-browser": {
"inputs": {
"nixpkgs": [
"nixpkgs"
]
},
"locked": {
"lastModified": 1772685307,
"narHash": "sha256-5xthZHeqwBeXNhnRIlxnCuaZLky0SZ6vQsxtd+eqhTU=",
"owner": "youwen5",
"repo": "zen-browser-flake",
"rev": "dc92d88524ee83308795bc90f6a9f1d965265aaa",
"type": "github"
},
"original": {
"owner": "youwen5",
"repo": "zen-browser-flake",
"type": "github"
} }
} }
}, },
-6
View File
@@ -9,12 +9,6 @@
}; };
import-tree.url = "github:vic/import-tree"; import-tree.url = "github:vic/import-tree";
# Third-party
zen-browser = {
url = "github:youwen5/zen-browser-flake";
inputs.nixpkgs.follows = "nixpkgs";
};
}; };
outputs = outputs =
+1 -1
View File
@@ -7,7 +7,7 @@
programs.firefox.enable = true; programs.firefox.enable = true;
environment.systemPackages = [ environment.systemPackages = [
inputs.zen-browser.packages.${pkgs.stdenv.hostPlatform.system}.default self.packages.${pkgs.stdenv.hostPlatform.system}.zen-browser
self.packages.${pkgs.stdenv.hostPlatform.system}.helium self.packages.${pkgs.stdenv.hostPlatform.system}.helium
]; ];
}; };
+28
View File
@@ -0,0 +1,28 @@
{ ... }: {
perSystem = { pkgs, ... }: {
packages.zen-browser = pkgs.appimageTools.wrapType2 rec {
pname = "zen-browser";
version = "1.19.1b";
src = pkgs.fetchurl {
url = "https://github.com/zen-browser/desktop/releases/download/${version}/zen-x86_64.AppImage";
hash = "sha256-h3lza2C+SxptpcX897Uf/nM8dNILUBXScSNQZlvSIQg=";
};
extraInstallCommands = let
contents = pkgs.appimageTools.extract { inherit pname version src; };
in ''
desktop_file=$(find ${contents} -name "*.desktop" | head -n1)
if [ -n "$desktop_file" ]; then
install -m 444 -D "$desktop_file" "$out/share/applications/${pname}.desktop"
substituteInPlace "$out/share/applications/${pname}.desktop" \
--replace 'Exec=AppRun' 'Exec=${pname}' || true
fi
if [ -d ${contents}/usr/share/icons ]; then
cp -r ${contents}/usr/share/icons $out/share
fi
'';
};
};
}