aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--README.md4
-rw-r--r--pkgs/krops/default.nix5
-rw-r--r--tests/scenarios.nix11
3 files changed, 17 insertions, 3 deletions
diff --git a/README.md b/README.md
index eda8dcd..8f71b59 100644
--- a/README.md
+++ b/README.md
@@ -137,7 +137,9 @@ draws inputs from other sources, its generated flake gets deployed, see
[Flake inputs from sources](#flake-inputs-from-sources). This makes
`nixos-rebuild` use `--flake`, and requires Nix with flake support (Nix 2.4 or
later) on the build target. Without the name of the NixOS configuration,
-`nixos-rebuild` uses the host name of the build target.
+`nixos-rebuild` uses the host name of the build target. Without `flake`,
+`nixos-rebuild` gets `--no-flake` if `/etc/nixos/flake.nix` exists on the
+build target, so it deploys `NIX_PATH` instead of that flake.
### `force` (optional, defaults to false)
diff --git a/pkgs/krops/default.nix b/pkgs/krops/default.nix
index 429fc61..e4f72cd 100644
--- a/pkgs/krops/default.nix
+++ b/pkgs/krops/default.nix
@@ -16,7 +16,10 @@ in
NIX_PATH=${lib.escapeShellArg target.path} \
nixos-rebuild ${lib.escapeShellArgs (args ++ lib.optionals (flake != null) [
"--flake" "${target.path}/${flake}"
- ])}
+ ])} ${lib.optionalString (flake == null)
+ # nixos-rebuild deploys /etc/nixos/flake.nix if it exists. Any
+ # nixos-rebuild doing so supports --no-flake.
+ "$(test -e /etc/nixos/flake.nix && echo --no-flake)"}
'');
runShell = target: {
diff --git a/tests/scenarios.nix b/tests/scenarios.nix
index 429cff8..ce356b0 100644
--- a/tests/scenarios.nix
+++ b/tests/scenarios.nix
@@ -418,6 +418,7 @@ in {
# writeDeploy's arguments to nixos-rebuild, which a stand-in records.
deploy = matrix "deploy" {
flake = [ false true ];
+ etcFlake = [ false true ];
buildTarget = [ false true ];
} (flags: ctx: let
target = targets.${ctx.targetKind} ctx.path;
@@ -429,13 +430,21 @@ in {
"--target-host" "${target.user}@${target.host}"
]
++ optional (flags.buildTarget && target.sudo) "--use-remote-sudo"
- ++ optionals flags.flake [ "--flake" "${build.path}/x" ];
+ ++ optionals flags.flake [ "--flake" "${build.path}/x" ]
+ ++ optional (flags.etcFlake && !flags.flake) "--no-flake";
in
# The local target can't have another build target.
if flags.buildTarget && ctx.targetKind == "local" then null else {
node = if flags.buildTarget then "deployer" else null;
+ # Each scenario creates or removes /etc/nixos/flake.nix.
prepare = ''
rm -f /tmp/nixos-rebuild.log
+ ${if flags.etcFlake then ''
+ mkdir -p /etc/nixos
+ touch /etc/nixos/flake.nix
+ '' else ''
+ rm -f /etc/nixos/flake.nix
+ ''}
'';
phases = twice {
sources.x =