Skip to content

Commit

Permalink
nix-build lib/tests/nix-daemon.nix --show-trace fails : mkRemoteBuild…
Browse files Browse the repository at this point in the history
…erDesc can't get submodule values
  • Loading branch information
Matthieu Coudron committed Mar 19, 2023
1 parent abd7e1f commit 8dd0c23
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 18 deletions.
45 changes: 45 additions & 0 deletions lib/tests/nix-daemon.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# to run these tests:
# nix-build lib/tests/nix-daemon.nix
# If it builds, all tests passed
{ pkgs ? import ../.. {}, lib ? pkgs.lib }:

let

buildMachine1 = {
hostName = "localhost";
# todo move it to secrets
# sshUser = "notroot";
sshKey = "/home/groot/.ssh/id_rsa";
system = "x86_64-linux";
maxJobs = 2;
speedFactor = 2;
supportedFeatures = [ "big-parallel" "kvm" ];
# mandatoryFeatures = [ "perf" ];
};

nixConfModule = { config, ... }: {

buildMachines = buildMachine1;

};

finalConfig = let
checkedAttrs = (lib.modules.evalModules {
modules = [
nixConfModule
({config,...}@args: {
options = {
buildMachines = lib.mkOption {

description = lib.mdDoc ''PlaceHolder'';
type = lib.types.submodule (import ../../nixos/modules/services/misc/remote-builder.nix (args // { isNixAtLeastPre24 = true; }));
};
};
})
];
}).config;
in checkedAttrs;
in
pkgs.writeTextDir "nix-config"
finalConfig.buildMachines.rendered

10 changes: 5 additions & 5 deletions nixos/modules/services/misc/nix-daemon.nix
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ let

isNixAtLeast = versionAtLeast (getVersion nixPackage);

remoteBuilder = import ./remote-builder.nix;
# remoteBuilder = import ./remote-builder.nix;

renderRemoteBuilder = machine: (lib.evalModules {
modules = [ ../modules/services/misc/remote-builder.nix machine ] ;
}).config.rendered;
# renderRemoteBuilder = machine: (lib.evalModules {
# modules = [ ../modules/services/misc/remote-builder.nix machine ] ;
# }).config.rendered;

makeNixBuildUser = nr: {
name = "nixbld${toString nr}";
Expand Down Expand Up @@ -227,7 +227,7 @@ in
buildMachines = mkOption {
#
# remoteBuilder.machineSubmodule;
type = types.listOf (types.submodule ./remote-builder.nix);
type = types.listOf (types.submodule ./remote-builder.nix { isNixAtLeastPre24 = (isNixAtLeast "2.4pre"); });
default = [ ];
description = lib.mdDoc ''
This option lists the machines to be used if distributed builds are
Expand Down
34 changes: 21 additions & 13 deletions nixos/modules/services/misc/remote-builder.nix
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
{ config, lib, pkgs, ... }:
{ config, lib, isNixAtLeastPre24, ... }:

with lib;

let

mkRemoteBuilderDesc = config:
concatStringsSep " " ([
"${optionalString (machine.sshUser != null) "${machine.sshUser}@"}${machine.hostName}"
(if machine.system != null then machine.system else if machine.systems != [ ] then concatStringsSep "," machine.systems else "-")
(if machine.sshKey != null then machine.sshKey else "-")
(toString machine.maxJobs)
(toString machine.speedFactor)
(concatStringsSep "," (machine.supportedFeatures ++ machine.mandatoryFeatures))
(concatStringsSep "," machine.mandatoryFeatures)
mkRemoteBuilderDesc =
# lib.traceSeq (machine)
(concatStringsSep " " ([
"${optionalString (config.sshUser != null) "${config.sshUser}@"}${config.hostName}"
(if config.system != null then config.system else if config.systems != [ ] then concatStringsSep "," config.systems else "-")
(if config.sshKey != null then config.sshKey else "-")
(toString config.maxJobs)
(toString config.speedFactor)
(concatStringsSep "," (config.supportedFeatures ++ config.mandatoryFeatures))
(concatStringsSep "," config.mandatoryFeatures)
]
++ optional (isNixAtLeast "2.4pre") (if machine.publicHostKey != null then machine.publicHostKey else "-"));
++ optional isNixAtLeastPre24 (if config.publicHostKey != null then config.publicHostKey else "-")));

# TODO rename into module one
machineSubmodule = {
Expand Down Expand Up @@ -124,10 +124,18 @@ let
};
rendered = mkOption {
internal = true;
readOnly = true;
type = types.str;
apply = mkRemoteBuilderDesc config;
# apply =
# x: "toto";
# mkRemoteBuilderDesc config;
};
};

config = {
rendered = mkRemoteBuilderDesc config.config;

};
};
in
machineSubmodule
1 change: 1 addition & 0 deletions nixos/tests/all-tests.nix
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,7 @@ in {
nginx-variants = handleTest ./nginx-variants.nix {};
nifi = handleTestOn ["x86_64-linux"] ./web-apps/nifi.nix {};
nitter = handleTest ./nitter.nix {};
nix-daemon = handleTest ./nix-daemon.nix {};
nix-ld = handleTest ./nix-ld.nix {};
nix-serve = handleTest ./nix-serve.nix {};
nix-serve-ssh = handleTest ./nix-serve-ssh.nix {};
Expand Down

0 comments on commit 8dd0c23

Please sign in to comment.