Skip to content

fix: don't require inputs.nixos-wsl when WSL is unused - #703

Merged
sini merged 1 commit into
denful:mainfrom
divyam234:fix/wsl-optional-input
Sep 26, 2026
Merged

sini merged 1 commit into
denful:mainfrom
divyam234:fix/wsl-optional-input

Conversation

@divyam234

Copy link
Copy Markdown
Contributor

Fixes #702.

The host.wsl.module default unconditionally reads inputs.nixos-wsl, so any flake without that input fails evaluation even with WSL disabled everywhere (and even with an explicit host.wsl.module value, since the default itself gets forced during option checking).

This falls back to an empty module when the input is absent. WSL users are unaffected (input present -> same module as before); enabling WSL without the input still errors, just later at the missing wsl.enable option instead of at den evaluation.

Verified against my own flake (no nixos-wsl input): before, nix eval .#nixosConfigurations.laptop... failed with attribute 'nixos-wsl' missing; with this patch it evaluates to the system drv.

@divyam234
divyam234 requested a review from sini as a code owner September 26, 2026 11:21
@sini sini added the allow-ci allow all CI integration tests label Sep 26, 2026
@sini sini changed the title fix(wsl): don't require inputs.nixos-wsl when WSL is unused fix: don't require inputs.nixos-wsl when WSL is unused Sep 26, 2026
@sini
sini merged commit 71dff3a into denful:main Sep 26, 2026
29 of 34 checks passed
sini added a commit that referenced this pull request Nov 6, 2026
A host with `wsl.enable = true` gets a `wsl-host` child scope with the
same scope id as the host. Pipes then go wrong for that host:

- other hosts' `pipe.collectAll` misses its data;
- it sees its own pool twice.

## Reproduction

`templates/ci/modules/deadbugs/wsl-host-scope-id.nix`: two hosts each
publish one `tag` and collect every host's tag. `iceberg` uses the wsl
battery, with a stub in place of NixOS-WSL.

```
expected: { iceberg = ["iceberg","igloo"]; igloo = ["iceberg","igloo"]; }
actual:   { iceberg = ["iceberg","iceberg","igloo","igloo"]; igloo = ["igloo"]; }
```

It fails on main, and on v0.19.0 once #703 is applied (v0.19.0 predates
it). It passes with `wsl.enable = false`.

## Cause

`host-to-wsl-host` resolves the child with only `host` bound:

```nix
(den.lib.policy.resolve.to "wsl-host" { inherit host; })
```

`mkScopeId` builds an id from the context alone, so the child's id is
the host's (`host=iceberg`). `scopeEntityKind` then records that id as
`wsl-host`, so `findMatchingAll` drops it from `({ host, ... }: true)`
matches, and the pipe runs twice under it.

## Fix

The child scope gets a binding of its own, the way
`system-to-flake-parts` does, so its id becomes
`host=iceberg,wsl-host=iceberg`.

Removing the `resolve.to` line also made the reproduction pass, but I
haven't checked what else relies on the `wsl-host` scope. If you'd
rather fix this in `mkScopeId`, for any `resolve.to` that adds no
binding, I can rework it.

## Checked

On NixOS with Nix 2.34.9, against main at 2f1ae4a:

| Check | main | main + fix |
| --- | --- | --- |
| `deadbugs.wsl-host-scope-id` | fails | passes |
| `just ci-deep` | passes | passes |
| `just fmt` | | no changes |
| `just unit` (checkmate) | | passes |

The same test as a bogus `bug.nix` fails on main and on v0.19.0 + #703,
and passes with `wsl.enable = false` or with the fix.

On my own config, which has a NixOS-WSL host, the fix leaves the system
derivation of that host and of a non-WSL host unchanged. I also have an
SSH key roster built on `pipe.collectAll`. Before the fix, the other
hosts missed the WSL host's key and the WSL host got every key twice;
with the fix, every host gets each key once.

AI-assisted: the analysis and the patch were drafted with Claude. I
reproduced and checked everything above on my own machine.

Co-authored-by: Jason Bowman <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

allow-ci allow all CI integration tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

wsl battery forces inputs.nixos-wsl on flakes that don't use WSL

2 participants