-
-
Notifications
You must be signed in to change notification settings - Fork 14.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
services.nix-daemon: refactor into mkRemoteBuilderDesc #189837
Draft
teto
wants to merge
2
commits into
NixOS:master
Choose a base branch
from
teto:mkRemoteBuilderDesc
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
{ config, lib, isNixAtLeastPre24, ... }: | ||
|
||
with lib; | ||
|
||
let | ||
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 isNixAtLeastPre24 (if config.publicHostKey != null then config.publicHostKey else "-"))); | ||
|
||
# TODO rename into module one | ||
machineSubmodule = { | ||
options = { | ||
hostName = mkOption { | ||
type = types.str; | ||
example = "nixbuilder.example.org"; | ||
description = lib.mdDoc '' | ||
The hostname of the build machine. | ||
''; | ||
}; | ||
system = mkOption { | ||
type = types.nullOr types.str; | ||
default = null; | ||
example = "x86_64-linux"; | ||
description = lib.mdDoc '' | ||
The system type the build machine can execute derivations on. | ||
Either this attribute or {var}`systems` must be | ||
present, where {var}`system` takes precedence if | ||
both are set. | ||
''; | ||
}; | ||
systems = mkOption { | ||
type = types.listOf types.str; | ||
default = [ ]; | ||
example = [ "x86_64-linux" "aarch64-linux" ]; | ||
description = lib.mdDoc '' | ||
The system types the build machine can execute derivations on. | ||
Either this attribute or {var}`system` must be | ||
present, where {var}`system` takes precedence if | ||
both are set. | ||
''; | ||
}; | ||
sshUser = mkOption { | ||
type = types.nullOr types.str; | ||
default = null; | ||
example = "builder"; | ||
description = lib.mdDoc '' | ||
The username to log in as on the remote host. This user must be | ||
able to log in and run nix commands non-interactively. It must | ||
also be privileged to build derivations, so must be included in | ||
{option}`nix.settings.trusted-users`. | ||
''; | ||
}; | ||
sshKey = mkOption { | ||
type = types.nullOr types.str; | ||
default = null; | ||
example = "/root/.ssh/id_buildhost_builduser"; | ||
description = lib.mdDoc '' | ||
The path to the SSH private key with which to authenticate on | ||
the build machine. The private key must not have a passphrase. | ||
If null, the building user (root on NixOS machines) must have an | ||
appropriate ssh configuration to log in non-interactively. | ||
|
||
Note that for security reasons, this path must point to a file | ||
in the local filesystem, *not* to the nix store. | ||
''; | ||
}; | ||
maxJobs = mkOption { | ||
type = types.int; | ||
default = 1; | ||
description = lib.mdDoc '' | ||
The number of concurrent jobs the build machine supports. The | ||
build machine will enforce its own limits, but this allows hydra | ||
to schedule better since there is no work-stealing between build | ||
machines. | ||
''; | ||
}; | ||
speedFactor = mkOption { | ||
type = types.int; | ||
default = 1; | ||
description = lib.mdDoc '' | ||
The relative speed of this builder. This is an arbitrary integer | ||
that indicates the speed of this builder, relative to other | ||
builders. Higher is faster. | ||
''; | ||
}; | ||
mandatoryFeatures = mkOption { | ||
type = types.listOf types.str; | ||
default = [ ]; | ||
example = [ "big-parallel" ]; | ||
description = lib.mdDoc '' | ||
A list of features mandatory for this builder. The builder will | ||
be ignored for derivations that don't require all features in | ||
this list. All mandatory features are automatically included in | ||
{var}`supportedFeatures`. | ||
''; | ||
}; | ||
supportedFeatures = mkOption { | ||
type = types.listOf types.str; | ||
default = [ ]; | ||
example = [ "kvm" "big-parallel" ]; | ||
description = lib.mdDoc '' | ||
A list of features supported by this builder. The builder will | ||
be ignored for derivations that require features not in this | ||
list. | ||
''; | ||
}; | ||
publicHostKey = mkOption { | ||
type = types.nullOr types.str; | ||
default = null; | ||
description = lib.mdDoc '' | ||
The (base64-encoded) public host key of this builder. The field | ||
is calculated via {command}`base64 -w0 /etc/ssh/ssh_host_type_key.pub`. | ||
If null, SSH will use its regular known-hosts file when connecting. | ||
''; | ||
}; | ||
rendered = mkOption { | ||
internal = true; | ||
readOnly = true; | ||
type = types.str; | ||
# apply = | ||
# x: "toto"; | ||
# mkRemoteBuilderDesc config; | ||
}; | ||
}; | ||
|
||
config = { | ||
rendered = mkRemoteBuilderDesc config.config; | ||
|
||
}; | ||
}; | ||
in | ||
machineSubmodule |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This way you don't have to call the module, and the module system can pass its own
config
parameter to the submodule, so that the submodule works.I think it'd be nicer to a value into a
nixVersion
option thanisNixAtLeastPre24
because the latter probably won't be sufficient in the future.