Skip to content

Commit

Permalink
Merge pull request #105 from kachick/dev-with-nix
Browse files Browse the repository at this point in the history
Pin bash and asdf-vm versions via Nix for stable development
  • Loading branch information
kachick authored Mar 23, 2024
2 parents cf466a7 + 7c7de29 commit 8064ff4
Show file tree
Hide file tree
Showing 12 changed files with 153 additions and 17 deletions.
3 changes: 3 additions & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash

use flake
10 changes: 8 additions & 2 deletions .github/renovate.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"github>kachick/renovate-config-dprint"
],
"labels": ["dependencies", "renovate"],
"enabledManagers": ["asdf", "regex"],
"enabledManagers": ["asdf", "regex", "nix"],
"prHourlyLimit": 10,
"prConcurrentLimit": 5,
"packageRules": [
Expand All @@ -15,5 +15,11 @@
],
"rangeStrategy": "bump"
}
]
],
"nix": {
"enabled": true
},
"lockFileMaintenance": {
"enabled": true
}
}
15 changes: 9 additions & 6 deletions .github/workflows/ci-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,13 @@ jobs:
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- uses: asdf-vm/actions/setup@v3
- run: 'asdf plugin-add yamlfmt .'
- uses: asdf-vm/actions/install@v3
- uses: DeterminateSystems/nix-installer-action@v10
- run: nix develop --command echo 'This step should be done before any other "nix develop" steps because of measuring Nix build time'
- run: |
makers help
makers setup
makers check
nix develop --command bash -c '
asdf plugin-add cargo-make https://github.com/kachick/asdf-cargo-make.git
asdf install cargo-make
makers help
makers setup
makers check
'
1 change: 1 addition & 0 deletions .github/workflows/dependency-review.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ jobs:
with:
# https://spdx.org/licenses/
allow-licenses: MIT, BSD-3-Clause, BSD-2-Clause, 0BSD, Unlicense, ISC, Apache-2.0
allow-dependencies-licenses: pkg:githubactions/DeterminateSystems/nix-installer-action
22 changes: 16 additions & 6 deletions .github/workflows/merge-bot-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,36 @@ permissions:
# actions: read # For private repositories

jobs:
dependabot:
judge-dependabot:
timeout-minutes: 5
runs-on: ubuntu-latest
outputs:
merge: ${{ steps.conclusion.outputs.merge }}
if: ${{ github.actor == 'dependabot[bot]' }}
steps:
- name: Dependabot metadata
id: metadata
id: dependabot
uses: dependabot/fetch-metadata@v2.0.0
with:
github-token: '${{ secrets.GITHUB_TOKEN }}'
- name: Judge
id: conclusion
if: >-
steps.dependabot.outputs.update-type != 'version-update:semver-major' || contains(steps.dependabot.outputs.dependency-names, 'DeterminateSystems')
run: echo -n 'merge=true' | tee -a "$GITHUB_OUTPUT"
dependabot:
needs: [judge-dependabot]
if: ${{ needs.judge-dependabot.outputs.merge == 'true' }}
timeout-minutes: 30
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Wait other jobs
if: ${{steps.metadata.outputs.update-type != 'version-update:semver-major'}}
uses: kachick/wait-other-jobs@v2
timeout-minutes: 30
with:
github-token: '${{ secrets.GITHUB_TOKEN }}'
retry-method: 'equal_intervals'
min-interval-seconds: '15'
- name: Approve and merge
if: ${{steps.metadata.outputs.update-type != 'version-update:semver-major'}}
run: gh pr review --approve "$PR_URL" && gh pr merge --auto --squash "$PR_URL"
env:
PR_URL: ${{github.event.pull_request.html_url}}
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.direnv
4 changes: 4 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Contributing

Maintaining this repository assumes that you are not using old versions of bash such as 3.x, which is included in MacOS\
I recommend using the [Nix package manager](https://nixos.org/) to prepare base environments.\
This repository contains the [flake.nix](flake.nix).

After installing asdf, running below command in this repo finishes setups.

```console
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Tested also [mise](https://github.com/jdx/mise).

## Dependencies

- `asdf-vm` or `mise`
- `bash`, `curl`, `tar`: generic POSIX utilities.

## Install
Expand Down
61 changes: 61 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 40 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
inputs = {
# Candidate channels
# - https://github.com/kachick/anylang-template/issues/17
# - https://discourse.nixos.org/t/differences-between-nix-channels/13998
# How to update the revision
# - `nix flake update --commit-lock-file` # https://nixos.org/manual/nix/stable/command-ref/new-cli/nix3-flake-update.html
nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.11";
flake-utils.url = "github:numtide/flake-utils";
};

outputs = { self, nixpkgs, flake-utils }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = nixpkgs.legacyPackages.${system};
in
{
formatter = pkgs.nixpkgs-fmt;
devShells.default = with pkgs;
mkShell {
buildInputs = [
# - Use newest bash to avoid darwin old bash problems. For example #139
# - Avoid https://github.com/NixOS/nix/issues/730#issuecomment-162323824
bashInteractive

# Keep minimum tools in nix layer, this repository should depend them with the asdf or mise itself(.tool-versions)
# So written here should be also clarified in [depedndencies](README.md#Dependencies)
curl
asdf-vm
# Also do not specify mise to avoid conflict with asdf
# mise
];

shellHook = ''
. "${pkgs.asdf-vm}/share/asdf-vm/asdf.sh"
'';
};
}
);
}
7 changes: 5 additions & 2 deletions scripts/format.bash
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@

set -euxo pipefail

# This option don't work in old bash as 3.x that installed in macOS
shopt -s globstar

shfmt --language-dialect bash --write \
./**/*
./**/*.bash bin/**/*

dprint fmt

yamlfmt
yamlfmt -gitignore_excludes
5 changes: 4 additions & 1 deletion scripts/lint.bash
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@

set -euxo pipefail

# This option don't work in old bash as 3.x that installed in macOS
shopt -s globstar

shellcheck --shell=bash --external-sources \
bin/* --source-path=lib/ \
lib/* \
scripts/*

shfmt --language-dialect bash --diff \
./**/*
./**/*.bash bin/**/*

dprint check

Expand Down

0 comments on commit 8064ff4

Please sign in to comment.