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,
|
2023-12-21 00:13:47 +03:00
|
|
|
age,
|
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,
|
2023-12-21 00:13:47 +03:00
|
|
|
ageBin ? "${age}/bin/age",
|
2023-01-29 22:58:38 +03:00
|
|
|
shellcheck,
|
2023-12-24 01:43:03 +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
|
|
|
|
2024-02-01 15:30:22 +03:00
|
|
|
test_tmp=$(mktemp -d 2>/dev/null || mktemp -d -t 'mytmpdir')
|
|
|
|
export HOME="$test_tmp/home"
|
|
|
|
export NIX_STORE_DIR="$test_tmp/nix/store"
|
|
|
|
export NIX_STATE_DIR="$test_tmp/nix/var"
|
|
|
|
mkdir -p "$HOME" "$NIX_STORE_DIR" "$NIX_STATE_DIR"
|
2023-12-24 01:47:15 +03:00
|
|
|
function cleanup {
|
2024-02-01 15:30:22 +03:00
|
|
|
rm -rf "$test_tmp"
|
2023-12-24 01:47:15 +03:00
|
|
|
}
|
|
|
|
trap "cleanup" 0 2 3 15
|
|
|
|
|
|
|
|
mkdir -p $HOME/.ssh
|
|
|
|
cp -r "${../example}" $HOME/secrets
|
|
|
|
chmod -R u+rw $HOME/secrets
|
2023-12-24 01:43:03 +03:00
|
|
|
(
|
|
|
|
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-12-24 01:47:15 +03:00
|
|
|
cd $HOME/secrets
|
2023-12-24 01:43:03 +03:00
|
|
|
test $(${bin} -d secret1.age) = "hello"
|
|
|
|
'';
|
2023-01-29 22:58:38 +03:00
|
|
|
|
2023-12-24 01:43:03 +03:00
|
|
|
installPhase = ''
|
|
|
|
install -D $src ${bin}
|
|
|
|
'';
|
|
|
|
|
|
|
|
meta.description = "age-encrypted secrets for NixOS";
|
|
|
|
}
|