1
0

pkgs/clerie-sops: regenerate clerie-sops-config on every call to clerie-sops

This commit is contained in:
2024-11-21 22:31:42 +01:00
parent 0e00c74ba7
commit c63a781dc6
3 changed files with 74 additions and 32 deletions

View File

@@ -1,37 +1,19 @@
{ pkgs, lib, ... }:
with lib;
pkgs.python313Packages.buildPythonPackage rec {
pname = "clerie-sops-config";
version = "0.0.1";
let
hosts = builtins.attrNames (builtins.readDir ../../hosts);
src = ./.;
mkAgeKey = hostname: ssh_pub_file:
pkgs.runCommand "${hostname}.age" {
buildInputs = [ pkgs.ssh-to-age ];
} ''
ssh-to-age -i ${ssh_pub_file} -o $out
'';
format = "other";
ageKeysForHost = hostname: let
ssh_pub_file = ../../hosts + "/${hostname}/ssh.pub";
in
if builtins.pathExists ssh_pub_file then [
(fileContents (mkAgeKey hostname ssh_pub_file))
] else [];
propagatedBuildInputs = with pkgs; [
ssh-to-age
];
mkCreationRules = hosts:
map (hostname: {
path_regex = escapeRegex "hosts/${hostname}/secrets.json";
key_groups = [{
pgp = [
(fileContents (pkgs.clerie-keys + "/gpg/clerie@clerie.de.fingerprint.txt"))
];
age = ageKeysForHost hostname;
}];
}) hosts;
sops_config = {
creation_rules = mkCreationRules hosts;
};
in
pkgs.writeText "sops.json" (builtins.toJSON sops_config)
installPhase = ''
mkdir -p $out/bin
cp clerie-sops-config.py $out/bin/clerie-sops-config
'';
}