1# fwupd daemon.
2
3{ config, lib, pkgs, ... }:
4
5with lib;
6
7let
8 cfg = config.services.fwupd;
9 originalEtc =
10 let
11 mkEtcFile = n: nameValuePair n { source = "${pkgs.fwupd}/etc/${n}"; };
12 in listToAttrs (map mkEtcFile pkgs.fwupd.filesInstalledToEtc);
13 extraTrustedKeys =
14 let
15 mkName = p: "pki/fwupd/${baseNameOf (toString p)}";
16 mkEtcFile = p: nameValuePair (mkName p) { source = p; };
17 in listToAttrs (map mkEtcFile cfg.extraTrustedKeys);
18in {
19
20 ###### interface
21 options = {
22 services.fwupd = {
23 enable = mkOption {
24 type = types.bool;
25 default = false;
26 description = ''
27 Whether to enable fwupd, a DBus service that allows
28 applications to update firmware.
29 '';
30 };
31
32 blacklistDevices = mkOption {
33 type = types.listOf types.string;
34 default = [];
35 example = [ "2082b5e0-7a64-478a-b1b2-e3404fab6dad" ];
36 description = ''
37 Allow blacklisting specific devices by their GUID
38 '';
39 };
40
41 blacklistPlugins = mkOption {
42 type = types.listOf types.string;
43 default = [];
44 example = [ "udev" ];
45 description = ''
46 Allow blacklisting specific plugins
47 '';
48 };
49
50 extraTrustedKeys = mkOption {
51 type = types.listOf types.path;
52 default = [];
53 example = literalExample "[ /etc/nixos/fwupd/myfirmware.pem ]";
54 description = ''
55 Installing a public key allows firmware signed with a matching private key to be recognized as trusted, which may require less authentication to install than for untrusted files. By default trusted firmware can be upgraded (but not downgraded) without the user or administrator password. Only very few keys are installed by default.
56 '';
57 };
58 };
59 };
60
61
62 ###### implementation
63 config = mkIf cfg.enable {
64 environment.systemPackages = [ pkgs.fwupd ];
65
66 environment.etc = {
67 "fwupd/daemon.conf" = {
68 source = pkgs.writeText "daemon.conf" ''
69 [fwupd]
70 BlacklistDevices=${lib.concatStringsSep ";" cfg.blacklistDevices}
71 BlacklistPlugins=${lib.concatStringsSep ";" cfg.blacklistPlugins}
72 '';
73 };
74 } // originalEtc // extraTrustedKeys;
75
76 services.dbus.packages = [ pkgs.fwupd ];
77
78 services.udev.packages = [ pkgs.fwupd ];
79
80 systemd.packages = [ pkgs.fwupd ];
81
82 systemd.tmpfiles.rules = [
83 "d /var/lib/fwupd 0755 root root -"
84 ];
85 };
86
87 meta = {
88 maintainers = pkgs.fwupd.maintainers;
89 };
90}