Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions flakeModule.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
inherit (flake-parts-lib)
mkSubmoduleOptions
;
defaultSystems = [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin" ];

in {
options = {
# compatibility layer for home-manager
Expand All @@ -24,6 +26,10 @@ in {
};

config = {
systems = lib.mkDefault defaultSystems;
perSystem = { pkgs, ... }: {
packages = import ./tools { inherit pkgs; inherit (config) nix-config; };
};
flake = {
darwinConfigurations = config.nix-config.darwinConfigurations;
homeConfigurations = config.nix-config.homeConfigurations;
Expand Down
18 changes: 16 additions & 2 deletions modules/lib/appType.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,17 @@ let
types
;

in types.submodule {
in types.submodule ({ name, ... }: {
_file = __curPos.file;

options = {
name = mkOption {
type = types.str;
default = name;
description = ''
The app name. Automatically set.
'';
};
enable = mkOption {
type = types.nullOr types.bool;
default = null;
Expand All @@ -25,6 +32,13 @@ in types.submodule {
List of tags that, when supplied, will enable the given app on the given host.
'';
};
description = mkOption {
type = types.str;
default = "";
description = ''
Description of the app.
'';
};
disableTags = mkOption {
type = types.listOf types.str;
default = [ ];
Expand Down Expand Up @@ -92,4 +106,4 @@ in types.submodule {
'';
};
};
}
})
25 changes: 25 additions & 0 deletions tools/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{ pkgs, nix-config }: let
inherit (pkgs) lib;
appDetails= lib.mapAttrs (appName: app: {
inherit (app) description tags disableTags systems;
name = appName;
}) nix-config.apps;
hostDetails = lib.mapAttrs (hostname: host: {
inherit (host) name kind system;
tags = lib.attrNames
(lib.filterAttrs (tag: enabled: enabled) host.tags);
apps = map (app: app.name) host._internal.apps;
}) nix-config.hosts;
appJson = pkgs.writeText "apps.json" (builtins.toJSON appDetails);
hostJson = pkgs.writeText "hosts.json" (builtins.toJSON hostDetails);
python-env = pkgs.python3.withPackages(p: with p; [
rich
]);
in {
describe-hosts = pkgs.writeShellScriptBin "describe-hosts" ''
${python-env}/bin/python ${./describe_hosts.py} ${hostJson}
'';
describe-apps = pkgs.writeShellScriptBin "describe-apps" ''
${python-env}/bin/python ${./describe_apps.py} ${appJson}
'';
}
36 changes: 36 additions & 0 deletions tools/describe_apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import json
import sys
import itertools

from rich.console import Console
from rich.table import Table
from rich.text import Text


apps_json = sys.argv[1]
with open(apps_json, "r") as f:
apps = json.load(f)


check_mark = Text("✓", style="bold green")
x_mark = Text("✗", style="bold red")

all_tags = sorted(list(set(itertools.chain(*[app["tags"] for app in apps.values()]))))

console = Console()
table = Table(show_header=True, header_style="bold magenta")
table.add_column("name", style="bold")
table.add_column("description")
for tag in all_tags:
table.add_column(tag)

for app_name, app in apps.items():
table.add_row(
app_name,
app["description"],
*[check_mark if tag in app["tags"] else
(x_mark if tag in app["disableTags"] else "")
for tag in all_tags]
)

console.print(table)
39 changes: 39 additions & 0 deletions tools/describe_hosts.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import itertools
import json
import sys

from rich.console import Console
from rich.table import Table
from rich.text import Text


hosts_json = sys.argv[1]
with open(hosts_json, "r") as f:
hosts = json.load(f)


all_tags = sorted(list(set(itertools.chain(*[host["tags"] for host in hosts.values()]))))

console = Console()

table = Table(show_header=True, header_style="bold magenta")
table.add_column("hostname", style="bold")
table.add_column("kind")
table.add_column("system")
table.add_column("num apps")
for tag in all_tags:
table.add_column(tag, justify="center")

check_mark = Text("✓", style="bold green")
x_mark = Text("✗", style="bold red")
for hostname, host in hosts.items():
table.add_row(
hostname,
host["kind"],
host["system"],
str(len(host["apps"])),
*[check_mark if tag in host["tags"] else x_mark for tag in all_tags]
)


console.print(table)