From 8dd0c23f8248dfd3b76a6e1e3694b4c42d1cb8b6 Mon Sep 17 00:00:00 2001 From: Matthieu Coudron Date: Sun, 19 Mar 2023 01:41:03 +0100 Subject: [PATCH] nix-build lib/tests/nix-daemon.nix --show-trace fails : mkRemoteBuilderDesc can't get submodule values --- lib/tests/nix-daemon.nix | 45 +++++++++++++++++++ nixos/modules/services/misc/nix-daemon.nix | 10 ++--- .../modules/services/misc/remote-builder.nix | 34 ++++++++------ nixos/tests/all-tests.nix | 1 + 4 files changed, 72 insertions(+), 18 deletions(-) create mode 100644 lib/tests/nix-daemon.nix diff --git a/lib/tests/nix-daemon.nix b/lib/tests/nix-daemon.nix new file mode 100644 index 0000000000000..2515558952194 --- /dev/null +++ b/lib/tests/nix-daemon.nix @@ -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 + diff --git a/nixos/modules/services/misc/nix-daemon.nix b/nixos/modules/services/misc/nix-daemon.nix index b23516e8bffa2..7cc94b5645204 100644 --- a/nixos/modules/services/misc/nix-daemon.nix +++ b/nixos/modules/services/misc/nix-daemon.nix @@ -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}"; @@ -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 diff --git a/nixos/modules/services/misc/remote-builder.nix b/nixos/modules/services/misc/remote-builder.nix index f4c2675726cf5..14fa23d8179b4 100644 --- a/nixos/modules/services/misc/remote-builder.nix +++ b/nixos/modules/services/misc/remote-builder.nix @@ -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 = { @@ -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 diff --git a/nixos/tests/all-tests.nix b/nixos/tests/all-tests.nix index 8386219f73d83..060f0ec75afe1 100644 --- a/nixos/tests/all-tests.nix +++ b/nixos/tests/all-tests.nix @@ -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 {};