2021-05-04 16:24:31 +03:00
|
|
|
{
|
2021-07-20 18:50:08 +03:00
|
|
|
lib,
|
2023-01-29 22:58:38 +03:00
|
|
|
stdenv,
|
2021-05-04 16:24:31 +03:00
|
|
|
rage,
|
2023-02-13 19:06:58 +03:00
|
|
|
jq,
|
2021-05-04 16:24:31 +03:00
|
|
|
nix,
|
|
|
|
mktemp,
|
2021-07-22 14:58:29 +03:00
|
|
|
diffutils,
|
2023-01-29 22:58:38 +03:00
|
|
|
substituteAll,
|
|
|
|
ageBin ? "${rage}/bin/rage",
|
|
|
|
shellcheck,
|
2023-02-22 07:35:56 +03:00
|
|
|
}: let
|
|
|
|
bin = "${placeholder "out"}/bin/agenix";
|
|
|
|
in
|
|
|
|
stdenv.mkDerivation rec {
|
|
|
|
pname = "agenix";
|
|
|
|
version = "0.15.0";
|
|
|
|
src = substituteAll {
|
|
|
|
inherit ageBin version;
|
|
|
|
jqBin = "${jq}/bin/jq";
|
|
|
|
nixInstantiate = "${nix}/bin/nix-instantiate";
|
|
|
|
mktempBin = "${mktemp}/bin/mktemp";
|
|
|
|
diffBin = "${diffutils}/bin/diff";
|
|
|
|
src = ./agenix.sh;
|
|
|
|
};
|
|
|
|
dontUnpack = true;
|
|
|
|
doInstallCheck = true;
|
|
|
|
installCheckInputs = [shellcheck];
|
|
|
|
postInstallCheck = ''
|
|
|
|
shellcheck ${bin}
|
|
|
|
${bin} -h | grep ${version}
|
2023-01-29 22:58:38 +03:00
|
|
|
|
2023-02-22 07:35:56 +03:00
|
|
|
mkdir -p /tmp/home/.ssh
|
|
|
|
cp -r "${../example}" /tmp/home/secrets
|
|
|
|
chmod -R u+rw /tmp/home/secrets
|
|
|
|
export HOME=/tmp/home
|
|
|
|
(
|
|
|
|
umask u=rw,g=r,o=r
|
|
|
|
cp ${../example_keys/user1.pub} $HOME/.ssh/id_ed25519.pub
|
|
|
|
chown $UID $HOME/.ssh/id_ed25519.pub
|
|
|
|
)
|
|
|
|
(
|
|
|
|
umask u=rw,g=,o=
|
|
|
|
cp ${../example_keys/user1} $HOME/.ssh/id_ed25519
|
|
|
|
chown $UID $HOME/.ssh/id_ed25519
|
|
|
|
)
|
2023-01-29 22:58:38 +03:00
|
|
|
|
2023-02-22 07:35:56 +03:00
|
|
|
cd /tmp/home/secrets
|
|
|
|
test $(${bin} -d secret1.age) = "hello"
|
|
|
|
'';
|
2023-01-29 22:58:38 +03:00
|
|
|
|
2023-02-22 07:35:56 +03:00
|
|
|
installPhase = ''
|
|
|
|
install -D $src ${bin}
|
|
|
|
'';
|
|
|
|
|
|
|
|
meta.description = "age-encrypted secrets for NixOS";
|
|
|
|
}
|