NixHostModelBuilder
Fluent builder for NixHostModel, in the same shape as the customer Company.CreateBuilder(...) chain so both read alike.
public sealed class NixHostModelBuilder
1. Example
var model = NixHostModel.CreateBuilder("nixipfs02")
.WithStaticIp("192.168.3.71")
.WithResources(cpuCores: 4, memoryGib: 8, diskGib: 64)
.AddPackage("htop")
.AddService("kubo", s => s
.WithOption("enable", NixValue.Bool(true))
.WithOption("settings", NixValue.Set(new[]
{
new KeyValuePair<string, NixValue>("Addresses", NixValue.Set(new[]
{
new KeyValuePair<string, NixValue>("API", NixValue.String("/ip4/0.0.0.0/tcp/5001")),
})),
})))
.Build();
2. Constructors
2.1. NixHostModelBuilder(string)
Starts a builder for the given hostname.
public NixHostModelBuilder(string hostname)
| Name | Type | Description |
|---|---|---|
hostname |
string |
Target hostname. |
3. Methods
3.1. AddModule(string)
Adds a module path to the host’s imports.
public NixHostModelBuilder AddModule(string modulePath)
| Name | Type | Description |
|---|---|---|
modulePath |
string |
Module path as written in nix, e.g. |
Returns: NixHostModelBuilder — This builder.
3.2. AddPackage(string)
Adds a package to environment.systemPackages.
public NixHostModelBuilder AddPackage(string attributePath)
| Name | Type | Description |
|---|---|---|
attributePath |
string |
nixpkgs attribute path, e.g. |
Returns: NixHostModelBuilder — This builder.
3.3. AddPackages(string[])
Adds several packages at once.
public NixHostModelBuilder AddPackages(params string[] attributePaths)
| Name | Type | Description |
|---|---|---|
attributePaths |
string[] |
nixpkgs attribute paths. |
Returns: NixHostModelBuilder — This builder.
3.4. AddRawNix(string)
Appends a verbatim nix line to the host body.
public NixHostModelBuilder AddRawNix(string nixLine)
| Name | Type | Description |
|---|---|---|
nixLine |
string |
Raw nix source line. |
Returns: NixHostModelBuilder — This builder.
3.5. AddSecret(string, string, bool)
Adds a sops secret this host requires.
public NixHostModelBuilder AddSecret(string sopsPath, string value, bool isMultiline = false)
| Name | Type | Description |
|---|---|---|
sopsPath |
string |
Secret path, e.g. |
value |
string |
Secret value. |
isMultiline |
bool |
True to emit as a YAML block scalar. |
Returns: NixHostModelBuilder — This builder.
3.6. AddService(string, Action<NixService>)
Adds a services.<name> block.
public NixHostModelBuilder AddService(string name, Action<NixService> configure = null)
| Name | Type | Description |
|---|---|---|
name |
string |
Service option path under |
configure |
Action<NixService> |
Optional callback to set further options. |
Returns: NixHostModelBuilder — This builder.
3.7. Build()
Returns the assembled model.
public NixHostModel Build()
Returns: NixHostModel — The configured NixHostModel.
3.8. SetOption(string, NixValue)
Sets any option path in the NixOS option tree.
public NixHostModelBuilder SetOption(string optionPath, NixValue value)
| Name | Type | Description |
|---|---|---|
optionPath |
string |
Full dotted path, e.g. |
value |
NixValue |
Value to assign. |
Returns: NixHostModelBuilder — This builder.
3.9. SetOption(string, bool)
Sets an option to a boolean.
public NixHostModelBuilder SetOption(string optionPath, bool value)
| Name | Type | Description |
|---|---|---|
optionPath |
string |
Full dotted option path. |
value |
bool |
Boolean value. |
Returns: NixHostModelBuilder — This builder.
3.10. SetOption(string, long)
Sets an option to an integer.
public NixHostModelBuilder SetOption(string optionPath, long value)
| Name | Type | Description |
|---|---|---|
optionPath |
string |
Full dotted option path. |
value |
long |
Integer value. |
Returns: NixHostModelBuilder — This builder.
3.11. SetOption(string, string)
Sets an option to a quoted string.
public NixHostModelBuilder SetOption(string optionPath, string value)
| Name | Type | Description |
|---|---|---|
optionPath |
string |
Full dotted option path. |
value |
string |
String value. |
Returns: NixHostModelBuilder — This builder.
3.12. WithDiskDevice(string)
Sets the install-target block device.
public NixHostModelBuilder WithDiskDevice(string device)
| Name | Type | Description |
|---|---|---|
device |
string |
Block device, e.g. |
Returns: NixHostModelBuilder — This builder.
3.13. WithResources(uint?, int?, int?, int?)
Sets the VM sizing used when the host is provisioned.
public NixHostModelBuilder WithResources(uint? cpuCores = null, int? memoryGib = null, int? diskGib = null, int? swapMib = null)
| Name | Type | Description |
|---|---|---|
cpuCores |
uint? |
vCPU count. |
memoryGib |
int? |
RAM in GiB. |
diskGib |
int? |
System disk in GiB. |
swapMib |
int? |
Swapfile in MiB. |
Returns: NixHostModelBuilder — This builder.
3.14. WithStaticIp(string, int, string, IReadOnlyList<string>)
Pins a static IPv4. Omit entirely to stay on DHCP.
public NixHostModelBuilder WithStaticIp(string address, int prefix = 24, string gateway = null, IReadOnlyList<string> nameservers = null)
| Name | Type | Description |
|---|---|---|
address |
string |
IPv4 address. |
prefix |
int |
Prefix length. |
gateway |
string |
Optional gateway; derived from the address when null. |
nameservers |
IReadOnlyList<string> |
Optional DNS servers. |
Returns: NixHostModelBuilder — This builder.
3.15. WithTimeZone(string)
Sets the IANA time zone.
public NixHostModelBuilder WithTimeZone(string timeZone)
| Name | Type | Description |
|---|---|---|
timeZone |
string |
Time zone, e.g. |
Returns: NixHostModelBuilder — This builder.
3.16. WithUser(string)
Sets the admin user name.
public NixHostModelBuilder WithUser(string userName)
| Name | Type | Description |
|---|---|---|
userName |
string |
Admin user. |
Returns: NixHostModelBuilder — This builder.