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)
Table 1. Parameters
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)
Table 2. Parameters
Name Type Description

modulePath

string

Module path as written in nix, e.g. ./extra.nix.

Returns: NixHostModelBuilder — This builder.

3.2. AddPackage(string)

Adds a package to environment.systemPackages.

public NixHostModelBuilder AddPackage(string attributePath)
Table 3. Parameters
Name Type Description

attributePath

string

nixpkgs attribute path, e.g. htop.

Returns: NixHostModelBuilder — This builder.

3.3. AddPackages(string[])

Adds several packages at once.

public NixHostModelBuilder AddPackages(params string[] attributePaths)
Table 4. Parameters
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)
Table 5. Parameters
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)
Table 6. Parameters
Name Type Description

sopsPath

string

Secret path, e.g. ipfs/swarm_key.

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)
Table 7. Parameters
Name Type Description

name

string

Service option path under services..

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)
Table 8. Parameters
Name Type Description

optionPath

string

Full dotted path, e.g. host.system.gc.frequency.

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)
Table 9. Parameters
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)
Table 10. Parameters
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)
Table 11. Parameters
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)
Table 12. Parameters
Name Type Description

device

string

Block device, e.g. /dev/sda.

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)
Table 13. Parameters
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)
Table 14. Parameters
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)
Table 15. Parameters
Name Type Description

timeZone

string

Time zone, e.g. Europe/Zurich.

Returns: NixHostModelBuilder — This builder.

3.16. WithUser(string)

Sets the admin user name.

public NixHostModelBuilder WithUser(string userName)
Table 16. Parameters
Name Type Description

userName

string

Admin user.

Returns: NixHostModelBuilder — This builder.