Skip to content

Commit be2c940

Browse files
committed
Allow the passing of extra modules
Allows the composing of multiple configurations, primarily so I can have a base VM defined in my system flake, which I can then extend with project specific configurations.
1 parent b333cb6 commit be2c940

2 files changed

Lines changed: 16 additions & 2 deletions

File tree

bin/nixos-shell

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,14 @@ usage() {
1313
[--impure] [--keep-going | -k] [--keep-failed | -K]
1414
[--no-net] [--option name value] [--repair]
1515
[--refresh] [--show-trace] [--verbose | -v | -vv | -vvv | -vvvv | -vvvvv]
16-
[--build-only] [--] [nixos-config]
16+
[--build-only] [--extra-module path] [--] [nixos-config]
1717
[--out-link link]
1818
1919
vm.nix" 1>&2
2020
}
2121

2222
nixos_config=
23+
extra_modules=()
2324
while [[ $# -gt 0 ]]; do
2425
i="$1"; shift 1
2526
case "$i" in
@@ -65,6 +66,10 @@ while [[ $# -gt 0 ]]; do
6566
out_link="$1";
6667
shift 1
6768
;;
69+
--extra-module)
70+
j="$1"; shift 1
71+
extra_modules+=("$(realpath "$j")")
72+
;;
6873
*)
6974
if [[ -n "$nixos_config" ]]; then
7075
usage
@@ -78,17 +83,25 @@ nixos_config=${nixos_config:-vm.nix}
7883

7984
unset NIXOS_CONFIG
8085

86+
extra_modules_list="["
87+
for module in "${extra_modules[@]}"; do
88+
extra_modules_list+=" \"$module\""
89+
done
90+
extra_modules_list+=" ]"
91+
8192
if [[ -z "$flake_uri" ]]; then
8293
extraBuildFlags+=(
8394
--extra-experimental-features "nix-command"
8495
-I "nixos-config=$nixos_config"
96+
--arg extraModules "$extra_modules_list"
8597
)
8698
else
8799
extraBuildFlags+=(
88100
--extra-experimental-features "nix-command flakes"
89101
--argstr flakeStr "$flake"
90102
--argstr flakeUri "$flake_uri"
91103
--argstr flakeAttr "${flake_attr:-"vm"}"
104+
--arg extraModules "$extra_modules_list"
92105
)
93106
fi
94107

share/nixos-shell.nix

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
, flakeStr ? null # flake as named on the command line
66
, flakeUri ? null
77
, flakeAttr ? null
8+
, extraModules ? [ ]
89
}:
910
let
1011
hasFlake = flakeUri != null;
@@ -21,7 +22,7 @@ let
2122
})
2223
./modules/nixos-shell.nix
2324
./modules/nixos-shell-config.nix
24-
];
25+
] ++ extraModules;
2526

2627
nixpkgsPath = if hasFlakeNixpkgs then
2728
flake.inputs.nixpkgs

0 commit comments

Comments
 (0)