Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Home Manager Configuration Options

security.nix-secrets.enable

Whether to enable nix-secrets integration.

Type: boolean

Default:

false

Example:

true

Declared by:

security.nix-secrets.package

nix-secrets package for the CLI.

It can also be installed into the system by enabling security.nix-secrets.installPackage, which is enabled by default.

Type: package

Default:

<derivation nix-secrets-0.9.0>

Declared by:

security.nix-secrets.activate.enable

Whether to enable automatic activation of nix-secrets secrets and templates.

Type: boolean

Default:

true

Example:

false

Declared by:

security.nix-secrets.activate.package

The nix-secrets package used in security.nix-secrets.activate.command. This is a dedicated activation package, separate from the regular nix-secrets CLI.

Type: package

Default:

<derivation nix-secrets-activate-0.9.0>

Declared by:

security.nix-secrets.activate.command

Command used to activate nix-secrets secrets and templates.

The function receives whether it should activate secrets and templates with neededForUsers enabled and returns the command to execute.

Type: function that evaluates to a(n) string

Default:

neededForUsers: "${lib.getExe cfg.activate.package} ${cfg.manifest { }} --needed-for-users ${lib.boolToString neededForUsers}"

Declared by:

security.nix-secrets.activate.method

Method used to activate nix-secrets secrets and templates.

The systemd method uses systemd services, while the launchd method uses the launchd agents.

Type: one of “systemd”, “launchd”

Default:

if pkgs.stdenv.hostPlatform.isLinux
then "systemd"
else "launchd"

Example:

"launchd"

Declared by:

security.nix-secrets.baseDir

Default directory where secrets and templates are mounted.

Each secret or template without a custom path is placed under this directory.

Type: string

Default:

"${if lib.hasPrefix "~/" config.xdg.dataHome then "${config.home.homeDirectory}/${lib.removePrefix "~/" config.xdg.dataHome}" else config.xdg.dataHome}/nix-secrets"

Declared by:

security.nix-secrets.baseForUsersDir

Default directory where secrets and templates with neededForUsers = true are mounted.

Serves the same purpose as baseDir but for the neededForUsers activation phase.

Type: string

Default:

"${cfg.baseDir}-for-users"

Declared by:

security.nix-secrets.checks.missingSecrets.enable

Whether to check that every enabled secret has a corresponding encrypted file.

Type: boolean

Default:

!cfg.ciMode.enableDangerously || !cfg.ciMode.usePlaceholders

Declared by:

security.nix-secrets.ciMode.enableDangerously

Whether to enable insecure CI mode options.

This option enables features that may weaken secret protection and should only be used in disposable CI environments or isolated test environments.

Type: boolean

Default:

false

Declared by:

security.nix-secrets.ciMode.debugPackage

Whether to use a debug build of security.nix-secrets.package.

The debug build enables additional logging.

Type: boolean

Default:

false

Declared by:

security.nix-secrets.ciMode.storePathIdentities

Whether to allow identity files stored in the Nix store.

Identity files should not normally be stored in the Nix store because its contents are world-readable and therefore unsuitable for keeping confidential information.

Type: boolean

Default:

false

Declared by:

security.nix-secrets.ciMode.usePlaceholders

Whether to use placeholder values instead of decrypted secrets.

This is intended for CI and testing environments where real secret values are not available or should not be used.

Type: boolean

Default:

false

Declared by:

security.nix-secrets.defaultGroup

Default group for secrets and templates.

May be specified as either a group name or a numeric GID.

Applied to both unless overridden by security.nix-secrets.secrets.<name>.group or security.nix-secrets.templates.<name>.group.

Type: signed integer or string

Default:

config._module.specialArgs.osConfig.users.users.${config.home.username}.group or (throw "cannot determine the default group in standalone Home Manager: set `security.nix-secrets.defaultGroup` explicitly")
`

Example:

"users"

Declared by:

security.nix-secrets.defaultMode

Default permissions for secrets and templates.

Applied to both unless overridden by security.nix-secrets.secrets.<name>.mode or security.nix-secrets.templates.<name>.mode.

Type: string

Default:

"0400"

Example:

"0660"

Declared by:

security.nix-secrets.defaultOwner

Default owner for secrets and templates.

May be specified as either a user name or a numeric UID.

Applied to both unless overridden by security.nix-secrets.secrets.<name>.owner or security.nix-secrets.templates.<name>.owner.

Type: signed integer or string

Default:

config.home.username

Example:

"forgejo"

Declared by:

security.nix-secrets.defaultRecipients

Recipients automatically added to every secret.

Entries may be age recipients, SSH public keys, or aliases defined in security.nix-secrets.recipientAliases.

To override this list for a specific secret, use lib.mkForce.

Type: list of string

Default:

[ ]

Example:

[ config.networking.hostname "someAlias" "age1nr6qkv2y49g5pvkswskyy3nzazsp9wy3gxyxzxlutqgq2ejec4xqpmjzh5" ]

Declared by:

security.nix-secrets.extraPackages

Additional packages added to PATH by the default values of the security.nix-secrets.package and security.nix-secrets.activate.package options.

This is primarily intended for age plugins such as pkgs.age-plugin-yubikey.

Type: list of package

Default:

[
  <derivation age-1.3.2>
]

Example:

[ pkgs.age-plugin-yubikey ]

Declared by:

security.nix-secrets.generationsDir

Directory where generations are stored for the standard activation phase.

A generation holds the set of secrets and templates that were active at a given point in time, allowing rollback to a previous state.

Type: string

Default:

"{{RUNTIME_DIR}}/nix-secrets.d"

Declared by:

security.nix-secrets.generationsForUsersDir

Directory where generations are stored for the neededForUsers activation phase.

A generation holds the set of secrets and templates that were active at a given point in time, allowing rollback to a previous state.

Type: string

Default:

"{{RUNTIME_DIR}}/nix-secrets-for-users.d"

Declared by:

security.nix-secrets.generators

Predefined secret generators referenced by name from security.nix-secrets.secrets.<name>.generator.

Each generator is a function that accepts an attribute set of arguments and returns a package or a generator specification.

A generator without arguments can be referenced by name:

generator = "uuid";

A generator with arguments can be referenced using an attribute set:

generator.uuid = {
  count = 5;
  raw = true;
};

Type: attribute set of ((function that evaluates to a(n) (string or package or (attribute set))) or (string or function that evaluates to a(n) (string or package or (attribute set))) convertible to it)

Default:

{ }

Example:

{
  password =
    { length ? 32 }:
    pkgs.writeShellScriptBin "generate-password" ''
      head -c ${toString length} /dev/urandom | base64
    '';

  uuid = {}: pkgs.writeShellScriptBin "generate-uuid" ''
    uuidgen
  '';
}

Declared by:

security.nix-secrets.identityPaths

Paths to identity files used for secret encryption and decryption.

For security reasons, identity files are kept outside of the Nix store.

Defaults to the identity path "${config.xdg.configHome}/nix-secrets/identities.txt".

Type: list of path not in the Nix store

Default:

[ "${config.xdg.configHome}/nix-secrets/identities.txt" ]

Example:

[
  "/var/lib/nix-secrets/identities.txt"
  "/home/user/keys.txt"
  "/home/user/.ssh/id_ed25519"
]

Declared by:

security.nix-secrets.installPackage

Whether to enable installation of security.nix-secrets.package into environment.systemPackages.

Type: boolean

Default:

true

Example:

false

Declared by:

security.nix-secrets.nixBuildCommand

Command used by the nix-secrets CLI to build the manifest for the security.nix-secrets.manifest option.

The placeholders listed below are replaced by the CLI and escaped as shell arguments:

  • {{versionCli}} - version of the CLI, e.g. "1.0.0",
  • {{isFlake}} - true if --flake was passed, false otherwise,
  • {{path}} - absolute path to the flake (for --flake) or to the configuration file (for --file),
  • {{moduleSystem}} - "nixos", "home-manager" or "nix-darwin"; empty when {{outputName}} is set,
  • {{manifestPath}} - path to the manifest option in config, e.g. "security.nix-secrets.manifest" or home-manager.users.<--home-manager>.security.nix-secrets.manifest,
  • {{manifestArgs}} - JSON-string with arguments for generating the manifest,
  • {{attr}} - attribute in {{path}} to evaluate (for --file only, empty for --flake),
  • {{outputName}} - name of the flake output, e.g. "nixosConfigurations" (for --flake only, empty for --file),
  • {{configurationName}} - name of the configuration in {{outputName}}, i.e. the part after "#" in --flake (for --flake only, empty for --file).

Type: null or string

Default:

"${
  lib.optionalString (config.nix.package or null != null) "${config.nix.package}/bin/"
}nix-build ${../../manifest.nix} --extra-experimental-features flakes --no-out-link --argstr versionNix ${lib.escapeShellArg (builtins.fromTOML (builtins.readFile ../../Cargo.toml)).workspace.package.version} --argstr versionCli {{versionCli}} --arg isFlake {{isFlake}} --argstr path {{path}} --argstr moduleSystem {{moduleSystem}} --argstr manifestPath {{manifestPath}} --argstr manifestArgs {{manifestArgs}} --argstr attr {{attr}} --argstr outputName {{outputName}} --argstr configurationName {{configurationName}}"

Declared by:

security.nix-secrets.recipientAliases

Recipient aliases used when defining secret recipients.

An alias may refer to one or more recipients or to other aliases. Alias references are resolved recursively. Cyclic references result in an evaluation error.

Type: attribute set of ((list of string) or (string or list of string) convertible to it)

Default:

{ }

Example:

{
  all = [
    "pc"
    "server"
  ];
  pc = "age14e2jdmau7tpau9emcn6gmg26vfl0uyf6cfd9lz85jml6ttv9wq2qphps4t";
  server = [
    "age1ls5m8ml8cdu202xakl56lspqrccgln4kfx8q7c6v7qdex92xryhs03v6re"
    "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIEuUsB0HH//1qkvgQMWTEoNd0riZpk+8A5w1Ep2vGKk0"
  ];
}

Declared by:

security.nix-secrets.secrets

Secrets managed by nix-secrets.

Type: attribute set of (submodule)

Default:

{ }

Declared by:

security.nix-secrets.secrets.<name>.enable

Whether to enable this secret.

When this option is set to false, the secret is not included in the resulting manifest, like it does not exist in the first place.

Type: boolean

Default:

true

Example:

false

Declared by:

security.nix-secrets.secrets.<name>.__toString

Internal option allowing the secret to be converted to its templateKey using "${secrets.<name>}".

Type: function that evaluates to a(n) string (read only)

Default:

self: self.templateKey

Example:

"{{NIX_SECRETS-2bb80d537b1da3e38bd30361aa855686bde0eacd7162fef6a25fe97bf527a25b}}"

Declared by:

security.nix-secrets.secrets.<name>.generator

Package used to generate the secret.

Can be either:

  • a derivation,
  • a generator name from config.security.nix-secrets.generators,
  • an attribute set with a single attribute, where the attribute name selects a generator from config.security.nix-secrets.generators and its value is passed to that generator.

Type: null or package or string or (attribute set)

Default:

null

Declared by:

security.nix-secrets.secrets.<name>.group

Group of the file created at path.

May be specified as either a group name or a numeric GID.

Cannot be set when neededForUsers is enabled because users and groups are not available at this stage of activation. In this case, the file group is set to root.

Type: signed integer or string

Default:

cfg.defaultGroup

Example:

"users"

Declared by:

security.nix-secrets.secrets.<name>.isIdentity

Whether to use the decrypted secret content as an identity for decrypting other secrets.

Type: boolean

Default:

false

Example:

true

Declared by:

Whether to symlink the decrypted secret to its path (the recommended default behavior), or write the decrypted secret content directly to that path.

Do not set this option unless you know exactly what you are doing. This option is mainly intended for secrets that must be persisted on disk independently of the nix-secrets activation state.

Type: boolean

Default:

true

Example:

false

Declared by:

security.nix-secrets.secrets.<name>.mode

Permissions of the file created at path.

Type: string

Default:

cfg.defaultMode

Example:

"0660"

Declared by:

security.nix-secrets.secrets.<name>.name

Secret name used as its path in the storage.

For example, the secret named "forgejo/token" is stored as forgejo/token.enc in the storage.

Type: relative path not in the Nix store

Default:

"‹name›"

Example:

"forgejo/token"

Declared by:

security.nix-secrets.secrets.<name>.neededForUsers

Whether the secret must be available before users and groups are created.

Enable this for secrets referenced before or during user creation, such as users.users.<name>.hashedPasswordFile.

Note

Only has an effect in NixOS. Forced to false in other module systems.

Type: boolean

Default:

false

Example:

true

Declared by:

security.nix-secrets.secrets.<name>.owner

Owner of the file created at path.

May be specified as either a user name or a numeric UID.

Cannot be set when neededForUsers is enabled because users and groups are not available at this stage of activation. In this case, the file owner is set to root.

Type: signed integer or string

Default:

cfg.defaultOwner

Example:

"forgejo"

Declared by:

security.nix-secrets.secrets.<name>.path

Path where the decrypted secret will be mounted.

By default, the secret is mounted under “${XDG_RUNTIME_DIR}/nix-secrets/secrets” if on non-Darwin systems, or under “$(getconf DARWIN_USER_TEMP_DIR)/nix-secrets/secrets” on Darwin.

Secrets using the default paths are activated atomically together. When a custom path is specified, secrets are updated individually and atomicity is only guaranteed for each individual secret.

Type: absolute path not in the Nix store

Default:

"${if config.neededForUsers then cfg.baseForUsersDir else cfg.baseDir}/secrets/‹name›"

Example:

"$HOME/.config/forgejo/token"

Declared by:

security.nix-secrets.secrets.<name>.placeholder

Placeholder content used instead of decrypting secret.

This option exists for CI and testing purposes. It replaces the decrypted secret only when security.nix-secrets.ciMode.usePlaceholders is enabled. It must not be used for real secrets.

Type: absolute path or (string or absolute path or package) convertible to it

Default:

"REPLACE WITH YOUR SECRET"

Example:

"insecurePassword"

Declared by:

security.nix-secrets.secrets.<name>.recipients

Recipients allowed to decrypt the secret.

Entries may be age recipients, SSH public keys, or aliases defined in security.nix-secrets.recipientAliases.

Type: list of string

Default:

[ ]

Example:

[
  "alias"
  "age1ls5m8ml8cdu202xakl56lspqrccgln4kfx8q7c6v7qdex92xryhs03v6re"
  "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIEuUsB0HH//1qkvgQMWTEoNd0riZpk+8A5w1Ep2vGKk0"
]

Declared by:

security.nix-secrets.secrets.<name>.reloadUnits

Systemd units to reload when the deployed secret changes.

The units are triggered when nix-secrets deploys the secret to a path that either does not exist yet or whose existing file does not match its decrypted content, permissions, ownership, or isSymlink.

Note

On NixOS this triggers system units. On Home Manager and Hjem it triggers user units. On nix-darwin these options are ignored.

Type: list of string

Default:

[ ]

Example:

[
  "nginx.service"
]

Declared by:

security.nix-secrets.secrets.<name>.restartUnits

Systemd units to restart when the deployed secret changes.

The units are triggered when nix-secrets deploys the secret to a path that either does not exist yet or whose existing file does not match its decrypted content, permissions, ownership, or isSymlink.

Note

On NixOS this triggers system units. On Home Manager and Hjem it triggers user units. On nix-darwin these options are ignored.

Type: list of string

Default:

[ ]

Example:

[
  "nginx.service"
]

Declared by:

security.nix-secrets.secrets.<name>.templateKey

Placeholder string used to reference this secret in templates.

Type: string (read only)

Default:

"{{NIX_SECRETS-${builtins.hashString "sha256" config.name}}}"

Example:

"{{NIX_SECRETS-2bb80d537b1da3e38bd30361aa855686bde0eacd7162fef6a25fe97bf527a25b}}"

Declared by:

security.nix-secrets.storage

Path to the nix-secrets storage.

The path is used by activation scripts and services and must be specified as a path rather than a relative path string. For example, use ./storage instead of "./storage".

For improved security, it is recommended to keep the storage in a private repository and reference it through a flake input.

Type: absolute path

Example:

inputs.my-secrets + /storage

Declared by:

security.nix-secrets.storagePath

Default storage path used by the nix-secrets CLI.

The path must be absolute and outside of the Nix store.

When set, the CLI does not require the --storage argument.

Type: null or absolute path not in the Nix store

Default:

null

Example:

"/etc/nixos/secrets"

Declared by:

security.nix-secrets.templates

Templates managed by nix-secrets.

Type: attribute set of (submodule)

Default:

{ }

Declared by:

security.nix-secrets.templates.<name>.enable

Whether to enable this template.

When this option is set to false, the template is not included in the resulting manifest, like it does not exist in the first place.

Type: boolean

Default:

true

Example:

false

Declared by:

security.nix-secrets.templates.<name>.content

Template content. May be either a string or a path to file.

Secret references can be inserted using security.nix-secrets.secrets.<name>.templateKey or by converting a secret option to a string: "${security.nix-secrets.secrets.<name>}".

References are replaced with the corresponding secret values when the template is activated.

Type: absolute path in the Nix store or (string or absolute path in the Nix store) convertible to it

Example:

''
  NAME="Git Server"
  TURNSTILE_SECRET="''${config.security.nix-secrets.secrets."forgejo/turnstile/secret"}"
  TURNSTILE_SITEKEY="''${config.security.nix-secrets.secrets."forgejo/turnstile/sitekey"}"
''

Declared by:

security.nix-secrets.templates.<name>.group

Group of the file created at path.

May be specified as either a group name or a numeric GID.

Cannot be set when neededForUsers is enabled because users and groups are not available at this stage of activation. In this case, the file group is set to root.

Type: signed integer or string

Default:

cfg.defaultGroup

Example:

"users"

Declared by:

Whether to symlink the decrypted secret to its path (the recommended default behavior), or write the decrypted secret content directly to that path.

Do not set this option unless you know exactly what you are doing. This option is mainly intended for secrets that must be persisted on disk independently of the nix-secrets activation state.

Type: boolean

Default:

true

Example:

false

Declared by:

security.nix-secrets.templates.<name>.mode

Permissions of the file created at path.

Type: string

Default:

cfg.defaultMode

Example:

"0660"

Declared by:

security.nix-secrets.templates.<name>.name

Template name used as part of the default path.

Type: relative path not in the Nix store

Default:

"‹name›"

Example:

"forgejo/env"

Declared by:

security.nix-secrets.templates.<name>.neededForUsers

Whether the template must be available before users and groups are created.

Enable this for templates referenced before or during user creation.

Note

Only has an effect in NixOS. Forced to false in other module systems.

Type: boolean

Default:

false

Example:

true

Declared by:

security.nix-secrets.templates.<name>.owner

Owner of the file created at path.

May be specified as either a user name or a numeric UID.

Cannot be set when neededForUsers is enabled because users and groups are not available at this stage of activation. In this case, the file owner is set to root.

Type: signed integer or string

Default:

cfg.defaultOwner

Example:

"forgejo"

Declared by:

security.nix-secrets.templates.<name>.path

Path where the rendered template will be mounted.

By default, the template is mounted under “${XDG_RUNTIME_DIR}/nix-secrets/templates” if on non-Darwin systems, or under “$(getconf DARWIN_USER_TEMP_DIR)/nix-secrets/templates” on Darwin.

Templates using the default paths are activated atomically together. When a custom path is specified, templates are updated individually and atomicity is only guaranteed for each individual template.

Type: absolute path not in the Nix store

Default:

"${if config.neededForUsers then cfg.baseForUsersDir else cfg.baseDir}/templates/‹name›"

Example:

"$HOME/.config/forgejo/.env"

Declared by:

security.nix-secrets.templates.<name>.reloadUnits

Systemd units to reload when the deployed template changes.

The units are triggered when nix-secrets deploys the template to a path that either does not exist yet or whose existing file does not match its rendered content, permissions, ownership, or isSymlink.

Note

On NixOS this triggers system units. On Home Manager and Hjem it triggers user units. On nix-darwin these options are ignored.

Type: list of string

Default:

[ ]

Example:

[
  "nginx.service"
]

Declared by:

security.nix-secrets.templates.<name>.restartUnits

Systemd units to restart when the deployed template changes.

The units are triggered when nix-secrets deploys the template to a path that either does not exist yet or whose existing file does not match its rendered content, permissions, ownership, or isSymlink.

Note

On NixOS this triggers system units. On Home Manager and Hjem it triggers user units. On nix-darwin these options are ignored.

Type: list of string

Default:

[ ]

Example:

[
  "nginx.service"
]

Declared by: