Skip to content

Make nix and direnv optional#452

Open
fwiesel wants to merge 2 commits intomainfrom
optional-nix-and-direnv
Open

Make nix and direnv optional#452
fwiesel wants to merge 2 commits intomainfrom
optional-nix-and-direnv

Conversation

@fwiesel
Copy link
Member

@fwiesel fwiesel commented Feb 25, 2026

Nix doesn't add much overhead, but writing the .envrc to activate
nix-shell complicates the use of direnv for other uses. Make both
configurable, but keep the existing default mostly out of consistency
reasons.

@fwiesel fwiesel requested a review from a team as a code owner February 25, 2026 14:49
@fwiesel fwiesel force-pushed the optional-nix-and-direnv branch from c481910 to b6c7631 Compare February 25, 2026 14:50
Copy link
Contributor

@majewsky majewsky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two small nitpicks below. To clarify regarding the intent, what does "break other people's workflows" mean? The .envrc is written in a way where it should not cause problems for people who do not have Nix installed. Do you mean that the problem is that go-m-m generating an .envrc file overwrites an existing custom one?

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds configuration switches to make Nix shell generation and direnv integration optional, addressing workflow concerns while preserving the existing default behavior.

Changes:

  • Extend nix configuration with enabled and writeEnvRc toggles.
  • Update Nix shell rendering to skip generating shell.nix and/or .envrc based on config.
  • Add tests covering the new configuration combinations and update README docs.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
internal/nix/nix-shell.go Respect nix.enabled and nix.writeEnvRc when generating shell.nix / .envrc.
internal/nix/nix-shell_test.go New test suite covering enable/disable behavior and package/variable inclusion.
internal/core/config.go Add Enabled and WriteEnvRc fields to NixConfig with YAML tags.
README.md Document the new nix.enabled and nix.writeEnvRc settings.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

func assertFileExists(t *testing.T, path string, shouldExist bool) {
t.Helper()
_, err := os.Stat(path)
exists := !os.IsNotExist(err)
Copy link

Copilot AI Feb 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

assertFileExists treats any os.Stat error other than IsNotExist as “file exists”. That can mask real failures (e.g., permission/IO errors) and make the test pass incorrectly. Consider failing the test on unexpected errors (or at least treating them as non-existent) instead of assuming the file exists.

Suggested change
exists := !os.IsNotExist(err)
var exists bool
if err == nil {
exists = true
} else if os.IsNotExist(err) {
exists = false
} else {
t.Fatalf("Failed to stat %s: %v", path, err)
}

Copilot uses AI. Check for mistakes.
@fwiesel
Copy link
Member Author

fwiesel commented Feb 26, 2026

Do you mean that the problem is that go-m-m generating an .envrc file overwrites an existing custom one?

Well, both overwriting it and having it checked in makes it difficult to use the .envrc for anything else than the prescribed way of activating a nix-shell (in that specific manner) rather cumbersome. That is fine for projects opting into it, but I think it should be a choice.

fwiesel and others added 2 commits February 26, 2026 17:45
Nix doesn't add much overhead, but writing the .envrc to activate
nix-shell complicates the use of direnv for other uses. Make both
configurable, but keep the existing default mostly out of consistency
reasons.

Update internal/nix/nix-shell_test.go

Co-authored-by: Stefan Majewsky <stefan.majewsky@sap.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@fwiesel fwiesel force-pushed the optional-nix-and-direnv branch from 55c535d to 2afbdf3 Compare February 26, 2026 16:46
@github-actions
Copy link
Contributor

Merging this branch will increase overall coverage

Impacted Packages Coverage Δ 🤖
github.com/sapcc/go-makefile-maker/internal/core 3.03% (+3.03%) 👍
github.com/sapcc/go-makefile-maker/internal/nix 92.31% (+92.31%) 🌟

Coverage by file

Changed files (no unit tests)

Changed File Coverage Δ Total Covered Missed 🤖
github.com/sapcc/go-makefile-maker/internal/core/config.go 3.70% (+3.70%) 108 (+54) 4 (+4) 104 (+50) 👍
github.com/sapcc/go-makefile-maker/internal/nix/nix-shell.go 92.31% (+92.31%) 52 (+52) 48 (+48) 4 (+4) 🌟

Please note that the "Total", "Covered", and "Missed" counts above refer to code statements instead of lines of code. The value in brackets refers to the test coverage of that file in the old version of the code.

Changed unit test files

  • github.com/sapcc/go-makefile-maker/internal/nix/nix-shell_test.go

@fwiesel
Copy link
Member Author

fwiesel commented Feb 26, 2026

I've updated the commit message.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants