Skip to content

Commit 6d7815c

Browse files
committed
use extendModules to add nixos-shell modules
if `extendModules` is available on the supplied NixOS configuration, in preference to using `override`. This permits callers to omit `makeOverridable` when using a recent-enough nixpkgs.
1 parent 55de7d4 commit 6d7815c

File tree

2 files changed

+16
-13
lines changed

2 files changed

+16
-13
lines changed

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,11 @@ $ nixos-shell --flake github:Mic92/nixos-shell#vm-forward
3939

4040
This will run the `vm-forward` example.
4141

42-
> Note: system configurations have to be made overridable with `lib.makeOverridable` to use them with `nixos-shell`
42+
> Note: `nixos-shell` must be able to extend the specified system configuration with [certain modules](share/modules).
43+
>
44+
> If your version of `nixpkgs` provides the `extendModules` function on system configurations, `nixos-shell` will use it to inject the required modules; no additional work on your part is needed.
45+
>
46+
> If your version of `nixpkgs` **does not** provide `extendModules`, you must make your system configurations overridable with `lib.makeOverridable` to use them with `nixos-shell`:
4347
>```nix
4448
>{
4549
> nixosConfigurations = let
@@ -51,6 +55,7 @@ This will run the `vm-forward` example.
5155
> };
5256
>}
5357
>```
58+
> Specifying a non-overridable system configuration will cause `nixos-shell` to abort with a non-zero exit status.
5459
5560
When using the `--flake` flag, if no attribute is given, `nixos-shell` tries the following flake output attributes:
5661
- `packages.<system>.nixosConfigurations.<vm>`

share/nixos-shell.nix

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,21 +31,19 @@ let
3131
(getFlakeOutput [ "packages" "${system}" "nixosConfigurations" "${flakeAttr}" ]);
3232

3333
flakeModule = getFlakeOutput [ "nixosModules" "${flakeAttr}" ];
34+
35+
nixosShellModules =
36+
if flakeSystem ? options.nixos-shell then
37+
[ nixos-shell-config ]
38+
else
39+
[ nixos-shell nixos-shell-config ];
3440
in
3541
if flakeUri != null then
3642
if flakeSystem != null then
37-
flakeSystem.override
38-
(attrs: {
39-
modules =
40-
let
41-
nixosShellModules =
42-
if flakeSystem ? options.nixos-shell then
43-
[ nixos-shell-config ]
44-
else
45-
[ nixos-shell nixos-shell-config ];
46-
in
47-
attrs.modules ++ nixosShellModules;
48-
})
43+
if flakeSystem ? "extendModules" then
44+
flakeSystem.extendModules { modules = nixosShellModules; }
45+
else
46+
flakeSystem.override (attrs: { modules = attrs.modules ++ nixosShellModules; })
4947
else if flakeModule != null then
5048
mkShellSystem flakeModule
5149
else

0 commit comments

Comments
 (0)