nyx/modules/flake/lib/secrets.nix

97 lines
1.7 KiB
Nix
Raw Normal View History

2025-01-27 14:03:42 +02:00
{inputs}: let
inherit (inputs) self;
2025-01-27 14:03:42 +02:00
/*
*
Create secrets for use with `agenix`.
2025-01-27 14:03:42 +02:00
# Arguments
2025-01-27 14:03:42 +02:00
- [file] the age file to use for the secret
- [owner] the owner of the secret, this defaults to "root"
- [group] the group of the secret, this defaults to "root"
- [mode] the permissions of the secret, this defaults to "400"
2025-01-27 14:03:42 +02:00
# Type
2025-01-27 14:03:42 +02:00
```
mkSecret :: (String -> String -> String -> String) -> AttrSet
```
2025-01-27 14:03:42 +02:00
# Example
2025-01-27 14:03:42 +02:00
```nix
mkSecret { file = "./my-secret.age"; }
=> {
file = "./my-secret.age";
owner = "root";
group = "root";
mode = "400";
}
```
*/
2025-01-27 14:03:42 +02:00
mkSecret = {
file,
owner ? "root",
group ? "root",
mode ? "400",
...
}: {
file = "${self}/secrets/${file}.age";
inherit owner group mode;
};
2025-01-27 14:03:42 +02:00
/*
*
A light wrapper around mkSecret that allows you to specify the output path
2025-01-27 14:03:42 +02:00
# Arguments
2025-01-27 14:03:42 +02:00
- [file] the age file to use for the secret
- [owner] the owner of the secret, this defaults to "root"
- [group] the group of the secret, this defaults to "root"
- [mode] the permissions of the secret, this defaults to "400"
- [path] the path to output the secret to
2025-01-27 14:03:42 +02:00
# Type
2025-01-27 14:03:42 +02:00
```
mkSecretWithPath :: (String -> String -> String -> String -> String) -> AttrSet
```
2025-01-27 14:03:42 +02:00
# Example
2025-01-27 14:03:42 +02:00
```nix
mkSecret { file = "./my-secret.age"; path = "/etc/my-secret"; }
=> {
file = "./my-secret.age";
path = "/etc/my-secret";
owner = "root";
group = "root";
mode = "400";
}
```
*/
2025-01-27 14:03:42 +02:00
mkSecretWithPath = {
file,
path,
owner ? "root",
group ? "root",
mode ? "400",
...
}:
mkSecret {
inherit
file
owner
group
mode
;
}
// {
inherit path;
};
2025-01-27 14:03:42 +02:00
in {
inherit mkSecret mkSecretWithPath;
}