mirror of
https://github.com/serokell/deploy-rs.git
synced 2024-10-05 14:28:11 +03:00
Merge pull request #272 from stuebinm/fix-nonflake-build
fix nix-build invocation in non-flake builds
This commit is contained in:
commit
3867348fa9
@ -2,11 +2,12 @@
|
|||||||
#
|
#
|
||||||
# SPDX-License-Identifier: MPL-2.0
|
# SPDX-License-Identifier: MPL-2.0
|
||||||
|
|
||||||
{inputs, pkgs, ...}: {
|
{inputs, pkgs, flakes, ...}: {
|
||||||
nix = {
|
nix = {
|
||||||
registry.nixpkgs.flake = inputs.nixpkgs;
|
registry.nixpkgs.flake = inputs.nixpkgs;
|
||||||
|
nixPath = [ "nixpkgs=${inputs.nixpkgs}" ];
|
||||||
extraOptions = ''
|
extraOptions = ''
|
||||||
experimental-features = nix-command flakes
|
experimental-features = ${if flakes then "nix-command flakes" else "nix-command"}
|
||||||
'';
|
'';
|
||||||
settings = {
|
settings = {
|
||||||
trusted-users = [ "root" "@wheel" ];
|
trusted-users = [ "root" "@wheel" ];
|
||||||
|
@ -20,12 +20,12 @@ let
|
|||||||
done <$refs
|
done <$refs
|
||||||
'';
|
'';
|
||||||
|
|
||||||
mkTest = { name ? "", user ? "root", isLocal ? true, deployArgs }: let
|
mkTest = { name ? "", user ? "root", flakes ? true, isLocal ? true, deployArgs }: let
|
||||||
nodes = {
|
nodes = {
|
||||||
server = { nodes, ... }: {
|
server = { nodes, ... }: {
|
||||||
imports = [
|
imports = [
|
||||||
./server.nix
|
./server.nix
|
||||||
(import ./common.nix { inherit inputs pkgs; })
|
(import ./common.nix { inherit inputs pkgs flakes; })
|
||||||
];
|
];
|
||||||
virtualisation.additionalPaths = lib.optionals (!isLocal) [
|
virtualisation.additionalPaths = lib.optionals (!isLocal) [
|
||||||
pkgs.hello
|
pkgs.hello
|
||||||
@ -35,8 +35,10 @@ let
|
|||||||
];
|
];
|
||||||
};
|
};
|
||||||
client = { nodes, ... }: {
|
client = { nodes, ... }: {
|
||||||
imports = [ (import ./common.nix { inherit inputs pkgs; }) ];
|
imports = [ (import ./common.nix { inherit inputs pkgs flakes; }) ];
|
||||||
environment.systemPackages = [ pkgs.deploy-rs.deploy-rs ];
|
environment.systemPackages = [ pkgs.deploy-rs.deploy-rs ];
|
||||||
|
# nix evaluation takes a lot of memory, especially in non-flake usage
|
||||||
|
virtualisation.memorySize = lib.mkForce 4096;
|
||||||
virtualisation.additionalPaths = lib.optionals isLocal [
|
virtualisation.additionalPaths = lib.optionals isLocal [
|
||||||
pkgs.hello
|
pkgs.hello
|
||||||
pkgs.figlet
|
pkgs.figlet
|
||||||
@ -56,11 +58,29 @@ let
|
|||||||
systems.url = "${inputs.utils.inputs.systems}";
|
systems.url = "${inputs.utils.inputs.systems}";
|
||||||
flake-compat.url = "${inputs.flake-compat}";
|
flake-compat.url = "${inputs.flake-compat}";
|
||||||
flake-compat.flake = false;
|
flake-compat.flake = false;
|
||||||
|
|
||||||
|
enable-flakes.url = "${builtins.toFile "use-flakes" (if flakes then "true" else "false")}";
|
||||||
|
enable-flakes.flake = false;
|
||||||
'';
|
'';
|
||||||
|
|
||||||
flake = builtins.toFile "flake.nix"
|
flake = builtins.toFile "flake.nix"
|
||||||
(lib.replaceStrings [ "##inputs##" ] [ flakeInputs ] (builtins.readFile ./deploy-flake.nix));
|
(lib.replaceStrings [ "##inputs##" ] [ flakeInputs ] (builtins.readFile ./deploy-flake.nix));
|
||||||
|
|
||||||
|
flakeCompat = builtins.toFile "default.nix" ''
|
||||||
|
(import
|
||||||
|
(
|
||||||
|
let
|
||||||
|
lock = builtins.fromJSON (builtins.readFile ./flake.lock);
|
||||||
|
in
|
||||||
|
fetchTarball {
|
||||||
|
url = "https://not-used-we-fetch-by-hash";
|
||||||
|
sha256 = lock.nodes.flake-compat.locked.narHash;
|
||||||
|
}
|
||||||
|
)
|
||||||
|
{ src = ./.; }
|
||||||
|
).defaultNix
|
||||||
|
'';
|
||||||
|
|
||||||
in pkgs.nixosTest {
|
in pkgs.nixosTest {
|
||||||
inherit nodes name;
|
inherit nodes name;
|
||||||
|
|
||||||
@ -73,11 +93,11 @@ let
|
|||||||
# Prepare
|
# Prepare
|
||||||
client.succeed("mkdir tmp && cd tmp")
|
client.succeed("mkdir tmp && cd tmp")
|
||||||
client.succeed("cp ${flake} ./flake.nix")
|
client.succeed("cp ${flake} ./flake.nix")
|
||||||
|
client.succeed("cp ${flakeCompat} ./default.nix")
|
||||||
client.succeed("cp ${./server.nix} ./server.nix")
|
client.succeed("cp ${./server.nix} ./server.nix")
|
||||||
client.succeed("cp ${./common.nix} ./common.nix")
|
client.succeed("cp ${./common.nix} ./common.nix")
|
||||||
client.succeed("cp ${serverNetworkJSON} ./network.json")
|
client.succeed("cp ${serverNetworkJSON} ./network.json")
|
||||||
client.succeed("nix flake lock")
|
client.succeed("nix --extra-experimental-features flakes flake lock")
|
||||||
|
|
||||||
|
|
||||||
# Setup SSH key
|
# Setup SSH key
|
||||||
client.succeed("mkdir -m 700 /root/.ssh")
|
client.succeed("mkdir -m 700 /root/.ssh")
|
||||||
@ -136,4 +156,10 @@ in {
|
|||||||
user = "deploy";
|
user = "deploy";
|
||||||
deployArgs = "-s .#profile --ssh-opts '-p 22 -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null' -- --offline";
|
deployArgs = "-s .#profile --ssh-opts '-p 22 -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null' -- --offline";
|
||||||
};
|
};
|
||||||
|
# Deployment using a non-flake nix
|
||||||
|
non-flake-build = mkTest {
|
||||||
|
name = "local-build";
|
||||||
|
flakes = false;
|
||||||
|
deployArgs = "-s .#server";
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
in {
|
in {
|
||||||
nixosConfigurations.server = nixpkgs.lib.nixosSystem {
|
nixosConfigurations.server = nixpkgs.lib.nixosSystem {
|
||||||
inherit system pkgs;
|
inherit system pkgs;
|
||||||
specialArgs = { inherit inputs; };
|
specialArgs = { inherit inputs; flakes = import inputs.enable-flakes; };
|
||||||
modules = [
|
modules = [
|
||||||
./server.nix
|
./server.nix
|
||||||
./common.nix
|
./common.nix
|
||||||
|
10
src/push.rs
10
src/push.rs
@ -244,9 +244,13 @@ pub async fn build_profile(data: PushProfileData<'_>) -> Result<(), PushProfileE
|
|||||||
.next()
|
.next()
|
||||||
.ok_or(PushProfileError::ShowDerivationEmpty)?;
|
.ok_or(PushProfileError::ShowDerivationEmpty)?;
|
||||||
|
|
||||||
// Since nix 2.15.0 'nix build <path>.drv' will build only the .drv file itself, not the
|
let new_deriver = &if data.supports_flakes {
|
||||||
// derivation outputs, '^out' is used to refer to outputs explicitly
|
// Since nix 2.15.0 'nix build <path>.drv' will build only the .drv file itself, not the
|
||||||
let new_deriver = &(deriver.to_owned().to_string() + "^out");
|
// derivation outputs, '^out' is used to refer to outputs explicitly
|
||||||
|
deriver.to_owned().to_string() + "^out"
|
||||||
|
} else {
|
||||||
|
deriver.to_owned()
|
||||||
|
};
|
||||||
|
|
||||||
let path_info_output = Command::new("nix")
|
let path_info_output = Command::new("nix")
|
||||||
.arg("--experimental-features").arg("nix-command")
|
.arg("--experimental-features").arg("nix-command")
|
||||||
|
Loading…
Reference in New Issue
Block a user