Skip to content

Commit

Permalink
docs: add flake-parts example
Browse files Browse the repository at this point in the history
  • Loading branch information
oddlama committed Jul 12, 2024
1 parent 8a69249 commit e7c64ea
Showing 1 changed file with 32 additions and 4 deletions.
36 changes: 32 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ Maybe it will be useful for somebody else, too.
## 📦 Installation and Usage

Installation should be as simple as adding nix-topology to your flake.nix,
defining the global module and adding the NixOS module to your systems:
defining the global module and adding the NixOS module to your systems.
A [flake-parts](https://flake.parts) module is also available (see end of this section for an example).

1. Add nix-topology as an input to your flake
```nix
Expand All @@ -61,8 +62,9 @@ defining the global module and adding the NixOS module to your systems:
4. Create the global topology by using `topology = import nix-topology { pkgs = /*...*/; };`.
Expose this as an output in your flake so you can access it.
```nix
inputs.nix-topology.url = "github:oddlama/nix-topology";
topology = import nix-topology {
# Repeat this for each system where you want to build your topology.
# You can do this manually or use flake-utils.
topology.x86_64-linux = import nix-topology {
inherit pkgs; # Only this package set must include nix-topology.overlays.default
modules = [
# Your own file to define global topology. Works in principle like a nixos module but uses different options.
Expand All @@ -72,7 +74,7 @@ defining the global module and adding the NixOS module to your systems:
];
};
```
5. Render your topology via `nix build .#topology.<current-system>.config.output`, the resulting directory will contain your finished svgs.
5. Render your topology via `nix build .#topology.x86_64-linux.config.output`, the resulting directory will contain your finished svgs.
Note that this can take a minute, depending on how many hosts you have defined. Evaluating many nixos configurations just takes some time,
and the renderer sometimes struggles with handling bigger PNGs in a timely fashion.

Expand Down Expand Up @@ -118,6 +120,32 @@ defining the global module and adding the NixOS module to your systems:
```
</details>

<details>
<summary>Example flake.nix with flake-parts</summary>


```nix
{
inputs.flake-parts.url = "github:hercules-ci/flake-parts";
inputs.nix-topology.url = "github:oddlama/nix-topology";
# ...
outputs = inputs:
inputs.flake-parts.lib.mkFlake {inherit inputs;} {
imports = [
inputs.nix-topology.flakeModule
];
perSystem = {...}: {
topology.modules = [
{
# Your global topology definitions
}
];
};
};
}
```
</details>

## 🌱 Adding connections, networks and other devices

After rendering for the first time, the initial diagram might look a little unstructured.
Expand Down

0 comments on commit e7c64ea

Please sign in to comment.