Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions modules/age-home.nix
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,12 @@ with lib; let
}
'';

enabledSecrets = lib.filter (s: s.enable) (builtins.attrValues cfg.secrets);

installSecrets = builtins.concatStringsSep "\n" (
["echo '[agenix] decrypting secrets...'"]
++ testIdentities
++ (map installSecret (builtins.attrValues cfg.secrets))
++ (map installSecret enabledSecrets)
++ [cleanupAndLink]
);

Expand All @@ -97,6 +99,11 @@ with lib; let
...
}: {
options = {
enable = mkOption {
type = types.bool;
default = true;
description = "Whether to include and decrypt this secret";
};
name = mkOption {
type = types.str;
default = name;
Expand Down Expand Up @@ -155,6 +162,8 @@ with lib; let
'';
in {
options.age = {
enable = mkEnableOption "agenix" // {default = cfg.secrets != {};};

package = mkPackageOption pkgs "age" {};

secrets = mkOption {
Expand Down Expand Up @@ -200,7 +209,7 @@ in {
};
};

config = mkIf (cfg.secrets != {}) {
config = mkIf cfg.enable {
assertions = [
{
assertion = cfg.identityPaths != [];
Expand Down
16 changes: 13 additions & 3 deletions modules/age.nix
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,12 @@ with lib; let
}
'';

enabledSecrets = lib.filter (s: s.enable) (builtins.attrValues cfg.secrets);

installSecrets = builtins.concatStringsSep "\n" (
["echo '[agenix] decrypting secrets...'"]
++ testIdentities
++ (map installSecret (builtins.attrValues cfg.secrets))
++ (map installSecret enabledSecrets)
++ [cleanupAndLink]
);

Expand All @@ -126,11 +128,18 @@ with lib; let
chownSecrets = builtins.concatStringsSep "\n" (
["echo '[agenix] chowning...'"]
++ [chownMountPoint]
++ (map chownSecret (builtins.attrValues cfg.secrets))
++ (map chownSecret enabledSecrets)
);

secretType = types.submodule ({config, ...}: {
options = {
enable = mkOption {
type = types.bool;
default = true;
description = ''
Whether to include and decrypt this secret
'';
};
name = mkOption {
type = types.str;
default = config._module.args.name;
Expand Down Expand Up @@ -188,6 +197,7 @@ in {
];

options.age = {
enable = mkEnableOption "agenix" // {default = cfg.secrets != {};};
ageBin = mkOption {
type = types.str;
default = "${pkgs.age}/bin/age";
Expand Down Expand Up @@ -252,7 +262,7 @@ in {
};
};

config = mkIf (cfg.secrets != {}) (mkMerge [
config = mkIf cfg.enable (mkMerge [
{
assertions = [
{
Expand Down
Loading