2019-01-03 14:33:38 -07:00
|
|
|
# Functions for working with NixOps keys.
|
2019-01-04 11:17:40 -07:00
|
|
|
{ lib, ... }:
|
2019-01-03 14:33:38 -07:00
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
# Where NixOps stores keys:
|
|
|
|
keyDirectory = "/run/keys/";
|
|
|
|
|
|
|
|
# Generate a service name:
|
|
|
|
mkServiceName = path:
|
|
|
|
replaceStrings ["/"] ["-"]
|
|
|
|
(removePrefix keyDirectory path + "-key.service");
|
|
|
|
|
|
|
|
funcs = rec {
|
|
|
|
|
|
|
|
/* Test to see if a file path is a NixOps managed key.
|
|
|
|
|
|
|
|
Example:
|
|
|
|
isKeyFile "/run/keys/foo"
|
|
|
|
=> true
|
|
|
|
isKeyFile "/etc/passwd"
|
|
|
|
=> false
|
|
|
|
*/
|
|
|
|
isKeyFile = path:
|
|
|
|
if path == null
|
|
|
|
then false
|
|
|
|
else hasPrefix keyDirectory path;
|
|
|
|
|
|
|
|
/* Returns an array containing a systemd service name that can be
|
|
|
|
used to add a 'wants' or 'after' entry for a NixOps key.
|
|
|
|
|
|
|
|
Example:
|
|
|
|
keyService "/run/keys/foo"
|
|
|
|
=> ["foo.service"]
|
|
|
|
keyService "/etc/passwd"
|
|
|
|
=> []
|
|
|
|
*/
|
|
|
|
keyService = path: optional (isKeyFile path) (mkServiceName path);
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
in funcs
|