2023-05-26 00:40:31 +07:00
|
|
|
{ exec, ... }: {
|
2023-12-25 04:13:25 +07:00
|
|
|
secrets = exec [ "cat" "/secrets/nixos/default.nix" ] {
|
2023-05-26 01:38:17 +07:00
|
|
|
# compress and base64 the file to make it representable in nix,
|
|
|
|
# then decompress it back in a derivation (shouldn't there be a better way...)
|
2023-10-17 20:25:03 +07:00
|
|
|
copyToStore = pkgs: name: path:
|
2023-05-26 01:38:17 +07:00
|
|
|
let
|
2023-10-17 23:12:08 +07:00
|
|
|
archive = exec [ "${pkgs.bash}/bin/bash" "-c" ''
|
2023-12-25 04:13:25 +07:00
|
|
|
cd /secrets/nixos
|
2023-10-17 23:12:08 +07:00
|
|
|
echo '"'"$(
|
|
|
|
${pkgs.gnutar}/bin/tar -I ${pkgs.zstd}/bin/zstd --exclude-vcs \
|
|
|
|
--transform='s#'${pkgs.lib.escapeShellArg path}'#!#' \
|
|
|
|
-c -- ${pkgs.lib.escapeShellArg path} | base64 -w0
|
|
|
|
)"'"'
|
|
|
|
'' ];
|
|
|
|
in derivation {
|
2023-10-18 18:35:41 +07:00
|
|
|
__contentAddressed = true;
|
|
|
|
outputHashAlgo = "sha256";
|
|
|
|
outputHashMode = "recursive";
|
|
|
|
preferLocalBuild = true;
|
|
|
|
allowSubstitutes = false;
|
|
|
|
allowedReferences = [];
|
|
|
|
passAsFile = [ "archive" ];
|
|
|
|
inherit name archive;
|
2023-10-17 23:12:08 +07:00
|
|
|
inherit (pkgs) system;
|
|
|
|
builder = "${pkgs.bash}/bin/bash";
|
|
|
|
args = [ "-c" ''
|
2023-10-18 18:35:41 +07:00
|
|
|
${pkgs.coreutils}/bin/base64 -d "$archivePath" |
|
2023-10-17 23:12:08 +07:00
|
|
|
${pkgs.gnutar}/bin/tar -P --transform="s#!#$out#" -I ${pkgs.zstd}/bin/zstd -x
|
|
|
|
'' ];
|
|
|
|
};
|
2023-05-26 01:38:17 +07:00
|
|
|
};
|
2023-05-26 00:40:31 +07:00
|
|
|
}
|