-
Notifications
You must be signed in to change notification settings - Fork 141
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Emit plain file when key is empty #520
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -708,6 +708,44 @@ This is how it can be included in your `configuration.nix`: | |||
} | ||||
``` | ||||
|
||||
## Emit plain file for yaml and json formats | ||||
|
||||
By default, sops-nix extracts a single key from yaml and json files. If you | ||||
need the plain file instead of extracting a specific key from the input document, | ||||
you can set `key` to an empty string. | ||||
|
||||
For example, the input document `my-config.yaml` likes this: | ||||
|
||||
```yaml | ||||
my-secret1: ENC[AES256_GCM,data:tkyQPQODC3g=,iv:yHliT2FJ74EtnLIeeQtGbOoqVZnF0q5HiXYMJxYx6HE=,tag:EW5LV4kG4lcENaN2HIFiow==,type:str] | ||||
my-secret2: ENC[AES256_GCM,data:tkyQPQODC3g=,iv:yHliT2FJ74EtnLIeeQtGbOoqVZnF0q5HiXYMJxYx6HE=,tag:EW5LV4kG4lcENaN2HIFiow==,type:str] | ||||
sops: | ||||
kms: [] | ||||
gcp_kms: [] | ||||
azure_kv: [] | ||||
hc_vault: [] | ||||
... | ||||
``` | ||||
|
||||
This is how it can be included in your NixOS module: | ||||
|
||||
```nix | ||||
{ | ||||
sops.secrets.my-config = { | ||||
format = "yaml"; | ||||
sopsFile = ./my-config.yaml; | ||||
key = ""; | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||
}; | ||||
} | ||||
``` | ||||
|
||||
Then, it will be mounted as `/run/secrets/my-config`: | ||||
|
||||
```yaml | ||||
my-secret1: hello | ||||
my-secret2: hello | ||||
``` | ||||
|
||||
## Use with home manager | ||||
|
||||
sops-nix also provides a home-manager module. | ||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,11 +15,12 @@ let | |
|
||
key = lib.mkOption { | ||
type = lib.types.str; | ||
default = name; | ||
default = if cfg.defaultSopsKey != null then cfg.defaultSopsKey else name; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also here, can you not just set the format to "binary" on a per secret base? |
||
description = '' | ||
Key used to lookup in the sops file. | ||
No tested data structures are supported right now. | ||
This option is ignored if format is binary. | ||
"" means whole file. | ||
''; | ||
}; | ||
|
||
|
@@ -132,6 +133,16 @@ in { | |
''; | ||
}; | ||
|
||
defaultSopsKey = mkOption { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Currently I don't have a better name but defaultSopsKey sounds very confusing because it's quite overloaded as we have private / public keys everywhere. One has to reach out fo the description to figure out what it's for. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For your usecase, do you actually need this option?
|
||
type = lib.types.nullOr lib.types.str; | ||
default = null; | ||
description = '' | ||
Default key used to lookup in all secrets. | ||
This option is ignored if format is binary. | ||
"" means whole file. | ||
''; | ||
}; | ||
|
||
validateSopsFiles = lib.mkOption { | ||
type = lib.types.bool; | ||
default = true; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.