Skip to content
Draft
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
14 changes: 13 additions & 1 deletion dev/treefmt.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ pkgs, ... }:
{ lib, pkgs, ... }:
{
# Used to find the project root
projectRootFile = ".git/config";
Expand Down Expand Up @@ -50,6 +50,18 @@

dnscontrol.includes = [ "*dnsconfig.js" ];

json-sort-compact = {
command = pkgs.writeShellScriptBin "json-sort-compact" ''
for file in "$@"; do
${lib.getExe pkgs.jq} \
'walk(if type == "array" then sort else . end)' \
--compact-output --sort-keys < "$file" |
${lib.getExe' pkgs.moreutils "sponge"} "$file"
done
'';
includes = [ "*report.json" ];
};

mdformat-mkdocs = {
command = pkgs.mdformat.withPlugins (p: [
p.mdformat-frontmatter
Expand Down
1 change: 1 addition & 0 deletions modules/nixos/common/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
../../shared/nix-daemon.nix
./armv7l.nix
./builder.nix
./facter.nix
./security.nix
./sops-nix.nix
./telegraf.nix
Expand Down
16 changes: 16 additions & 0 deletions modules/nixos/common/facter.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
config,
inputs,
lib,
...
}:
let
reportPath = "${inputs.self}/hosts/${config.networking.hostName}/report.json";
in
{
imports = [ inputs.nixos-facter-modules.nixosModules.facter ];

config = lib.mkIf (builtins.pathExists reportPath) {
facter = { inherit reportPath; };
};
}
20 changes: 20 additions & 0 deletions tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,26 @@ def deploy(h: DeployHost) -> None:
g.run_function(deploy)


@task
def facter_report(c: Any, hosts: str = "") -> None:
"""
Generate facter report
"""
g = DeployGroup(get_hosts(hosts))

def facter(h: DeployHost) -> None:
res = h.run(
["sudo", "nix", "run", "nixpkgs#nixos-facter"],
stdout=subprocess.PIPE,
)
hostname = h.host.replace(".nix-community.org", "")
path = f"{ROOT}/hosts/{hostname}/report.json"
with open(path, "w") as f:
f.write(res.stdout)

g.run_function(facter)


@task
def sotp(c: Any, acct: str) -> None:
"""
Expand Down