Skip to content

Commit 4f3df0d

Browse files
committed
print error when given non-extensible config
that describes the issue (inability to mix in nixos-shell's modules) and links to the README
1 parent 6d7815c commit 4f3df0d

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

bin/nixos-shell

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ if [[ -z "$flake_uri" ]]; then
6565
)
6666
else
6767
extraBuildFlags+=(
68-
--extra-experimental-features "flakes"
68+
--extra-experimental-features "flakes"
69+
--argstr flakeStr "$flake"
6970
--argstr flakeUri "$flake_uri"
7071
--argstr flakeAttr "${flake_attr:-"vm"}"
7172
)

share/nixos-shell.nix

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
, system ? builtins.currentSystem
33
, configuration ? <nixos-config>
44

5+
, flakeStr ? null # flake as named on the command line
56
, flakeUri ? null
67
, flakeAttr ? null
78
}:
@@ -42,8 +43,28 @@ if flakeUri != null then
4243
if flakeSystem != null then
4344
if flakeSystem ? "extendModules" then
4445
flakeSystem.extendModules { modules = nixosShellModules; }
45-
else
46+
else if flakeSystem ? "override" then
4647
flakeSystem.override (attrs: { modules = attrs.modules ++ nixosShellModules; })
48+
else
49+
throw ''
50+
'${flakeStr}#${flakeAttr}' is missing the expected 'override' attribute.
51+
52+
Please ensure that '${flakeStr}#${flakeAttr}' is an overridable attribute set by declaring it with 'lib.makeOverridable'.
53+
54+
For instance:
55+
56+
nixosConfigurations = let
57+
lib = nixpkgs.lib;
58+
in {
59+
"${flakeAttr}" = lib.makeOverridable lib.nixosSystem {
60+
# ...
61+
};
62+
};
63+
64+
Alternatively, upgrade to a version of nixpkgs that provides the 'extendModules' function on NixOS system configurations.
65+
66+
See https://github.com/Mic92/nixos-shell#start-a-virtual-machine for additional information.
67+
''
4768
else if flakeModule != null then
4869
mkShellSystem flakeModule
4970
else

0 commit comments

Comments
 (0)