Commit Graph

68 Commits

Author SHA1 Message Date
Eman Resu
02e0629f57 nixos/lib/systemd-lib: remove optionalAttrs chain 2026-07-15 01:22:39 -04:00
Florian Klink
b62d8df99d nixos/systemd-lib: use structuredAttrs instead of passAsFile for makeUnit (#498934) 2026-05-28 13:55:04 +00:00
sternenseemann
222ed18540 nixos/lib/systemd-lib: make unitNameType work with e.g. Rust regex
The unitNameType regex currently makes the Tvix CI (and likely Snix
in the future) fail since "sysroot-nix-.ro\\x2dstore.mount" will
fail the check since it doesn't interpret the single backslash
as part of the bracket expression.

POSIX doesn't require escaping the backslash in bracket exprs:
> The special characters '.', '*', '[', and '\\' ( <period>, <asterisk>,
> <left-square-bracket>, and <backslash>, respectively) shall lose their
> special meaning within a bracket expression.

However, Rust uses the backslash for escaping in bracket exprs,
so it also needs to be escaped:
> [\[\]]        Escaping in character classes (matching [ or ])

Making the Regex work with both POSIX-like regexes and Rust's regex
syntax is possible in this case, so let's do it.
2026-05-01 18:09:28 +02:00
Stefan Frijters
fc513d020b nixos/systemd-lib: use structuredAttrs instead of passAsFile for makeUnit 2026-05-01 16:47:17 +02:00
Fabian Möller
18d69f6e9d nixos/systemd-networkd: Allow three value variant in ipv6AcceptRAConfig.RouteMetric option 2026-04-07 10:44:36 +02:00
Will Fancher
999004c3c9 nixos/systemd: allow disabling the path default for services (#482045) 2026-02-10 01:03:13 +00:00
quantenzitrone
3e622a5110 nixos: remove references to the xorg namespace
this only creates the usual nixos module rebuilds
2026-01-25 22:58:40 +01:00
Winter M
1312b27c07 nixos/systemd: allow disabling the path default for services
There are times where I want to have services without this default,
especially when writing overrides.
2026-01-20 14:19:02 -05: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
K900
e93c560b79 Merge remote-tracking branch 'origin/master' into staging-next 2025-10-05 12:17:08 +03:00
Wolfgang Walther
91a8fee3aa treewide: remove redundant parentheses
Auto-fixed by nixf-diagnose.
2025-10-05 10:52:03 +02:00
Grimmauld
a27a433370 nixos/lib/systemd: migrate single-section attrsToSection to settingsToSections 2025-08-27 12:38:10 +02:00
Grimmauld
e88c68514d nixos/lib/systemd: introduce settingsToSections 2025-08-27 12:28:40 +02:00
Jeremy Kescher
a1545a073c nixos/systemd: drop kbrequest.target symlink 2025-08-12 22:50:39 +02:00
Will Fancher
570ae8423d nixos/autovt: Pull in autovt@tty1 in Nix, not generateUnits 2025-07-28 14:46:39 -04:00
Wolfgang Walther
5a0711127c treewide: run nixfmt 1.0.0 2025-07-24 13:55:40 +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](8616af08d9/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
Andreas Fuchs
878be9c20b Address review feedback: Attempt to fix wonky indentation 2024-12-18 08:17:04 -05:00
Andreas Fuchs
bf9c6c9861 switch-to-configuration-ng: Better handling of socket-activated units
Previously, if any unit had a socket associated with it, stc-ng
counted it as "socket-activated", meaning that the unit would get
stopped and the socket get restarted. That can wreak havoc on units
like systemd-udevd and systemd-networkd.

Instead, let units set the new flag notSocketActivated, which sets a
boolean on the unit indicating to stc-ng that the unit wants to be
treated like any other non-socket-activated unit instead. That will
stop/start or restart these units on upgrades, without unnecessarily
tearing down any machinery that the system needs to run.
2024-11-27 21:36:09 -05:00
Jack Wilsdon
2223312e3d nixos/networkd: allow byte values to be integers 2024-11-03 18:26:20 +00:00
Will Fancher
a6e54f566a nixos/networkd: support systemd-creds in WireGuard (#346964) 2024-10-15 14:31:27 -04:00
r-vdp
2b224f0e3c nixos/systemd: allow using writeShellApplication for systemd unit scripts 2024-10-08 12:01:48 +02:00
James Atkins
42f5ecde9d nixos/networkd: support systemd-creds in WireGuard
systemd 256 supports network.wireguard.* credentials (https://github.com/systemd/systemd/pull/30826).
Check whether PrivateKey / PresharedKey starts with an @, if so it is a credential.
2024-10-06 18:38:40 -05:00
František Hanzlík
8b4cd01f90 nixos/networkd: allow specifying FirewallMark mask 2024-08-01 22:22:01 +02:00
nikstur
d4a80b6d0c systemd: 255.6 -> 256.2 2024-07-21 06:31:37 -04:00
Maximilian Bosch
c4fd7cf16d nixos/networkd: get rid of *Config attributes in lists
This patch is about removing `wireguardPeerConfig`,
`dhcpServerStaticLeaseConfig` - a.k.a. the
AbstractSingletonProxyFactoryBean of nixpkgs - and friends.

As a former colleague said

> worst abstraction ever

I second that. I've written enough networkd config for NixOS systems so
far to have a strong dislike. In fact, these don't even make sense:
`netdevs.wireguardPeers._.wireguardPeerConfig` will be rendered into
the key `[WireGuardPeer]` and every key from `wireguardPeerConfig` is in
there. Since it's INI, there's no place where sections on the same level
as wireguardPeerConfig fit into. Hence, get rid of it all.

For the transition, using the old way is still allowed, but gives a
warning. I think we could drop this after one release.

The tests of rosenpass and systemd-networkd-dhcpserver-static-leases
were broken on the rev before, hence they were updated, but are still
not building.
2024-05-20 17:26:42 +02:00
Jared Baur
38907ef84d nixos/systemd-lib: fix assertRangeOrOneOf when value is not comparable
We cannot compare non-numerical values to a min or max value in a range.
2024-05-06 10:41:20 -07:00
Florian Klink
5a2d4496d3 Merge pull request #297726 from r-vdp/systemd-unit-names
systemd: add a name option to all systemd units
2024-04-23 12:58:51 +03:00
Ryan Hendrickson
61153af068 Merge pull request #298983 from illustris/mysql
nixos/systemd-lib: fix restart/reloadTriggers when passing paths
2024-04-21 17:45:16 -04:00
illustris
4a9c962aca nixos/systemd-lib: fix restart/reloadTriggers when passing paths
When passing a path to restartTriggers or reloadTriggers, X-Restart/Reload-Triggers
will get populated by the absolute path of the file on the machine where the
config is evaluated. This patch corrects this behavior.
2024-04-21 09:40:17 +05:30
r-vdp
9258f57625 systemd: add a name option to all systemd units
This allows us to set things like dependencies in a way that we can
catch typos at eval time.
So instead of
```nix
systemd.services.foo.wants = [ "bar.service" ];
```
we can write
```nix
systemd.services.foo.wants = [ config.systemd.services.bar.name ];
```
which will throw an error if no such service has been defined.

Not all cases can be done like this (eg template services), but in a lot
of cases this will allow to avoid typos.

There is a matching option on the unit option
(`systemd.units."foo.service".name`) as well.
2024-04-15 11:32:45 +02:00
Astrid Yu
ed854ed0e3 nixos/networkd: add [Bridge] section to netdev conf
This setting was missing from netdev.

This commit additionally adds a test using the new
section, ensuring that STP can be enabled.
2024-04-14 15:16:44 -07:00
nikstur
4c397ea6de systemd-lib: include GPTMaxLabelLength constant 2024-04-08 16:42:25 +02:00
Philip Taron
f290c5901b Avoid top-level with ...; in nixos/lib/systemd-lib.nix 2024-03-27 21:42:17 -07:00
Fabian Möller
f753e58e6e nixos/networkd: allow RoutingPolicyRule port ranges
Linux and Systemd allow port ranges to be used in routing policy rules.

https://www.freedesktop.org/software/systemd/man/latest/systemd.network.html#SourcePort=
2024-03-06 09:11:54 +01:00
Simonas Kazlauskas
34c5cc74a1 systemd: fix propagation of upheldBy option to units 2024-02-29 02:01:24 +02:00
Simonas Kazlauskas
74eeb75af1 systemd: add support for upholds and upheldBy 2024-02-10 13:48:40 +02:00
K900
3d6a5ad604 systemd-lib: fix automount generation after 9fbf82d9cb
This one got missed in the refactor.
2024-01-18 08:33:46 +03:00
Sandro Jäckel
9fbf82d9cb systemd-lib: add Install WantedBy section to make units similar to upstream ones
and make them better grepable
2024-01-02 23:09:03 +01:00
Sandro Jäckel
ae0bbc00e8 systemd-lib: cleanup empty lines in unit files 2023-11-09 02:08:57 +01:00
emilylange
6c7ad5e732 nixos/systemd-lib: fix building of empty unit files
This is a fixup for c1ae82f448.

nix' `passAsFile` does not create empty files for variables that are
`null`.

This results in the following error for units that have no overrides or
content, but are, e.g. `wantedBy`:
`mv: cannot stat '': No such file or directory`.

Minimal reproducer:
`systemd.units.empty.wantedBy = [ "multi-user.target" ];`

This is often necessary when a unit is loaded in via `systemd.packages`.
2023-11-02 01:18:46 +01:00
5aaee9
c1ae82f448 nixos/systemd: fix make unit failed when unit too large 2023-10-31 01:06:37 +08:00
ign0tus
237f7ba7d2 networkd: Allow combinations of WakeOnLan policies
To comply with the systemd.link WakeOnLan[^1] specification, the option
"off" and all other possible policy combinations must be allowed.

[^1]: https://www.freedesktop.org/software/systemd/man/systemd.link.html#WakeOnLan=
2023-09-28 17:04:35 +02:00
Sandro Jäckel
9e5aa81a22 systemd-lib: add name to X-{Reloads,Restart}-Triggers to easily identify to which service/unit/... they belong 2023-09-13 21:03:37 +02:00
nikstur
a662dc8b73 nixos/lib: systemd definition files function
Add a re-usable function that converts an attrset to a directory
containing systemd definition files.
2023-07-26 23:30:08 +02:00
Raito Bezarius
1ca68deebd nixos/networkd: fix netdev MAC addresses asserts
The `||` condition made it fail no matter what because nothing can be none and a proper MAC address.

Thanks to trofi for catching it.
2023-07-20 11:03:46 +02:00
Raito Bezarius
4d38fa043b nixos/networkd: support netdev MAC addresses
According to systemd.netdev manpage:

```
MACAddress=
           Specifies the MAC address to use for the device, or takes the special value "none". When "none", systemd-networkd does not request the MAC address for
           the device, and the kernel will assign a random MAC address. For "tun", "tap", or "l2tp" devices, the MACAddress= setting in the [NetDev] section is
           not supported and will be ignored. Please specify it in the [Link] section of the corresponding systemd.network(5) file. If this option is not set,
           "vlan" device inherits the MAC address of the master interface. For other kind of netdevs, if this option is not set, then the MAC address is
           generated based on the interface name and the machine-id(5).

           Note, even if "none" is specified, systemd-udevd will assign the persistent MAC address for the device, as 99-default.link has
           MACAddressPolicy=persistent. So, it is also necessary to create a custom .link file for the device, if the MAC address assignment is not desired.
```

Therefore, `none` is an acceptable value.
2023-07-04 01:21:35 +02:00
wrvsrx
05129aab01 nixos/lib: save triggers of systemd into nix store 2023-05-11 17:38:54 +08:00
wrvsrx
cc41b47c6f nixos/lib: hash triggers after converting them to string in systemd-lib
This change is made for two reasons:

1.  If `toString config.restartTriggers` containes `\n`, systemd unit
    file will be ill-formed.
2.  This change can limit length of the trigger, although it doesn't
    matter in most cases.
2023-05-07 09:04:18 +08:00
Sandro Jäckel
a10f3197fc systemd-lib: fix building -.slice (root slice)
The error was:

dirname: invalid option -- '.'
Try 'dirname --help' for more information.
2023-03-20 01:11:23 +01:00