96 Commits
Author SHA1 Message Date
Florian Klink 633f52c08e nixos/acme: remove unused symbols 2026-06-21 23:47:29 +03:00
Florian Klink 78d07871f5 nixos/acme: also allow _PATH-suffixed credential files
The acmedns backend consumes a ACME_DNS_STORAGE_PATH environment
variable.

Upstream does treat this file as mutable (if you create or delete
accounts through the CLI, it would update it. We don't do this in our
module).

But the possibility for edits is probably why they didn't go with
`ACME_DNS_CONFIG` env var for the contents (as they'd be read-only), or
a `ACME_DNS_CONFIG_FILE`. (And the fact that a
`ACME_DNS_STORAGE_PATH_FILE` env var with questionable usability exists
is due to this logic being generic for most env vars).

So instead of fighting upstream over this, let's simply make our module
assertion also accept `_PATH` suffixes for `credentialFiles`.

Fixes #344684.
2026-06-21 23:47:29 +03:00
znmz ff1f398de0 treewide: fix typos in all markdown files 2026-05-17 13:02:47 +03:00
Martin WeineltandGitHub 8eff708f20 nixos/acme: improve webroot handling (#510615) 2026-05-13 13:59:17 +00:00
Andrew Marshall 7c34ac4769 nixos/acme: fix incorrectly using mkRenamedOptionModule in submodule
Per https://github.com/NixOS/nixpkgs/issues/96006, this does not work as
expected.

The warning trace will be emitted regardless of whether the option is
set, rendering it pointless. It does not work at the top-level either
(i.e. as `"security" "acme" "defaults" "credentialsFile"`), As such,
remove it entirely.
2026-04-21 10:47:22 -04:00
Linus Heckemann d25d639031 nixos/acme: remove scripted webroot creation
Situations where systemd-tmpfiles rules aren't applied but
acme-$name.service is rerun are quite unlikely, so it should be fine to
remove the mkdir completely.
2026-04-16 16:42:01 +02:00
Linus Heckemann a86d6ed9b1 nixos/acme: make webroot world-readable at creation
Up to now, the webroot mechanism wasn't usable without extra steps
when the certificate was not intended for the web server. In my case,
I wanted to obtain a certificate for use in other services from a
private CA, but validate via a webroot served by nginx. The (sensibly!)
restrictive umask of acme-$name.service led to the webroot being created
with o-rx permissions, which meant that nginx could not serve the
webroot and the certificate could not be obtained.

This retains the mkdir invocation as a best-effort attempt to create the
webroot if for example the state has been cleared since systemd-tmpfiles
setup, but relies primarily on systemd-tmpfiles to create the webroots
with appropriate permissions.
2026-04-16 16:36:29 +02:00
Franz PletzandGitHub 3f66adff44 nixos/acme: drop email requirement (#489983) 2026-03-22 11:53:08 +00:00
Franz PletzandGitHub 941dfcd183 nixos/acme: add compat for IP SANs to minica fallback (#479212) 2026-03-22 11:38:37 +00:00
Franz PletzandGitHub fa020b792e nixos/acme: default to dynamic renewal days (#479209) 2026-03-22 11:36:48 +00:00
Silvan MosbergerandGitHub 046203875c ci: module maintainer review requests; nixos/modules: init meta.teams (#499596) 2026-03-13 17:51:21 +00:00
Janne HeßandGitHub e91b6d2274 nixos/acme: Make the maximum jitter configurable (#479084) 2026-03-13 17:29:09 +00:00
Silvan Mosberger b513ab8192 Reapply "ci: module maintainer review requests; nixos/modules: init meta.teams"
This reverts commit 2cc2e0225f.
2026-03-13 16:53:28 +01:00
Martin Weinelt 633ede5af6 nixos/acme: default to dynamic renewal days
With Lego since 4.25.0 instead of --days we can pass --dynamic to pick
the renewal date based on a fraction of its total validity duration.

This provides a reasonable default that accomodates varying certificate
validy durations we're going to be seeing through the profile option and
LE's plans to reduce the default validity duration in multiple steps down
to 45 days in 2028.

This changes changes the default valid duration to null to enable dynamic
renewal calculation. To that end the expiration skip function gained the
ability to calculate the total and remaining duration and to apply the
correct remainder based on the certificates total duration.
2026-03-09 23:47:12 +01:00
Silvan MosbergerandGitHub 2cc2e0225f Revert "ci: module maintainer review requests; nixos/modules: init meta.teams" 2026-03-06 08:41:24 +01:00
Silvan Mosberger dbb164c759 nixos/modules: Use meta.teams over meta.maintainers = lib.teams.*.members
This allows getting the team itself requested for a review instead of
the individual members
2026-03-02 10:59:09 +01:00
Martin Weinelt e65f8ef106 nixos/acme: drop email requirement
Let's Encrypt does not require email addreses any longer, so we should
allow users not to provide any.

Unsetting the email adress will change the account hash and Lego will
start using a dummy email address instead. The address is hardcoded in
the Lego source code in the userIDPlaceholder constant.

We then verify in tests that changing between no email address and the
placeholder address does not create a new account nor rotate the previous
certificate.

This is supported since Lego 4.30.1.

https://github.com/go-acme/lego/commit/bc163db9edd23bbfc3521086c0b570f468b9a87b
2026-02-16 20:53:41 +01:00
pvgoranandGitHub 014d5dd8f1 modules/acme: fix typo in documentation 2026-01-20 15:41:12 +07:00
Bjørn Forsman c98cf6835b nixos/acme: fix ReadWritePaths for acme-${domain}.service
Currently ReadWritePaths is only sufficiently specificed for
acme-order-renew-${domain}.service, and not acme-${domain}.service. This
results in service failure if specifying the webroot outside of
/var/lib/acme, for example /var/www/challenges:

  acme-example.com-start[1379]: + mkdir -p /var/www/challenges//.well-known/acme-challenge
  acme-example.com-start[1382]: mkdir: cannot create directory ‘/var/www/challenges//.well-known’: Read-only file system
  systemd[1]: acme-example.com.service: Main process exited, code=exited, status=1/FAILURE

Fix it by adding the webroots to ReadWritePaths in the common
serviceConfig, where it can affect both acme-order-renew-${domain}.service
AND acme-${domain}.service.

Avoid adding subdirs of existing ReadWritePaths entries, because
otherwise systemd will fail to set up the services, for example:

  acme-zeroconf.example.test.service: Failed to set up mount namespacing: /run/acme: No such file or directory

(Confusingly, the path shown in the error message isn't necessarily
related to the problematic path.)
2026-01-16 17:52:21 +01:00
NAHO a2ed7e8d88 nixos: remove optional builtins prefixes from prelude functions
Remove optional builtins prefixes from prelude functions by running:

    builtins=(
      abort
      baseNameOf
      break
      derivation
      derivationStrict
      dirOf
      false
      fetchGit
      fetchMercurial
      fetchTarball
      fetchTree
      fromTOML
      import
      isNull
      map
      null
      placeholder
      removeAttrs
      scopedImport
      throw
      toString
      true
    )

    fd \
      --exclude doc/manual/release-notes \
      --type file \
      . \
      nixos \
      --exec-batch sed --in-place --regexp-extended "
        s/\<builtins\.($(
          printf '%s\n' "${builtins[@]}" |
            paste --delimiter '|' --serial -
        ))\>/\1/g
      "

    nix fmt
2026-01-15 16:07:55 +01:00
Martin Weinelt 91b8ad76e0 nixos/acme: Make the maximum jitter configurable
Extracts the fixed 24h random delay into a configurable option suitable
for other profiles, that require different renew intervals.

With the introduction of LE's shortlived profile a fixed random delay
does not cut it anymore, as it will delay short renew intervals by up
to a day before they are run. In an ideal world we could make the delay
proportional to the renew interval, but the `OnCalendar=` format is a bit
too complicated.
2026-01-12 03:28:27 +01:00
Martin Weinelt 0d0844ca64 nixos/acme: add compat for IP SANs to minica fallback
With minica we need to pass domain names and IP addresses separately.
2026-01-12 03:13:37 +01:00
Defelo d57e9c1cfa nixos/acme: add profile option 2025-12-04 20:09:38 +01:00
Wolfgang Walther c283f32d29 treewide: remove unused with
Auto-fixed by nixf-diagnose.
2025-10-05 10:50:41 +02:00
Christian Theune 2c111ce343 nixos/acme: update release notes and documentation 2025-08-13 14:34:53 +02:00
Christian Theune 98ecc9035d nixos/acme: switch concurrency limit to a runtime-based implementation
The previous implementation caused triggers on many units when adding
or removing certificates because the baked-in lock file assignments
changed.
2025-08-08 16:28:57 +02:00
Christian Theune 2d0a489125 nixos/acme: improve scalability - reduce superfluous unit activations
The previous setup caused all renewal units to be triggered upon
ever so slight changes in config. In larger setups (100+ certificates)
adding a new certificate caused high system load and/or large memory
consumption issues. The memory issues are already a alleviated with
the locking mechanism. However, this then causes long delays upwards
of multiple minutes depending on individual runs and also caused
superfluous activations.

In this change we streamline the overall setup of units:

1. The unit that other services can depend upon is 'acme-{cert}.service'.
We call this the 'base unit'. As this one as `RemainAfterExit` set
the `acme-finished-{cert}` targets are not required any longer.

2. We now always generate initial self-signed certificates to simplify
the dependency structure. This deprecates the `preliminarySelfsigned`
option.

3. The `acme-order-renew-{cert}` service gets activated after the base
unit and services using certificates have started and performs all acme
interactions. When it finishes others services (like web servers) will
be notified through the `reloadServices` option or they can use
`wantedBy` and `after` dependencies if they implement their own reload
units.

The renewal timer also triggers this unit.

4. The timer unit is explicitly blocked from being started by s-t-c.

5. Permission management has been cleaned up a bit: there was an
   inconsistency between having the .lego files set to 600 vs 640
   on the exposed side. This is unified to 640 now.

6. Exempt the account target from being restarted by s-t-c. This will
   happen automatically if something relevant to the account changes.
2025-08-08 16:28:42 +02:00
Wolfgang Walther 5a0711127c treewide: run nixfmt 1.0.0 2025-07-24 13:55:40 +02:00
Wolfgang Walther 62fe016519 treewide: run treefmt with mdcr/nixfmt 2025-07-24 13:52:31 +02:00
C0D3 M4513R 754412b4ae acme: Add csr option
Signed-off-by: C0D3 M4513R <28912031+C0D3-M4513R@users.noreply.github.com>
2025-05-16 11:45:54 +02:00
Silvan Mosberger 374e6bcc40 treewide: Format all Nix files
Format all Nix files using the officially approved formatter,
making the CI check introduced in the previous commit succeed:

  nix-build ci -A fmt.check

This is the next step of the of the [implementation](https://github.com/NixOS/nixfmt/issues/153)
of the accepted [RFC 166](https://github.com/NixOS/rfcs/pull/166).

This commit will lead to merge conflicts for a number of PRs,
up to an estimated ~1100 (~33%) among the PRs with activity in the past 2
months, but that should be lower than what it would be without the previous
[partial treewide format](https://github.com/NixOS/nixpkgs/pull/322537).

Merge conflicts caused by this commit can now automatically be resolved while rebasing using the
[auto-rebase script](https://github.com/NixOS/nixpkgs/tree/8616af08d915377bd930395f3b700a0e93d08728/maintainers/scripts/auto-rebase).

If you run into any problems regarding any of this, please reach out to the
[formatting team](https://nixos.org/community/teams/formatting/) by
pinging @NixOS/nix-formatting.
2025-04-01 20:10:43 +02:00
K900andGitHub b157c03c40 nixos/tests/acme: Refactor test suite (#378705) 2025-02-26 10:29:20 +03:00
K900andGitHub 62b5275700 nixos/acme: Refactor setup process (#355087) 2025-02-26 10:29:09 +03:00
Lucas Savva 229640ed3a nixos/tests/acme: Refactor test suite
Split tests up based on certain use cases:

- http01-builtin: Tests most functionality of the core module, such
 as the systemd and hashing components, whilst utilising lego's built
 in http01 resolution mechanis.
- dns01: Tests only that DNS01 renewal works as expected.
- nginx: Tests nginx compatability
- httpd: Tests httpd compatability
- caddy: Tests caddy compatability
2025-02-22 23:58:29 +00:00
Lucas Savva 84af416af6 nixos/acme: Refactor setup process
Over time, we added a lot of setup services to the ACME module, namely:

- acme-selfsigned-ca.service: Creates the selfsigned CA certificates
 used to generate selfsigned certs for each configured cert.
- acme-fixperms.service: Ensures permissions correctness on certs after
 system configuration changes.
- acme-lockfiles.service: Create lockfiles used to implement
 maxConcurrentRenewals.

These numerous setup services complicated the dependency chain for any
cert renewal, and also made it difficult to track responsibility for
specific setup steps, for example, creating /var/lib/acme or setting
permissions of shared folders.

This change proposes a new acme-setup.service which encapsulates the
functionality of the previous 3 services into one. The service is still
defined in 3 separate chunks (using lib.mkMerge) which allows us to
keep a logical separation between each step and preserve some
optionality in the features.

The result is a generally simplified definition of systemd unit
dependencies and an obvious entrypoint for future setup extensions.
2025-02-22 21:14:56 +00:00
Maximilian BoschandGitHub dda82d9eef Merge: nixos/acme: fix account creation service ordering (#355054) 2025-02-19 21:17:41 +01:00
ThinkChaos 1e8e314fdb nixos/acme: fix cert ownership assert message
Handle the case where a service has no `User` defined in the message
in addition to the assertion itself.
2024-12-05 20:38:45 -05:00
misuzuandGitHub f608d1b3bc nixos/acme: fix cert ownership assert for string SupplementaryGroups (#356064) 2024-12-01 16:31:01 +02:00
Franz PletzandGitHub 6473ecdc08 nixos/acme: Set /var/lib/acme permissions to 755 (#353659) 2024-11-27 14:51:32 +01:00
Malte Voos d9bf91700e nixos/acme: make address families in systemd service less restrictive
This change is to support LEGO's capability to spawn an external process that
solves the DNS-01 challenge. In particular, this enables a setup where LEGO
runs a shell script that uses nsd-control to add an appropriate zone to a
local NSD instance.
2024-11-19 01:40:59 +01:00
ThinkChaos b2e7be76ba nixos/acme: fix cert ownership assert for string SupplementaryGroups 2024-11-14 19:19:46 -05:00
K900andGitHub 871087c18d nixos/acme: do not limit credentials functionality to DNS/S3 config (#348344) 2024-11-11 01:43:53 +03:00
ThinkChaos 2f52ab637c nixos/acme: fix account creation service ordering
If the chosen leader was an HTTP service, then the web server would be
both before and after the server.
2024-11-09 14:29:05 -05:00
ThinkChaos 1bd7f1374d nixos/acme: use non deprecated CLI flag for dnsPropagationCheck 2024-11-07 20:19:12 -05:00
ThinkChaos 3c2e82337d nixos/web-servers: assert ACME cert access via service user and groups
Allows giving access using SupplementaryGroups.
2024-11-07 20:19:12 -05:00
Yuriy Taraday 64a6e8292a nixos/acme: Set /var/lib/acme permissions to 755
It was being created with the default home permissions of 700, and then
set to 755 at runtime by something either some script or systemd as
part of service startup.

It worked fine without sysusers, but when it's enabed with:

    systemd.sysusers.enable = true;

systemd-tmpfiles is resetting permissions on each activation, which
breaks, for example, nginx reload, because it cannot load certificates
anymore, because it doesn't have any access to `/var/lib/acme`.

Fix this by setting `homeMode = "755";` explicitely so that it's set to
the final value from the beginning.
2024-11-04 16:04:56 +01:00
Piotr Dobrowolski 6e6fc7ca26 nixos/acme: do not limit credentials functionality to DNS/S3 config 2024-10-13 22:48:14 +02:00
Peder Bergebakken Sundt 3100acba08 treewide: \xc2\xa0 ->
I have no idea what this escape sequence even is, but it breaks the nix parser with cryptic errors if not used in a comment.
A friend let me know MacOS is prone to input weird spaces, not sure if that is the source.

Candidates were located and created with:

    chr="$(echo -e '\xc2\xa0')"; rg -F "$chr" -l | xe sd -F "$chr" " "

There are some examples left, most being example output from `tree` in various markdown documents, some patches which we can't really touch, and `pkgs/tools/nix/nixos-render-docs/src/tests/test_commonmark.py` which I'm not sure if should be addressed
2024-10-02 15:33:06 +02:00
phaerandr-vdp 22794b93e0 security/acme: shellcheck fixes 2024-09-08 12:29:58 +02:00
Felix Buehler 03a0f9debe nixos/security.acme: remove with lib; 2024-09-05 00:28:18 +02:00