encrypt secret.nix with git-crypt

This commit is contained in:
Dmitriy Kholkin 2020-08-04 01:44:50 +04:00
parent f3eda5575e
commit 1565ee0a23
3 changed files with 15 additions and 6 deletions

1
.gitattributes vendored
View File

@ -1 +1,2 @@
* text=auto eol=lf * text=auto eol=lf
secret.nix filter=git-crypt diff=git-crypt

View File

@ -2,17 +2,22 @@
with lib; with lib;
with types; with types;
let let
secret = description:
mkOption {
inherit description;
type = nullOr str;
};
mkCredOption = service: extra: mkCredOption = service: extra:
mkOption { mkOption {
description = "Credentials for ${service}"; description = "Credentials for ${service}";
type = nullOr (submodule { type = nullOr (submodule {
options = { options = {
user = mkOption { user = mkOption {
type = string; type = str;
description = "Username for ${service}"; description = "Username for ${service}";
}; };
password = mkOption { password = mkOption {
type = string; type = str;
description = "Password for ${service}"; description = "Password for ${service}";
}; };
} // extra; } // extra;
@ -21,17 +26,20 @@ let
in rec { in rec {
options.secrets = { options.secrets = {
wireguard = mkOption { wireguard = mkOption {
type = attrs;
description = "Wireguard conf"; description = "Wireguard conf";
type = attrs;
}; };
windows-samba = mkCredOption "samba on windows" { }; windows-samba = mkCredOption "samba on windows" { };
linux-samba = mkCredOption "samba on linux" { }; linux-samba = mkCredOption "samba on linux" { };
spotify = mkCredOption "Spotify" { }; spotify = mkCredOption "Spotify" { };
}; };
config = let config = let
unlocked = import (pkgs.runCommand "check-secret" { }
"set +e; grep -qI . ${../secret.nix}; echo $? > $out") == 0;
secretnix = import ../secret.nix; secretnix = import ../secret.nix;
secrets = if isNull secretnix then secrets = if !unlocked || isNull secretnix then
mapAttrs (n: v: null) options.secrets builtins.trace "secret.nix locked, building without any secrets"
(mapAttrs (n: v: null) options.secrets)
else else
secretnix; secretnix;
in { inherit secrets; }; in { inherit secrets; };

Binary file not shown.