Skip to content

Improve NixOS support #1211

@misumisumi

Description

@misumisumi

Feature description

I'm glad to have contributed to the support for NixOS last time.
Since then, we have been able to operate it stably for several months.
However, previous support did not provide an option to place lazy-lock.json under .config/nvim.
This is because NixOS places it as read-only, which means it cannot be updated with :Lazy.
Fortunately, we were able to create a workflow that updates lazy-lock.json by following upstream in a forked repository based on update_lockfile.yml, so the above problem will be alleviated.
I provide bind support in terms of the NixOS ethos of strongly anchoring the environment.

Also, last time it was provided as nixosModules, but since it actually only works with home-manager, we changed it to homeManagerModules. (breaking change)
This is because I didn't know about the existence of homeManagerModules last time.

Additional information

  • example merge upstream and update lazy-lock workflow
    In the example, I create a PR instead of just pushing it to main
name: auto merge upstream
on:
  workflow_dispatch: # allows manual triggering
  schedule:
    - cron: "0 19 * * 5" # runs weekly on Saturday at 04:00 (JST)

permissions:
  contents: write
  pull-requests: write
jobs:
  auto-merge-upstream:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0

      - uses: andstor/file-existence-action@v3
        id: check_lockfile
        with:
          files: "lazy-lock.json"

      - name: Merge upstream
        id: merge-upstream
        continue-on-error: true
        run: |
          git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
          git config --global user.name "github-actions[bot]"

          git remote add upstream https://github.com/ayamir/nvimdots.git
          git fetch upstream
          git merge upstream/main --allow-unrelated-histories --no-commit --no-ff

          git reset HEAD lazy-lock.json
          git reset HEAD .github/workflows/update_lockfile.yml

          git checkout lazy-lock.json
          git checkout .github/workflows/update_lockfile.yml

      - name: Run count-new-commits
        run: |
          echo "NEW_COMMIT_COUNT=$(git log --oneline --since '24 hours ago' --perl-regexp --author='^((?!github-actions).*)$' | wc -l)" >> "$GITHUB_ENV"

      - uses: rhysd/action-setup-vim@v1
        if: ${{ steps.check_lockfile.outputs.files_exists == 'true' && env.NEW_COMMIT_COUNT > 0 }}
        with:
          neovim: true

      - name: Run lockfile-autoupdate
        if: ${{ steps.check_lockfile.outputs.files_exists == 'true' && env.NEW_COMMIT_COUNT > 0 }}
        timeout-minutes: 5
        run: |
          ./scripts/install.sh
          nvim --headless "+Lazy! update" +qa
          cp -pv "${HOME}/.config/nvim/lazy-lock.json" .

      - uses: peter-evans/create-pull-request@v6
        if: >-
          ${{
            (
              steps.check_lockfile.outputs.files_exists == 'true' &&
              env.NEW_COMMIT_COUNT > 0
            ) ||
            steps.merge-upstream.outcome == 'success'
          }}
        with:
          token: ${{ github.token }}
          commit-message: "chore: auto merge upstream and update lazy-lock.json"
          title: "chore: auto merge upstream and update lazy-lock.json"
          branch: "merge_upstream_and_update_lazy_lock_action"
          labels: |
            dependencies
            automated

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions