Skip to content

Commit d6b582d

Browse files
committed
allow remote builds with non-flake nix
This does two things: - lift the restriction on remote builds with legacy nix; the logic remains the same and we use `nix --experimental-features nix-command' to call Nix - change the logic on build drivers: if we do a remote build, use the nix-command setup even if we're not using a flake-enabled nix (this still assumes the remote host has a nix version > 2.4)
1 parent 6c12d84 commit d6b582d

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

nix/tests/default.nix

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,12 @@ in {
134134
isLocal = false;
135135
deployArgs = "-s .#server --remote-build -- --offline";
136136
};
137+
non-flake-remote-build = mkTest {
138+
name = "non-flake-remote-build";
139+
isLocal = false;
140+
flakes = false;
141+
deployArgs = "-s .#server --remote-build";
142+
};
137143
# Deployment with overridden options
138144
options-overriding = mkTest {
139145
name = "options-overriding";

src/push.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// SPDX-License-Identifier: MPL-2.0
44

5-
use log::{debug, info};
5+
use log::{debug, info, warn};
66
use std::collections::HashMap;
77
use std::path::Path;
88
use std::process::Stdio;
@@ -41,8 +41,6 @@ pub enum PushProfileError {
4141
Copy(std::io::Error),
4242
#[error("Nix copy command resulted in a bad exit code: {0:?}")]
4343
CopyExit(Option<i32>),
44-
#[error("The remote building option is not supported when using legacy nix")]
45-
RemoteBuildWithLegacyNix,
4644

4745
#[error("Failed to run Nix path-info command: {0}")]
4846
PathInfo(std::io::Error),
@@ -169,7 +167,9 @@ pub async fn build_profile_remotely(data: &PushProfileData<'_>, derivation_name:
169167

170168

171169
// copy the derivation to remote host so it can be built there
172-
let copy_command_status = Command::new("nix").arg("copy")
170+
let copy_command_status = Command::new("nix")
171+
.arg("--experimental-features").arg("nix-command")
172+
.arg("copy")
173173
.arg("-s") // fetch dependencies from substitures, not localhost
174174
.arg("--to").arg(&store_address)
175175
.arg("--derivation").arg(derivation_name)
@@ -186,6 +186,7 @@ pub async fn build_profile_remotely(data: &PushProfileData<'_>, derivation_name:
186186

187187
let mut build_command = Command::new("nix");
188188
build_command
189+
.arg("--experimental-features").arg("nix-command")
189190
.arg("build").arg(derivation_name)
190191
.arg("--eval-store").arg("auto")
191192
.arg("--store").arg(&store_address)
@@ -244,7 +245,7 @@ pub async fn build_profile(data: PushProfileData<'_>) -> Result<(), PushProfileE
244245
.next()
245246
.ok_or(PushProfileError::ShowDerivationEmpty)?;
246247

247-
let new_deriver = &if data.supports_flakes {
248+
let new_deriver = &if data.supports_flakes || data.deploy_data.merged_settings.remote_build.unwrap_or(false) {
248249
// Since nix 2.15.0 'nix build <path>.drv' will build only the .drv file itself, not the
249250
// derivation outputs, '^out' is used to refer to outputs explicitly
250251
deriver.to_owned().to_string() + "^out"
@@ -276,7 +277,7 @@ pub async fn build_profile(data: PushProfileData<'_>) -> Result<(), PushProfileE
276277
};
277278
if data.deploy_data.merged_settings.remote_build.unwrap_or(false) {
278279
if !data.supports_flakes {
279-
return Err(PushProfileError::RemoteBuildWithLegacyNix)
280+
warn!("remote builds using non-flake nix are experimental");
280281
}
281282

282283
build_profile_remotely(&data, &deriver).await?;

0 commit comments

Comments
 (0)