Skip to content

Commit

Permalink
feat(packages): Add secret package
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinNikov authored and PetarKirov committed May 28, 2024
1 parent 23ba5a7 commit e19a3b0
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
pyroscope = pkgs.callPackage ./pyroscope {};
grafana-agent = import ./grafana-agent {inherit inputs';};
ci-matrix = pkgs.callPackage ./ci-matrix {};
secret = import ./secret {inherit inputs' pkgs;};
}
// pkgs.lib.optionalAttrs isLinux {
inherit (inputs'.validator-ejector.packages) validator-ejector;
Expand Down
72 changes: 72 additions & 0 deletions packages/secret/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
{
inputs',
pkgs,
...
}: let
agenix = inputs'.agenix.packages.agenix.override {ageBin = "${pkgs.rage}/bin/rage";};
in
pkgs.writeShellApplication {
name = "secret";
text = ''
#!/usr/bin/env bash
set -euo pipefail
machine=""
service=""
secret=""
vm=""
export RULES=""
while [[ $# -gt 0 ]]; do
case "$1" in
--machine=*)
machine="''${1#*=}"
;;
--service=*)
service="''${1#*=}"
;;
--secret=*)
secret="''${1#*=}"
;;
--vm)
vm="true"
;;
--help)
echo -e "NAME\n\
secret\n\n\
SYNOPSIS\n\
secret [OPTION]\n\n\
EXAMPLE\n\
secret --machine=mymachine --service=myservice --secret=mysecret\n\n\
DESCRIPTION\n\
Secret is the command made for nix repos to get rid of the secret.nix when\n\
you are using agenix. Secret must be used with mcl-secrets and mcl-host-info\n\
modules from nixos-modules repository to work properly.\n\n\
OPTIONS\n\
--machine - Machine for which you want to create a secret.\n\
--service - Service for which you want to create a secret.\n\
--secret - Secret you want to encrypt.\n\
--vm - Make secret for the vmVariant."
exit 0
;;
*)
echo "Unknown option: $1"
exit 1
;;
esac
shift
done
if [[ -z "$machine" || -z "$service" || -z "$secret" ]]; then
echo "You must specify machine, service, and secret"
exit 1
fi
if [ "$vm" = "true" ]; then
RULES="$(nix eval --raw ".#nixosConfigurations.$machine-vm.config.virtualisation.vmVariant.mcl.secrets.services.$service.nix-file")"
else
RULES="$(nix eval --raw ".#nixosConfigurations.$machine.config.mcl.secrets.services.$service.nix-file")"
fi
"${agenix}/bin/agenix" -e "$secret.age"
'';
}

0 comments on commit e19a3b0

Please sign in to comment.