Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add nixos-factor #1490

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
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
15 changes: 14 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 @@ -43,6 +43,18 @@
priority = 9; # last
};

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" ];
};

shellcheck.priority = 1;
shfmt.priority = 2;

Expand All @@ -62,6 +74,7 @@
"never"
];
excludes = [
"*report.json"
"config.yaml"
"*secrets.yaml"
"modules/secrets/*.yaml"
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 @@ -49,6 +49,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
Loading