Skip to content

Commit

Permalink
feat: Generate flake-graph and nix-topology diagrams automatically
Browse files Browse the repository at this point in the history
- Display in readme
- Fix generated artifact permissions
- Update flake.lock
  • Loading branch information
nikitawootten committed Apr 20, 2024
1 parent 7231322 commit e526137
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 17 deletions.
31 changes: 31 additions & 0 deletions .github/workflows/artifacts.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Artifacts
on:
push:
branches:
- main
jobs:
generate:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3
- uses: cachix/install-nix-action@v20
with:
github_access_token: ${{ secrets.GITHUB_TOKEN }}
- uses: DeterminateSystems/magic-nix-cache-action@main
- run: make artifacts
# Note: I'd prefer to use commit artifacts here, but GitHub does not
# expose a URL to refer to the latest run of a specific workflow.
- name: Upload flake-graph.svg
uses: exuanbo/[email protected]
with:
gist_id: "a0b5b3e0afdaaa8e02ace16b955da7ec"
token: ${{ secrets.GIST_TOKEN }}
file_path: out/flake-graph.svg
gist_file_name: flake-graph.svg
- name: Upload topology.svg
uses: exuanbo/[email protected]
with:
gist_id: "a0b5b3e0afdaaa8e02ace16b955da7ec"
token: ${{ secrets.GIST_TOKEN }}
file_path: out/topology.svg
gist_file_name: topology.svg
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,13 @@ topology: out/topology.svg ## Build the nix-topology diagram

out/topology.svg: out flake.nix
$(NIX_CMD) build .#topology.$(shell make --silent get-system).config.output
cp result/main.svg out/topology.svg
cp --no-preserve=mode result/main.svg out/topology.svg

.PHONY: flake-graph
flake-graph: out/flake-graph.svg ## Build the flake-graph diagram

out/flake-graph.svg: out flake.lock
$(NIX_CMD) develop --command flake-graph flake.lock | dot -Tsvg > out/flake-graph.svg
$(NIX_CMD) develop --command bash -c 'flake-graph flake.lock | dot -Tsvg > out/flake-graph.svg'

.PHONY: clean
clean: ## Clean all artifacts
Expand All @@ -86,7 +86,7 @@ clean: ## Clean all artifacts

.PHONY: get-hosts
list-hosts: ## List NixOS configuration names
@$(NIX_CMD) develop --command nix flake show --json 2>/dev/null | jq -r ".nixosConfigurations | keys | .[] | @text"
@$(NIX_CMD) develop --command bash -c 'nix flake show --json 2>/dev/null | jq -r ".nixosConfigurations | keys | .[] | @text"'

.PHONY: get-system
get-system: ## Get the current system name
Expand Down
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

Welcome to my Nix-ified infrastructure and personal monorepo.

![man made horrors beyond comprehension](https://gist.githubusercontent.com/nikitawootten/a0b5b3e0afdaaa8e02ace16b955da7ec/raw/flake-graph.svg)
*Flake dependency diagram [generated](./.github/workflows/artifacts.yaml) with [`nikitawootten/flake-graph`](https://github.com/nikitawootten/flake-graph).*

## Projects

This repository contains my Nix-related experiments.
Expand All @@ -19,7 +22,6 @@ Beyond managing dotfiles, I have also experimented with [packaging some of my co
├── packages/ # My packages
├── Makefile # Common operations defined here
├── README.md # You are here
└── shell.nix # Shell environment for Makefile operations
```

### Packages
Expand All @@ -35,6 +37,9 @@ If you would like to see these packages submitted [upstream](https://github.com/

### Homelab

![network diagram](https://gist.githubusercontent.com/nikitawootten/a0b5b3e0afdaaa8e02ace16b955da7ec/raw/topology.svg)
*Network diagram [generated](./.github/workflows/artifacts.yaml) with [`oddlama/nix-topology`](https://github.com/oddlama/nix-topology).*

The [`homelab` NixOS module](./hostModules/homelab/) packages most of my homelab-specific configuration, including media management and monitoring.

For usage examples, refer to the [`hades`](./hosts/hades/) and [`iris`](./hosts/iris/) host configurations:
Expand All @@ -46,7 +51,7 @@ I have created a few Flake helpers and placed them in [`lib/`](./lib):
- [`mkHomes`](./lib/mkHomes.nix): Home-Manager configuration helper that generates Home-Manager and NixOS module compatible outputs and imports `user@hostname`-specific Home-Manager modules by path.
- [`mkHosts`](./lib/mkHosts.nix): NixOS configuration helper that imports a corresponding Home-Manager configuration and imports `hostname`-specific NixOS modules by path.

Refer to the [`flake.nix`](./flake.nix) for usage.
Refer to [`flake.nix`](./flake.nix) for usage.

## Usage

Expand Down
18 changes: 9 additions & 9 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions hostModules/homelab/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ in {
recommendedGzipSettings = true;
};

topology.self.services.nginx = {
hidden = true;
};
topology.self.services.nginx = { hidden = true; };

# Helper function to create a subdomain for a service
lib.homelab.mkServiceSubdomain = subdomain: "${subdomain}.${cfg.domain}";
Expand Down
4 changes: 4 additions & 0 deletions hostModules/homelab/media/prowlarr.nix
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,9 @@ in {
icon = "prowlarr.png";
};
};

topology.self.services.prowlarr = {
details.listen.text = lib.mkForce cfg.domain;
};
};
}
4 changes: 4 additions & 0 deletions hostModules/homelab/media/radarr.nix
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,9 @@ in {
icon = "radarr.png";
};
};

topology.self.services.radarr = {
details.listen.text = lib.mkForce cfg.domain;
};
};
}
4 changes: 4 additions & 0 deletions hostModules/homelab/media/sonarr.nix
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,9 @@ in {
icon = "sonarr.png";
};
};

topology.self.services.sonarr = {
details.listen.text = lib.mkForce cfg.domain;
};
};
}
4 changes: 4 additions & 0 deletions hostModules/homelab/media/transmission.nix
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,9 @@ in {
icon = "transmission.png";
};
};

topology.self.services.transmission = {
details.listen.text = lib.mkForce cfg.domain;
};
};
}

0 comments on commit e526137

Please sign in to comment.