Skip to content

Commit

Permalink
add nixos-factor
Browse files Browse the repository at this point in the history
  • Loading branch information
zowoq committed Sep 30, 2024
1 parent 28c87d1 commit 2c44efc
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 0 deletions.
16 changes: 16 additions & 0 deletions flake.lock

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

1 change: 1 addition & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
nix-darwin.url = "github:LnL7/nix-darwin";
nix-index-database.inputs.nixpkgs.follows = "nixpkgs";
nix-index-database.url = "github:nix-community/nix-index-database";
nixos-facter-modules.url = "github:numtide/nixos-facter-modules";
nixpkgs-update-github-releases.flake = false;
nixpkgs-update-github-releases.url = "github:nix-community/nixpkgs-update-github-releases";
nixpkgs-update.inputs.mmdoc.follows = "empty";
Expand Down
14 changes: 14 additions & 0 deletions modules/nixos/common/facter.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
config,
inputs,
lib,
...
}:
let
report = "${inputs.self}/hosts/${config.networking.hostName}/report.json";
in
{
imports = [ inputs.nixos-facter-modules.nixosModules.facter ];

facter.reportPath = lib.mkIf (builtins.pathExists report) report;
}
21 changes: 21 additions & 0 deletions tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,27 @@ 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)
# h.run_local(f"jq -c < {path} | sponge {path}")

g.run_function(facter)


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

0 comments on commit 2c44efc

Please sign in to comment.