Skip to content

Commit f5e6a84

Browse files
committed
feat(packages): Add secret package
1 parent 3a0a816 commit f5e6a84

File tree

2 files changed

+73
-0
lines changed

2 files changed

+73
-0
lines changed

packages/default.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
}
5151
// optionalAttrs (system == "x86_64-linux" || system == "aarch64-darwin") {
5252
grafana-agent = import ./grafana-agent {inherit inputs';};
53+
secret = import ./secret {inherit inputs' pkgs;};
5354
}
5455
// optionalAttrs isLinux {
5556
folder-size-metrics = pkgs.callPackage ./folder-size-metrics {};

packages/secret/default.nix

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
{
2+
inputs',
3+
pkgs,
4+
...
5+
}: let
6+
agenix = inputs'.agenix.packages.agenix.override {ageBin = "${pkgs.rage}/bin/rage";};
7+
in
8+
pkgs.writeShellApplication {
9+
name = "secret";
10+
text = ''
11+
#!/usr/bin/env bash
12+
set -euo pipefail
13+
14+
machine=""
15+
service=""
16+
secret=""
17+
vm=""
18+
export RULES=""
19+
20+
while [[ $# -gt 0 ]]; do
21+
case "$1" in
22+
--machine=*)
23+
machine="''${1#*=}"
24+
;;
25+
--service=*)
26+
service="''${1#*=}"
27+
;;
28+
--secret=*)
29+
secret="''${1#*=}"
30+
;;
31+
--vm)
32+
vm="true"
33+
;;
34+
--help)
35+
echo -e "NAME\n\
36+
secret\n\n\
37+
SYNOPSIS\n\
38+
secret [OPTION]\n\n\
39+
EXAMPLE\n\
40+
secret --machine=mymachine --service=myservice --secret=mysecret\n\n\
41+
DESCRIPTION\n\
42+
Secret is the command made for nix repos to get rid of the secret.nix when\n\
43+
you are using agenix. Secret must be used with mcl-secrets and mcl-host-info\n\
44+
modules from nixos-modules repository to work properly.\n\n\
45+
OPTIONS\n\
46+
--machine - Machine for which you want to create a secret.\n\
47+
--service - Service for which you want to create a secret.\n\
48+
--secret - Secret you want to encrypt.\n\
49+
--vm - Make secret for the vmVariant."
50+
exit 0
51+
;;
52+
*)
53+
echo "Unknown option: $1"
54+
exit 1
55+
;;
56+
esac
57+
shift
58+
done
59+
60+
if [[ -z "$machine" || -z "$service" || -z "$secret" ]]; then
61+
echo "You must specify machine, service, and secret"
62+
exit 1
63+
fi
64+
65+
if [ "$vm" = "true" ]; then
66+
RULES="$(nix eval --raw ".#nixosConfigurations.$machine-vm.config.virtualisation.vmVariant.mcl.secrets.services.$service.nix-file")"
67+
else
68+
RULES="$(nix eval --raw ".#nixosConfigurations.$machine.config.mcl.secrets.services.$service.nix-file")"
69+
fi
70+
"${agenix}/bin/agenix" -e "$secret.age"
71+
'';
72+
}

0 commit comments

Comments
 (0)