Skip to content

head-gardener/alloy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Alloy

alloy is a tool for managing interdependent services between different configurations inside a flake. See more on https://backyard-hg.net/alloy.html!

Overview

It works by allowing defined modules to access each other's configuration options from args.

{ alloy, ... }:
let
  inherit (alloy) nix-serve;
in
{
  nix.settings.substituters = [
    "http://${nix-serve.host}:${toString nix-serve.config.services.nix-serve.port}"
  ];
}

Features

  • Pull config values from host found by modules it uses: get hostname from a host running nginx module.
  • Collect configurations from multiple hosts in a single value with forEach: get VPN addresses of all IPFS consumers in a network.
  • Extend configs of other hosts: configure reverse proxy from a web-server's host.

Installation

To install alloy you can use flake-parts or do it yourself.

  • When using parts, add alloy.flakeModule to your imports, put your configuration in flake.alloy.config and move flake.nixosConfigurations to flake.alloy.nixosConfigurations. See module defenition for details.
  • When doing it yourself, wrap your nixosConfigurations in a call to alloy.lib.apply, providing configuration:
nixosConfigurations = alloy.lib.apply {
  config = [ ./alloy_config.nix ];
  extraSpecialArgs = { ... };
  nixosConfigurations = {
    host = { ... };
    # your configs
  }
};

Configuration

In general your configuration would look like this.

{
  modules = {
    module = ./module.nix; # anything that's considered a module
  };

  hosts = mods: with mods; {
    host = [ module ]; # what modules go where
  };
}

alloy configuration uses Nix modules, so you can use imports, config, etc. alloy modules have a special argument alloy-utils, which is alloy.lib.utils.

Example

See /example for a complete flake, defining multiple interdependent configurations via alloy.

Caveats

Error propagation

Since alloy collects extensions for a given host from every other one, evaluation errors will propagate in the alloy host pull. This means a host can fail because a completely different one accesses an undefined option. In this case, look for alloy's error context messages, e.g. while collecting alloy extensions for ....

TODO

  • make this a flake-parts module
  • use nix's module system for config
  • handle multi-instance services
  • remote extend
  • middleware
  • documentation, errors

About

melting Nix modules together across configurations

Resources

License

Stars

1 star

Watchers

1 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors