Skip to content

Commit 3867348

Browse files
authored
Merge pull request #272 from stuebinm/fix-nonflake-build
fix nix-build invocation in non-flake builds
2 parents 254e9d1 + d3b1122 commit 3867348

File tree

4 files changed

+42
-11
lines changed

4 files changed

+42
-11
lines changed

nix/tests/common.nix

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22
#
33
# SPDX-License-Identifier: MPL-2.0
44

5-
{inputs, pkgs, ...}: {
5+
{inputs, pkgs, flakes, ...}: {
66
nix = {
77
registry.nixpkgs.flake = inputs.nixpkgs;
8+
nixPath = [ "nixpkgs=${inputs.nixpkgs}" ];
89
extraOptions = ''
9-
experimental-features = nix-command flakes
10+
experimental-features = ${if flakes then "nix-command flakes" else "nix-command"}
1011
'';
1112
settings = {
1213
trusted-users = [ "root" "@wheel" ];

nix/tests/default.nix

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ let
2020
done <$refs
2121
'';
2222

23-
mkTest = { name ? "", user ? "root", isLocal ? true, deployArgs }: let
23+
mkTest = { name ? "", user ? "root", flakes ? true, isLocal ? true, deployArgs }: let
2424
nodes = {
2525
server = { nodes, ... }: {
2626
imports = [
2727
./server.nix
28-
(import ./common.nix { inherit inputs pkgs; })
28+
(import ./common.nix { inherit inputs pkgs flakes; })
2929
];
3030
virtualisation.additionalPaths = lib.optionals (!isLocal) [
3131
pkgs.hello
@@ -35,8 +35,10 @@ let
3535
];
3636
};
3737
client = { nodes, ... }: {
38-
imports = [ (import ./common.nix { inherit inputs pkgs; }) ];
38+
imports = [ (import ./common.nix { inherit inputs pkgs flakes; }) ];
3939
environment.systemPackages = [ pkgs.deploy-rs.deploy-rs ];
40+
# nix evaluation takes a lot of memory, especially in non-flake usage
41+
virtualisation.memorySize = lib.mkForce 4096;
4042
virtualisation.additionalPaths = lib.optionals isLocal [
4143
pkgs.hello
4244
pkgs.figlet
@@ -56,11 +58,29 @@ let
5658
systems.url = "${inputs.utils.inputs.systems}";
5759
flake-compat.url = "${inputs.flake-compat}";
5860
flake-compat.flake = false;
61+
62+
enable-flakes.url = "${builtins.toFile "use-flakes" (if flakes then "true" else "false")}";
63+
enable-flakes.flake = false;
5964
'';
6065

6166
flake = builtins.toFile "flake.nix"
6267
(lib.replaceStrings [ "##inputs##" ] [ flakeInputs ] (builtins.readFile ./deploy-flake.nix));
6368

69+
flakeCompat = builtins.toFile "default.nix" ''
70+
(import
71+
(
72+
let
73+
lock = builtins.fromJSON (builtins.readFile ./flake.lock);
74+
in
75+
fetchTarball {
76+
url = "https://not-used-we-fetch-by-hash";
77+
sha256 = lock.nodes.flake-compat.locked.narHash;
78+
}
79+
)
80+
{ src = ./.; }
81+
).defaultNix
82+
'';
83+
6484
in pkgs.nixosTest {
6585
inherit nodes name;
6686

@@ -73,11 +93,11 @@ let
7393
# Prepare
7494
client.succeed("mkdir tmp && cd tmp")
7595
client.succeed("cp ${flake} ./flake.nix")
96+
client.succeed("cp ${flakeCompat} ./default.nix")
7697
client.succeed("cp ${./server.nix} ./server.nix")
7798
client.succeed("cp ${./common.nix} ./common.nix")
7899
client.succeed("cp ${serverNetworkJSON} ./network.json")
79-
client.succeed("nix flake lock")
80-
100+
client.succeed("nix --extra-experimental-features flakes flake lock")
81101
82102
# Setup SSH key
83103
client.succeed("mkdir -m 700 /root/.ssh")
@@ -136,4 +156,10 @@ in {
136156
user = "deploy";
137157
deployArgs = "-s .#profile --ssh-opts '-p 22 -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null' -- --offline";
138158
};
159+
# Deployment using a non-flake nix
160+
non-flake-build = mkTest {
161+
name = "local-build";
162+
flakes = false;
163+
deployArgs = "-s .#server";
164+
};
139165
}

nix/tests/deploy-flake.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
in {
1616
nixosConfigurations.server = nixpkgs.lib.nixosSystem {
1717
inherit system pkgs;
18-
specialArgs = { inherit inputs; };
18+
specialArgs = { inherit inputs; flakes = import inputs.enable-flakes; };
1919
modules = [
2020
./server.nix
2121
./common.nix

src/push.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -244,9 +244,13 @@ pub async fn build_profile(data: PushProfileData<'_>) -> Result<(), PushProfileE
244244
.next()
245245
.ok_or(PushProfileError::ShowDerivationEmpty)?;
246246

247-
// Since nix 2.15.0 'nix build <path>.drv' will build only the .drv file itself, not the
248-
// derivation outputs, '^out' is used to refer to outputs explicitly
249-
let new_deriver = &(deriver.to_owned().to_string() + "^out");
247+
let new_deriver = &if data.supports_flakes {
248+
// Since nix 2.15.0 'nix build <path>.drv' will build only the .drv file itself, not the
249+
// derivation outputs, '^out' is used to refer to outputs explicitly
250+
deriver.to_owned().to_string() + "^out"
251+
} else {
252+
deriver.to_owned()
253+
};
250254

251255
let path_info_output = Command::new("nix")
252256
.arg("--experimental-features").arg("nix-command")

0 commit comments

Comments
 (0)