Skip to content

Commit 244b6d6

Browse files
authored
Merge pull request #78 from infertux/nix-support
Add support for building Bashcov with the Nix package manager
2 parents aa76565 + c910eeb commit 244b6d6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+1467
-40
lines changed

.github/workflows/ci.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,15 @@ jobs:
7676
id: yard
7777
run: |
7878
bundle exec yard stats --list-undoc
79+
nix:
80+
runs-on: ubuntu-latest
81+
# Don't fail the build if this job fails
82+
continue-on-error: true
83+
steps:
84+
- uses: actions/checkout@v3
85+
- uses: cachix/install-nix-action@v22
86+
with:
87+
extra_nix_config: |
88+
system-features = benchmark big-parallel kvm nixos-test uid-range
89+
- name: run flake checks
90+
run: nix flake check -L

.github/workflows/deps.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: Update Nix dependencies
2+
3+
on:
4+
schedule:
5+
# Sunday and Wednesday
6+
- cron: '42 4 * * 0,3'
7+
workflow_dispatch:
8+
9+
jobs:
10+
update-deps-conservative:
11+
runs-on: ubuntu-latest
12+
permissions:
13+
# So that `create-pull-request` can... create a pull request :)
14+
# https://github.com/peter-evans/create-pull-request#action-inputs
15+
contents: write
16+
pull-requests: write
17+
steps:
18+
- uses: actions/checkout@v3
19+
- uses: cachix/install-nix-action@v22
20+
with:
21+
extra_nix_config: |
22+
system-features = benchmark big-parallel kvm nixos-test uid-range
23+
- name: update lockfiles
24+
run: nix run '.#devshell' -- update-deps-conservative
25+
- name: create PR
26+
uses: peter-evans/create-pull-request@v5
27+
with:
28+
branch: create-pull-request/update-nix-deps
29+
title: '[create-pull-request] Update Nix dependencies'
30+
body: |
31+
Update Nix dependencies in `Gemfile.nix.lock` and `gemset.nix`.
32+
33+
Auto-generated by [create-pull-request][1].
34+
35+
[1]: https://github.com/peter-evans/create-pull-request

.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,11 @@ spec/reports
1717
test/tmp
1818
test/version_tmp
1919
tmp
20+
21+
# Nix output links
22+
result
23+
result-*
24+
repl-result-*
25+
26+
# Bundler-installed gems
27+
/vendor/

.rubocop.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,26 @@ require:
55
AllCops:
66
TargetRubyVersion: 3.0
77
NewCops: enable
8+
# Ignore files ignored by Git. Improved version of the template shown here:
9+
# https://docs.rubocop.org/rubocop/configuration.html#pre-processing
10+
# Properly handles symlinks-to-directories, which `git status --ignored
11+
# --porcelain` displays without a trailing slash.
12+
Exclude:
13+
<% git_ignored_file_status = `git status --ignored --porcelain 2>/dev/null` %>
14+
<% if $? == 0 %>
15+
<% git_ignored_file_status.each_line(chomp: true).grep(/^!! /).map { |p| p.sub(/^!! /, '') }.each do |path| %>
16+
<% if File.directory?(path) && ! path.end_with?('/') %>
17+
- <%= path + '/**/*' %>
18+
<% else %>
19+
- <%= path.sub(/\/$/, '/**/*') %>
20+
<% end %>
21+
<% end %>
22+
<% else %>
23+
- 'vendor/**/*'
24+
- 'result/**/*'
25+
- 'result-*/**/*'
26+
- 'repl-result-*/**/*'
27+
<% end %>
828

929
Metrics:
1030
Enabled: false

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
## Unreleased ([changes](https://github.com/infertux/bashcov/compare/v3.1.3...master))
22

3-
* TBD
3+
* [FEATURE] Support building Bashcov with [the Nix package manager](https://nixos.org) (#78)
44

55
## v3.1.3, 2024-08-29 ([changes](https://github.com/infertux/bashcov/compare/v3.1.2...v3.1.3))
66

Gemfile.nix.lock

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
PATH
2+
remote: .
3+
specs:
4+
bashcov (3.1.2)
5+
simplecov (~> 0.22.0)
6+
7+
GEM
8+
remote: https://rubygems.org/
9+
specs:
10+
aruba (2.2.0)
11+
bundler (>= 1.17, < 3.0)
12+
contracts (>= 0.16.0, < 0.18.0)
13+
cucumber (>= 8.0, < 10.0)
14+
rspec-expectations (~> 3.4)
15+
thor (~> 1.0)
16+
ast (2.4.2)
17+
bigdecimal (3.1.7)
18+
builder (3.2.4)
19+
bundler-audit (0.9.1)
20+
bundler (>= 1.2.0, < 3)
21+
thor (~> 1.0)
22+
contracts (0.17)
23+
cucumber (9.2.0)
24+
builder (~> 3.2)
25+
cucumber-ci-environment (> 9, < 11)
26+
cucumber-core (> 13, < 14)
27+
cucumber-cucumber-expressions (~> 17.0)
28+
cucumber-gherkin (> 24, < 28)
29+
cucumber-html-formatter (> 20.3, < 22)
30+
cucumber-messages (> 19, < 25)
31+
diff-lcs (~> 1.5)
32+
mini_mime (~> 1.1)
33+
multi_test (~> 1.1)
34+
sys-uname (~> 1.2)
35+
cucumber-ci-environment (10.0.1)
36+
cucumber-core (13.0.2)
37+
cucumber-gherkin (>= 27, < 28)
38+
cucumber-messages (>= 20, < 23)
39+
cucumber-tag-expressions (> 5, < 7)
40+
cucumber-cucumber-expressions (17.1.0)
41+
bigdecimal
42+
cucumber-gherkin (27.0.0)
43+
cucumber-messages (>= 19.1.4, < 23)
44+
cucumber-html-formatter (21.3.1)
45+
cucumber-messages (> 19, < 25)
46+
cucumber-messages (22.0.0)
47+
cucumber-tag-expressions (6.1.0)
48+
diff-lcs (1.5.1)
49+
docile (1.4.0)
50+
ffi (1.16.3)
51+
json (2.7.2)
52+
language_server-protocol (3.17.0.3)
53+
mini_mime (1.1.5)
54+
multi_test (1.1.0)
55+
parallel (1.24.0)
56+
parser (3.3.0.5)
57+
ast (~> 2.4.1)
58+
racc
59+
racc (1.7.3)
60+
rainbow (3.1.1)
61+
rake (13.2.1)
62+
regexp_parser (2.9.0)
63+
rexml (3.2.6)
64+
rspec (3.13.0)
65+
rspec-core (~> 3.13.0)
66+
rspec-expectations (~> 3.13.0)
67+
rspec-mocks (~> 3.13.0)
68+
rspec-core (3.13.0)
69+
rspec-support (~> 3.13.0)
70+
rspec-expectations (3.13.0)
71+
diff-lcs (>= 1.2.0, < 2.0)
72+
rspec-support (~> 3.13.0)
73+
rspec-mocks (3.13.0)
74+
diff-lcs (>= 1.2.0, < 2.0)
75+
rspec-support (~> 3.13.0)
76+
rspec-support (3.13.1)
77+
rubocop (1.63.2)
78+
json (~> 2.3)
79+
language_server-protocol (>= 3.17.0)
80+
parallel (~> 1.10)
81+
parser (>= 3.3.0.2)
82+
rainbow (>= 2.2.2, < 4.0)
83+
regexp_parser (>= 1.8, < 3.0)
84+
rexml (>= 3.2.5, < 4.0)
85+
rubocop-ast (>= 1.31.1, < 2.0)
86+
ruby-progressbar (~> 1.7)
87+
unicode-display_width (>= 2.4.0, < 3.0)
88+
rubocop-ast (1.31.2)
89+
parser (>= 3.3.0.4)
90+
rubocop-capybara (2.20.0)
91+
rubocop (~> 1.41)
92+
rubocop-factory_bot (2.25.1)
93+
rubocop (~> 1.41)
94+
rubocop-rake (0.6.0)
95+
rubocop (~> 1.0)
96+
rubocop-rspec (2.29.1)
97+
rubocop (~> 1.40)
98+
rubocop-capybara (~> 2.17)
99+
rubocop-factory_bot (~> 2.22)
100+
rubocop-rspec_rails (~> 2.28)
101+
rubocop-rspec_rails (2.28.3)
102+
rubocop (~> 1.40)
103+
ruby-progressbar (1.13.0)
104+
simplecov (0.22.0)
105+
docile (~> 1.1)
106+
simplecov-html (~> 0.11)
107+
simplecov_json_formatter (~> 0.1)
108+
simplecov-html (0.12.3)
109+
simplecov_json_formatter (0.1.4)
110+
sys-uname (1.2.3)
111+
ffi (~> 1.1)
112+
thor (1.3.1)
113+
unicode-display_width (2.5.0)
114+
yard (0.9.36)
115+
116+
PLATFORMS
117+
x86_64-linux
118+
119+
DEPENDENCIES
120+
aruba
121+
bashcov!
122+
bundler-audit
123+
cucumber
124+
rake
125+
rspec
126+
rubocop
127+
rubocop-rake
128+
rubocop-rspec
129+
yard
130+
131+
BUNDLED WITH
132+
2.4.10

HACKING.md

Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
# Hacking on Bashcov
2+
3+
[Nix development shell]: #entering-the-nix-development-shell
4+
[`Gemfile.nix.lock`]: ./Gemfile.nix.lock
5+
[`gemset.nix`]: ./gemset.nix
6+
[`bashcov.gemspec`]: ./bashcov.gemspec
7+
8+
## Nix flake usage
9+
10+
This project supplies a [`flake.nix`](./flake.nix) file defining a Nix
11+
flake[^nix-flakes] that makes it possible to build, test, run, and hack on
12+
Bashcov using the [Nix package manager](https://nixos.org)
13+
14+
[^nix-flakes]: See the [NixOS wiki](https://nixos.wiki/wiki/Flakes) and the
15+
[`nix flake` page in the Nix package manager reference manual](https://nixos.org/manual/nix/unstable/command-ref/new-cli/nix3-flake.html)
16+
for background on Nix flakes.
17+
18+
This Nix flake defines three important important outputs:
19+
20+
1. A [Nix package for Bashcov](#building-the-bashcov-package),
21+
2. A [Nix flake check](#nix-flake-checks) (test) that runs Bashcov's
22+
unit and feature tests,
23+
3. A [Nix application](#running-the-nix-application),[^app] and
24+
4. A [Nix development shell],[^devshell].
25+
26+
[^devshell]: Based on the [`numtide/devshell`](https://github.com/numtide/devshell) project.
27+
[^app]: Runnable with `nix run`.
28+
29+
In order to work on the Bashcov project's Nix features,
30+
you'll need to [install the Nix package manager](https://nixos.org/download.html) and
31+
[ensure that the `flakes` and `nix-command` experimental features are enabled](https://nixos.wiki/wiki/Flakes#Enable_flakes).
32+
33+
### Building the Bashcov package
34+
35+
To build the Bashcov package exposed by this flake, run the
36+
following command:[^verbose-output]
37+
38+
[^verbose-output]: Note that the `-L` flag can be omitted for terser output.
39+
40+
```shell-session
41+
$ nix build -L '.#'
42+
```
43+
44+
Or:
45+
46+
```shell-session
47+
$ nix build -L '.#bashcov'
48+
```
49+
50+
These two forms are functionally equivalent because the
51+
Bashcov package is the default package.
52+
53+
In addition to building the package, `nix build` will place a symbolic link to
54+
its output path at `./result` (`ls -lAR ./result/`, `tree ./result/`, or
55+
similar to see what the package contains).
56+
57+
### Nix flake checks
58+
59+
This project includes a test of Bashcov's functionality and features, exposed
60+
as a Nix flake check. In essence, this runs the Bashcov test suite, but inside
61+
the Nix build environment[^nix-builder-execution] (which may be
62+
sandboxed[^nix-sandbox]).
63+
64+
[^nix-builder-execution]: The Nix build environment is described [here](https://nixos.org/manual/nix/stable/language/derivations#builder-execution).
65+
[^nix-sandbox]: The Nix sandbox is described [here](https://nixos.org/manual/nix/stable/command-ref/conf-file.html#conf-sandbox).
66+
67+
This project also includes a test that Nix source files are properly
68+
formatted.[^treefmt-nix-check]
69+
70+
[^treefmt-nix-check]: Defined by [`treefmt-nix`](https://github.com/numtide/treefmt-nix#flakes).
71+
72+
#### Running Nix flake checks
73+
74+
To run Nix flake checks, execute the following command:[^verbose-output]
75+
76+
```shell-session
77+
$ nix flake check -L
78+
```
79+
80+
If a check fails, `nix` will print a diagnostic message and exit with nonzero
81+
status.
82+
83+
##### Running a check for a specific system
84+
85+
Running `nix flake check` will execute Nix flake checks for all supported
86+
systems.[^supported-systems] To run a check for a particular system, instead
87+
use the `nix build` command. For instance, to execute the Bashcov unit and
88+
feature tests with Nix on the `x86_64-linux` system, run:[^verbose-output]
89+
90+
```shell-session
91+
$ nix build -L '.#checks.x86_64-linux.bashcov'
92+
```
93+
94+
[^supported-systems]: Run `nix flake show` to view flake outputs namespaced by
95+
all supported systems.
96+
97+
### Running the Nix application
98+
99+
To run Bashcov itself:
100+
101+
```shell-session
102+
$ nix run '.#' -- <args>
103+
```
104+
105+
To run commands from [the Nix development shell](#entering-the-nix-development-shell)
106+
but without entering the shell:
107+
108+
```shell-session
109+
$ nix run '.#devshell' -- <command> <args>
110+
```
111+
112+
For instance, to run [the `update-deps` shell command](#summary-of-available-commands):
113+
114+
```shell-session
115+
$ nix run '.#devshell' -- update-deps
116+
```
117+
118+
### Entering the Nix development shell
119+
120+
To enter the Nix development shell, run the following command:
121+
122+
```shell-session
123+
$ nix develop
124+
```
125+
126+
You will be presented with a menu of commands available within the development
127+
shell.
128+
129+
#### Summary of available commands
130+
131+
- `fmt`: format all Nix code in this project using
132+
[`alejandra`](https://github.com/kamadorueda/alejandra).
133+
- `bundix`: tool for managing Nix <=> Ruby integration assets (Bundix lives
134+
[here](https://github.com/nix-community/bundix)).
135+
- `update-deps`: update [the Nix-specific lockfile][`Gemfile.nix.lock`] and
136+
[Nix gemset][`gemset.nix`].
137+
- `update-deps-conservative`: update [the Nix-specific lockfile][`Gemfile.nix.lock`]
138+
and [Nix gemset][`gemset.nix`] if (and only if) `nix build` fails _without_
139+
updates to those assets **and** `nix build` succeeds _with_ updates to them.
140+
141+
### Maintenance of Nix assets
142+
143+
The Bashcov Nix package depends on [`nixpkgs`'s Ruby
144+
integration](https://nixos.org/manual/nixpkgs/stable/#developing-with-ruby);
145+
specifically, it uses the `bundlerEnv` function to create an environment with
146+
all of Bashcov's Ruby gem dependencies present. `bundlerEnv` requires a
147+
Bundler lockfile (here, [`Gemfile.nix.lock`]) and a Nix-specific [`gemset.nix`]
148+
that acts as a sort of translation layer between Bundler and Nix.
149+
150+
Both of these files must be updated from time to time in order to reflect
151+
changes in [`bashcov.gemspec`], including certain changes to Bashcov itself
152+
(e.g. version bumps).
153+
154+
> **Note**
155+
> If [`bashcov.gemspec`] is updated without updating the Bundler lockfile and
156+
> [`gemset.nix`], the Bashcov Nix package will fail to build.
157+
158+
The [Nix development shell] includes two convenience commands for managing
159+
these assets:
160+
161+
- `update-deps` unconditionally updates [`Gemfile.nix.lock`] with
162+
[`bundle lock`](https://bundler.io/v2.4/man/bundle-lock.1.html), then updates
163+
[`gemset.nix`] to reflect any changes to the Bundler lockfile.
164+
- `update-deps-conservative` does the same, but if (and only if) doing so fixes
165+
failures running `nix build`. That is, it updates the assets if it looks
166+
like problems with those assets have broken the Bashcov Nix package.

0 commit comments

Comments
 (0)