diff --git a/.forgejo/workflows/main.yml b/.forgejo/workflows/main.yml index 86942cb..ec45041 100644 --- a/.forgejo/workflows/main.yml +++ b/.forgejo/workflows/main.yml @@ -4,7 +4,6 @@ on: push: branches: - main - pull_request: jobs: check: diff --git a/.forgejo/workflows/pull-request.yml b/.forgejo/workflows/pull-request.yml new file mode 100644 index 0000000..ba4afb3 --- /dev/null +++ b/.forgejo/workflows/pull-request.yml @@ -0,0 +1,81 @@ +name: Pull Request + +on: + pull_request: + +jobs: + check: + runs-on: x86_64 + steps: + - uses: actions/checkout@v4 + - name: Check flake + run: | + source /etc/bashrc + nix flake check + + list-packages: + runs-on: x86_64 + outputs: + packages: ${{ steps.set-matrix.outputs.packages }} + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + - id: set-matrix + run: | + source /etc/bashrc + ALL_PACKAGES=$(nix flake show --json | nix run nixpkgs#jq -- -r '.packages."x86_64-linux" | keys[]') + + if [ "${{ github.event_name }}" == "pull_request" ]; then + echo "Detecting changed packages for PR..." + BASE_REF="${{ github.base_ref }}" + # Ensure the base branch is available for diffing + git fetch origin "$BASE_REF" --depth=1 + CHANGED_FILES=$(git diff --name-only "origin/$BASE_REF"...HEAD) + + if echo "$CHANGED_FILES" | grep -qE 'flake.nix|flake.lock'; then + echo "Flake files changed, building all packages." + SELECTED_PACKAGES=$(echo "$ALL_PACKAGES" | nix run nixpkgs#jq -- -R . | nix run nixpkgs#jq -- -s -c .) + else + # Extract package names from pkgs// + CHANGED_PKGS=$(echo "$CHANGED_FILES" | grep '^pkgs/' | cut -d'/' -f2 | sort -u || true) + + FINAL_PKGS=() + for pkg in $CHANGED_PKGS; do + if echo "$ALL_PACKAGES" | grep -q "^$pkg$"; then + FINAL_PKGS+=("$pkg") + fi + done + + if [ ${#FINAL_PKGS[@]} -eq 0 ]; then + SELECTED_PACKAGES="[]" + else + SELECTED_PACKAGES=$(printf '%s\n' "${FINAL_PKGS[@]}" | nix run nixpkgs#jq -- -R . | nix run nixpkgs#jq -- -s -c .) + fi + fi + else + echo "Push event, listing all packages." + SELECTED_PACKAGES=$(echo "$ALL_PACKAGES" | nix run nixpkgs#jq -- -R . | nix run nixpkgs#jq -- -s -c .) + fi + + echo "packages=$SELECTED_PACKAGES" >> $GITHUB_OUTPUT + + build: + needs: [check, list-packages] + runs-on: x86_64 + if: ${{ fromJson(needs.list-packages.outputs.packages)[0] != null }} + strategy: + fail-fast: false + matrix: + package: ${{ fromJson(needs.list-packages.outputs.packages) }} + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Build package + run: | + source /etc/bashrc + nix build .#${{ matrix.package }} + + diff --git a/.forgejo/workflows/update-vscode-insiders.yml b/.forgejo/workflows/update-vscode-insiders.yml index 33c1486..4c0ec9c 100644 --- a/.forgejo/workflows/update-vscode-insiders.yml +++ b/.forgejo/workflows/update-vscode-insiders.yml @@ -7,15 +7,17 @@ on: jobs: update: - runs-on: x86_64 + runs-on: ubuntu-latest + steps: - name: Checkout code uses: actions/checkout@v4 - name: Check for new vscode-insiders release id: check + shell: bash run: | - source /etc/bashrc + source /etc/bashrc || true CURRENT_VERSION=$(grep 'version = ' pkgs/vscode-insiders/default.nix | head -1 | grep -oP '"[^"]+"' | tr -d '"') echo "Current version: $CURRENT_VERSION" @@ -25,45 +27,109 @@ jobs: if [ "$CURRENT_VERSION" = "$LATEST_VERSION" ]; then echo "Already up to date." - echo "updated=false" >> $GITHUB_OUTPUT + echo "updated=false" >> "$GITHUB_OUTPUT" exit 0 fi echo "New version found: $LATEST_VERSION" - echo "latest_version=$LATEST_VERSION" >> $GITHUB_OUTPUT - echo "updated=true" >> $GITHUB_OUTPUT + + echo "latest_version=$LATEST_VERSION" >> "$GITHUB_OUTPUT" + echo "updated=true" >> "$GITHUB_OUTPUT" - name: Update version and sha256 if: steps.check.outputs.updated == 'true' id: update + shell: bash run: | - source /etc/bashrc + source /etc/bashrc || true LATEST="${{ steps.check.outputs.latest_version }}" - URL="https://code.visualstudio.com/sha/download?build=insider&os=linux-x64" - echo "Fetching new sha256 for VSCode Insiders..." - NEW_SHA256=$(nix-prefetch-url --type sha256 "$URL" 2>/dev/null | tail -1) - NEW_SHA256_SRI=$(nix hash convert --hash-algo sha256 --to sri "$NEW_SHA256") - echo "New sha256 (SRI): $NEW_SHA256_SRI" + fetch_sri() { + local url="$1" - sed -i "s|version = \".*\";|version = \"${LATEST}\";|" pkgs/vscode-insiders/default.nix - sed -i "s|sha256 = \"sha256-.*\";|sha256 = \"${NEW_SHA256_SRI}\";|" pkgs/vscode-insiders/default.nix + HASH=$(nix-prefetch-url --type sha256 "$url" 2>/dev/null | tail -1) + nix hash convert --hash-algo sha256 --to sri "$HASH" + } - echo "new_sha256=$NEW_SHA256_SRI" >> $GITHUB_OUTPUT + echo "Fetching hashes..." + + LINUX_SHA=$(fetch_sri "https://code.visualstudio.com/sha/download?build=insider&os=linux-x64") + DARWIN_ARM_SHA=$(fetch_sri "https://code.visualstudio.com/sha/download?build=insider&os=darwin-arm64") + DARWIN_X64_SHA=$(fetch_sri "https://code.visualstudio.com/sha/download?build=insider&os=darwin") + + echo "Linux SHA: $LINUX_SHA" + echo "Darwin ARM SHA: $DARWIN_ARM_SHA" + echo "Darwin x64 SHA: $DARWIN_X64_SHA" + + export LATEST + export LINUX_SHA + export DARWIN_ARM_SHA + export DARWIN_X64_SHA + + python <<'PY' + import os + import re + from pathlib import Path + + path = Path("pkgs/vscode-insiders/default.nix") + text = path.read_text() + + text = re.sub( + r'version = ".*?";', + f'version = "{os.environ["LATEST"]}";', + text, + count=1 + ) + + text = re.sub( + r'(os=darwin-arm64";\s+sha256 = ").*?(";\s+)', + rf'\g<1>{os.environ["DARWIN_ARM_SHA"]}\2', + text, + count=1, + flags=re.S + ) + + text = re.sub( + r'(os=darwin";\s+sha256 = ").*?(";\s+)', + rf'\g<1>{os.environ["DARWIN_X64_SHA"]}\2', + text, + count=1, + flags=re.S + ) + + text = re.sub( + r'(os=linux-x64";\s+sha256 = ").*?(";\s+)', + rf'\g<1>{os.environ["LINUX_SHA"]}\2', + text, + count=1, + flags=re.S + ) + + path.write_text(text) + PY + + echo "linux_sha=$LINUX_SHA" >> "$GITHUB_OUTPUT" + echo "darwin_arm_sha=$DARWIN_ARM_SHA" >> "$GITHUB_OUTPUT" + echo "darwin_x64_sha=$DARWIN_X64_SHA" >> "$GITHUB_OUTPUT" - name: Verify build if: steps.check.outputs.updated == 'true' + shell: bash run: | - source /etc/bashrc - NIXPKGS_ALLOW_UNFREE=1 nix build .#vscode-insiders + source /etc/bashrc || true + + export NIXPKGS_ALLOW_UNFREE=1 + + nix build .#vscode-insiders - name: Create Pull Request if: steps.check.outputs.updated == 'true' env: API_FORGEJO_TOKEN: ${{ secrets.API_FORGEJO_TOKEN }} + shell: bash run: | - source /etc/bashrc + source /etc/bashrc || true LATEST="${{ steps.check.outputs.latest_version }}" BRANCH="update/vscode-insiders-${LATEST}" @@ -72,16 +138,20 @@ jobs: git config user.email "akiyama@mizuki.guru" git checkout -b "$BRANCH" + git add pkgs/vscode-insiders/default.nix + git commit -m "pkgs/vscode-insiders: update to ${LATEST}" REPO_URL=$(git remote get-url origin | sed 's|https://||') + git push "https://oauth2:${API_FORGEJO_TOKEN}@${REPO_URL}" "$BRANCH" FORGEJO_HOST=$(echo "$REPO_URL" | cut -d'/' -f1) REPO_PATH=$(echo "$REPO_URL" | cut -d'/' -f2-) - - curl -fsSL -X POST \ + + curl -fsSL \ + -X POST \ -H "Authorization: token ${API_FORGEJO_TOKEN}" \ -H "Content-Type: application/json" \ "https://${FORGEJO_HOST}/api/v1/repos/${REPO_PATH}/pulls" \ @@ -89,5 +159,4 @@ jobs: \"title\": \"pkgs/vscode-insiders: update to ${LATEST}\", \"head\": \"${BRANCH}\", \"base\": \"main\", - \"body\": \"Automated update of VSCode Insiders to version \`${LATEST}\`.\n\nNew SRI Hash: \`${{ steps.update.outputs.new_sha256 }}\`\" - }" \ No newline at end of file + \"body\": \"Automated update of VSCode Insiders to version \`${LATEST}\`.\n\nLinux SHA:\n\`${{ steps.update.outputs.linux_sha }}\`\n\nDarwin ARM SHA:\n\`${{ steps.update.outputs.darwin_arm_sha }}\`\n\nDarwin x64 SHA:\n\`${{ steps.update.outputs.darwin_x64_sha }}\`\"}" \ No newline at end of file diff --git a/README.md b/README.md index 4cf4e13..cac98f4 100644 --- a/README.md +++ b/README.md @@ -42,33 +42,3 @@ Add the following to your nix configuration: ``` ## Modules - -### helium-sync - -#### NixOS -```nix -{ - inputs.imnyang.url = "git+https://git.mizuki.guru/imnyang/nix-packages.git"; - outputs = { self, nixpkgs, imnyang }: { - nixosConfigurations.my-host = nixpkgs.lib.nixosSystem { - modules = [ - imnyang.nixosModules.helium-sync - ]; - }; - }; -} -``` - -#### Home Manager -```nix -{ - inputs.imnyang.url = "git+https://git.mizuki.guru/imnyang/nix-packages.git"; - outputs = { self, home-manager, imnyang, ... }: { - homeConfigurations.my-user = home-manager.lib.homeManagerConfiguration { - modules = [ - imnyang.homeManagerModules.helium-sync - ]; - }; - }; -} -``` diff --git a/flake.lock b/flake.lock index 08dc0f4..f6a9c89 100644 --- a/flake.lock +++ b/flake.lock @@ -2,11 +2,11 @@ "nodes": { "nixpkgs": { "locked": { - "lastModified": 1778869304, - "narHash": "sha256-30sZNZoA1cqF5JNO9fVX+wgiQYjB7HJqqJ4ztCDeBZE=", + "lastModified": 1779508470, + "narHash": "sha256-Ap9KJX+5xHIn3bPIpfNgT6MEXdAECECwo4/rmlQD74M=", "owner": "nixos", "repo": "nixpkgs", - "rev": "d233902339c02a9c334e7e593de68855ad26c4cb", + "rev": "29916453413845e54a65b8a1cf996842300cd299", "type": "github" }, "original": { diff --git a/flake.nix b/flake.nix index bb164b2..2b22aa9 100644 --- a/flake.nix +++ b/flake.nix @@ -7,40 +7,45 @@ outputs = { self, nixpkgs }: let - system = "x86_64-linux"; - - # Overlay 정의 + supportedSystems = [ + "x86_64-linux" + "aarch64-darwin" + "x86_64-darwin" + ]; + overlay = final: prev: { waterfox-bin = final.callPackage ./pkgs/waterfox-bin/default.nix { }; xcursor-mizuki = final.callPackage ./pkgs/xcursor-mizuki/default.nix { }; pjsk-cursor = final.callPackage ./pkgs/pjsk-cursor/default.nix { }; helium = final.callPackage ./pkgs/helium/default.nix { }; - helium-sync = final.callPackage ./pkgs/helium-sync/default.nix { }; vscode-insiders = final.callPackage ./pkgs/vscode-insiders/default.nix { }; }; - pkgs = import nixpkgs { - inherit system; - overlays = [ overlay ]; - config.allowUnfree = true; - }; + forAllSystems = f: nixpkgs.lib.genAttrs supportedSystems (system: f ( + import nixpkgs { + inherit system; + overlays = [ overlay ]; + config.allowUnfree = true; + } + )); in { overlays.default = overlay; - nixosModules.helium-sync = import ./modules/helium-sync.nix; - homeManagerModules.helium-sync = import ./modules/helium-sync-hm.nix; - - packages.${system} = { - inherit (pkgs) - waterfox-bin - xcursor-mizuki - pjsk-cursor - helium - helium-sync - vscode-insiders; - - default = pkgs.helium; # 예시로 하나를 기본값으로 지정 - }; + packages = forAllSystems (pkgs: + let + allPkgs = { + inherit (pkgs) + waterfox-bin + xcursor-mizuki + pjsk-cursor + helium + vscode-insiders; + }; + in + nixpkgs.lib.filterAttrs (name: pkg: + nixpkgs.lib.elem pkgs.stdenv.hostPlatform.system (pkg.meta.platforms or [ "x86_64-linux" ]) + ) allPkgs + ); nixConfig = { extra-substituters = [ diff --git a/pkgs/helium-sync/default.nix b/pkgs/helium-sync/default.nix deleted file mode 100644 index db06a38..0000000 --- a/pkgs/helium-sync/default.nix +++ /dev/null @@ -1,27 +0,0 @@ -{ - lib, - buildGoModule, - fetchFromGitHub, -}: -buildGoModule rec { - pname = "helium-sync"; - version = "0.4.0"; - - src = fetchFromGitHub { - owner = "imnyang"; - repo = "helium-sync"; - rev = "v${version}"; - hash = "sha256-ARd2S9c5iFVvSwFTyZjEB2w1l54vvYBXKZTESWpCqvw="; - }; - - vendorHash = "sha256-sWi8QV1uMjfgRMATjXb/qCp6IvBQojtLI3Gr2BHS9Hs="; - - subPackages = [ "cmd/helium-sync" ]; - - meta = { - description = "Synchronize selected Helium browser profile data across devices using Amazon S3"; - homepage = "https://github.com/imnyang/helium-sync"; - license = lib.licenses.mit; - mainProgram = "helium-sync"; - }; -} diff --git a/pkgs/helium/default.nix b/pkgs/helium/default.nix index 1c3a4b5..de254f5 100644 --- a/pkgs/helium/default.nix +++ b/pkgs/helium/default.nix @@ -8,11 +8,11 @@ pkgs.appimageTools.wrapType2 rec { pname = "helium"; - version = "0.12.3.1"; + version = "0.12.4.1"; src = pkgs.fetchurl { url = "https://github.com/imputnet/helium-linux/releases/download/${version}/${pname}-${version}-x86_64.AppImage"; - sha256 = "sha256-VnOhzhAulvFNBB/0AD1d+K/TzfFL9Zwtk/vcm5vWl+I="; + sha256 = "sha256-OgS8HkLBseFrEhNFJxMwp1bg0gzPdfY1VaySAAp7vq0="; }; _enableFeatures = diff --git a/pkgs/vscode-insiders/default.nix b/pkgs/vscode-insiders/default.nix index 4ad87d1..3dd4d81 100644 --- a/pkgs/vscode-insiders/default.nix +++ b/pkgs/vscode-insiders/default.nix @@ -1,22 +1,100 @@ -{ pkgs }: +{ pkgs, lib, fetchurl }: let - src = fetchTarball { - url = "https://code.visualstudio.com/sha/download?build=insider&os=linux-x64"; - sha256 = "09dk54da3kwjnvnr2hvwblcba0big2pb1a3bsvgdfhl0sl24p4i1"; + inherit (pkgs) stdenv; + + sysAttrs = + if stdenv.hostPlatform.isDarwin then + if stdenv.hostPlatform.isAarch64 then { + url = "https://code.visualstudio.com/sha/download?build=insider&os=darwin-arm64-dmg"; + sha256 = "sha256-K+U6JtVNz1PRzL/0SIEK7RXwQu6LL3p+248Ywbn+mDc="; + name = "vscode-insiders-darwin-arm64.dmg"; + } else { + url = "https://code.visualstudio.com/sha/download?build=insider&os=darwin-x64-dmg"; + sha256 = "sha256-ex0ESS9APZxgc7b96Q7EQbckUXE51LmTqDfsnN07W3I="; + name = "vscode-insiders-darwin-x64.dmg"; + } + else { + url = "https://code.visualstudio.com/sha/download?build=insider&os=linux-x64"; + sha256 = "sha256-kE99FyilwwFv3zTCkufGwD3s1WwoJ2krg10l3Xy5PRE="; + name = "vscode-insiders-linux-x64.tar.gz"; + }; + + src = fetchurl { + inherit (sysAttrs) url sha256 name; }; + in + (pkgs.vscode.override { isInsiders = true; }).overrideAttrs (oldAttrs: { pname = "vscode-insiders"; - version = "1.120.0-insider"; - isInsiders = true; + version = "1.122.0-insider"; + inherit src; - buildInputs = oldAttrs.buildInputs ++ [ pkgs.krb5 pkgs.libsoup_3 pkgs.webkitgtk_4_1 ]; + sourceRoot = lib.optionalString stdenv.hostPlatform.isDarwin "."; - meta = oldAttrs.meta // { + postUnpack = lib.optionalString stdenv.hostPlatform.isDarwin '' + export sourceRoot="$(ls -d *.app)" + chmod -R +w "$sourceRoot" + ''; + + nativeBuildInputs = (oldAttrs.nativeBuildInputs or []) + ++ lib.optionals stdenv.hostPlatform.isDarwin [ pkgs.undmg pkgs.darwin.xattr ]; + + buildInputs = + (oldAttrs.buildInputs or []) + ++ lib.optionals stdenv.hostPlatform.isLinux [ + pkgs.krb5 + pkgs.libsoup_3 + pkgs.webkitgtk_4_1 + ]; + + prePatch = if stdenv.hostPlatform.isDarwin then '' + ${oldAttrs.prePatch or ""} + + mkdir -p Contents/Resources/app/node_modules/@vscode/ripgrep/bin + touch Contents/Resources/app/node_modules/@vscode/ripgrep/bin/rg + '' else if stdenv.hostPlatform.isLinux then '' + ${oldAttrs.prePatch or ""} + + mkdir -p resources/app/node_modules/@vscode/ripgrep/bin + touch resources/app/node_modules/@vscode/ripgrep/bin/rg + '' else ""; + + installPhase = lib.optionalString stdenv.hostPlatform.isDarwin '' + mkdir -p $out/Applications + cp -r . $out/Applications/Visual\ Studio\ Code\ -\ Insiders.app + + # Create a wrapper script in bin/ to launch the app + mkdir -p $out/bin + cat > $out/bin/code-insiders << 'EOF' + #!/bin/sh + exec "$out/Applications/Visual Studio Code - Insiders.app/Contents/MacOS/Electron" "$@" + EOF + chmod +x $out/bin/code-insiders + ''; + + preFixup = + if stdenv.hostPlatform.isDarwin then '' + ${oldAttrs.preFixup or ""} + + # Fix executable permissions in the app bundle + chmod +x "Contents/MacOS/Electron" + find Contents -type f -perm +111 -exec chmod +x {} \; + + # Make the app executable for Gatekeeper/notarization checks + xattr -d com.apple.quarantine . 2>/dev/null || true + '' else '' + ${oldAttrs.preFixup or ""} + + rm -rf resources/app/node_modules/@github/copilot-linuxmusl-x64 + ''; + + meta = (oldAttrs.meta or {}) // { mainProgram = "code-insiders"; + }; }) \ No newline at end of file