2023-07-08 10:34:46 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
2023-01-20 06:57:49 +00:00
|
|
|
|
|
|
|
let
|
2023-07-08 10:34:46 +00:00
|
|
|
|
|
|
|
hash-path-with-salt = pkgs.static-nix-shell.mkBash {
|
|
|
|
pname = "hash-path-with-salt";
|
2024-02-25 17:37:38 +00:00
|
|
|
srcRoot = ./.;
|
2023-07-08 10:34:46 +00:00
|
|
|
};
|
2023-07-11 05:15:56 +00:00
|
|
|
|
2023-01-20 06:57:49 +00:00
|
|
|
cfg = config.sane.derived-secrets;
|
2023-07-11 05:15:56 +00:00
|
|
|
secret = with lib; types.submodule {
|
2023-01-20 06:57:49 +00:00
|
|
|
options = {
|
|
|
|
len = mkOption {
|
|
|
|
type = types.int;
|
2023-10-17 01:16:08 +00:00
|
|
|
description = ''
|
|
|
|
how many bytes of entropy to use; not necessarily the encoded length of the secret.
|
|
|
|
e.g. if using base16, the length of the encoded secret will be twice this value.
|
|
|
|
'';
|
|
|
|
default = 32; # 256b security
|
2023-01-20 06:57:49 +00:00
|
|
|
};
|
|
|
|
encoding = mkOption {
|
|
|
|
type = types.enum [ "base64" ];
|
|
|
|
};
|
2023-10-17 01:16:08 +00:00
|
|
|
acl.mode = mkOption {
|
2023-10-17 22:46:02 +00:00
|
|
|
type = types.str;
|
2023-10-17 01:16:08 +00:00
|
|
|
default = "0600";
|
|
|
|
};
|
2023-01-20 06:57:49 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
in
|
|
|
|
{
|
|
|
|
options = {
|
2023-07-11 05:15:56 +00:00
|
|
|
sane.derived-secrets = with lib; mkOption {
|
2023-01-20 06:57:49 +00:00
|
|
|
type = types.attrsOf secret;
|
|
|
|
default = {};
|
|
|
|
description = ''
|
|
|
|
fs path => secret options.
|
|
|
|
for each entry, we create an item at the given path whose value is deterministic,
|
|
|
|
but also pseudo-random and not predictable by anyone without root access to the machine.
|
|
|
|
as PRNG source we use the host ssh key, and derived secrets are salted based on the destination path.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = {
|
2023-07-11 05:15:56 +00:00
|
|
|
sane.fs = lib.mapAttrs (path: c: {
|
2023-07-08 11:14:55 +00:00
|
|
|
generated.command = [
|
2023-07-08 10:56:24 +00:00
|
|
|
"${hash-path-with-salt}/bin/hash-path-with-salt"
|
|
|
|
path
|
2023-07-08 11:20:00 +00:00
|
|
|
c.encoding
|
2023-07-11 05:15:56 +00:00
|
|
|
(builtins.toString (c.len * 2))
|
2023-07-08 10:56:24 +00:00
|
|
|
];
|
2023-10-17 01:16:08 +00:00
|
|
|
generated.acl.mode = c.acl.mode;
|
2023-01-20 06:57:49 +00:00
|
|
|
}) cfg;
|
|
|
|
};
|
|
|
|
}
|