nixpkgs/nixos/modules
Maximilian Bosch 11376df6d4
nixos/rust-motd: allow ordering sections by priority
Closes #234802

The problem here is that with e.g.

    {
      uptime.prefix = "Up";
      banner.command = "hostname | figlet -f slant";
    }

`banner` still appears before `uptime` in the final motd text because
Nix sorts attribute names alphabetically internally.

To work around this without breaking compatibility or losing the
property to override individual sections in other modules - e.g.

    {
      banner.color = mkForce "blue";
    }

I decided to introduce an option `priority` here, similar to the
priority field for `nginx`[1] and with the same semantics (i.e. higher
value means lower priority).

Internally a bunch of env vars are generated, i.e. `env0` to `envN` for
`N` sections with each of them containing a declaration for the TOML,
i.e. `env0` contains `{ uptime.prefix = "Up"; }` and `env1` contains
`{ banner.command = "hostname | figlet -f slant"; }` if `uptime.priority`
is set to a value below 1000.

In this order, the declarations are concatenated together by `jq(1)`
which doesn't sort keys alphabetically which results in a JSON
representation with `uptime` before `banner`. This is finally piped to
`json2toml` which converts this into TOML for rust-motd.

[1] https://nixos.org/manual/nixos/unstable/options#opt-services.nginx.virtualHosts._name_.locations._name_.priority
2023-09-21 13:17:13 +02:00
..
config nixos/{sudo, terminfo}: Adjust defaults for compatibility with sudo-rs 2023-09-18 17:36:15 +00:00
hardware nixos/nvidia: don't assume x11 is used.. 2023-09-14 18:19:15 +02:00
i18n/input-method uim: remove qt4, fix qt5 2023-09-04 13:54:50 +02:00
image modules/image/repart: Fix stripNixStorePrefix 2023-08-22 13:09:03 +02:00
installer nixos/installer: mention search.nixos.org 2023-09-18 14:38:26 +02:00
misc nixos/doc: Improve documentation of documentation 2023-08-12 22:28:04 +03:00
profiles nixos/installation-device: allow nix-copy for root/nixos user 2023-08-07 16:48:49 +02:00
programs nixos/rust-motd: allow ordering sections by priority 2023-09-21 13:17:13 +02:00
security nixos/sudo: Add myself as maintainer 2023-09-18 18:03:58 +00:00
services Merge pull request #255064 from tomfitzhenry/vikunja-cli 2023-09-20 18:03:34 +08:00
system Merge pull request #254918 from RaitoBezarius/dnssec-resolved 2023-09-19 06:45:07 +03:00
tasks nixos/swraid: only warn if swraid was explicitly enabled (#255426) 2023-09-16 12:19:19 +02:00
testing Merge pull request #219106 from m-bdf/nixos-testing-increase-device-timeout 2023-06-20 11:48:45 +02:00
virtualisation fix capitalization (#254542) 2023-09-15 09:59:11 +02:00
module-list.nix nixos/frp: init 2023-09-17 14:37:19 +08:00
rename.nix nodePackages.tedicross: drop 2023-09-13 15:00:38 -07:00