2 { config, lib, pkgs, ... }:
4 cfg = config.services.fwupd;
6 format = pkgs.formats.ini {
7 listToValue = l: lib.concatStringsSep ";" (map (s: lib.generators.mkValueStringDefault {} s) l);
8 mkKeyValue = lib.generators.mkKeyValueDefault {} "=";
12 "fwupd/fwupd.conf" = {
13 source = format.generate "fwupd.conf" ({
14 fwupd = cfg.daemonSettings;
15 } // lib.optionalAttrs (lib.length (lib.attrNames cfg.uefiCapsuleSettings) != 0) {
16 uefi_capsule = cfg.uefiCapsuleSettings;
18 # fwupd tries to chmod the file if it doesn't have the right permissions
25 mkEtcFile = n: lib.nameValuePair n { source = "${cfg.package}/etc/${n}"; };
26 in lib.listToAttrs (map mkEtcFile cfg.package.filesInstalledToEtc);
29 mkName = p: "pki/fwupd/${baseNameOf (toString p)}";
30 mkEtcFile = p: lib.nameValuePair (mkName p) { source = p; };
31 in lib.listToAttrs (map mkEtcFile cfg.extraTrustedKeys);
33 enableRemote = base: remote: {
34 "fwupd/remotes.d/${remote}.conf" = {
35 source = pkgs.runCommand "${remote}-enabled.conf" {} ''
36 sed "s,^Enabled=false,Enabled=true," \
37 "${base}/etc/fwupd/remotes.d/${remote}.conf" > "$out"
42 (configFiles: remote: configFiles // (enableRemote cfg.package remote))
46 # We cannot include the file in $out and rely on filesInstalledToEtc
47 # to install it because it would create a cyclic dependency between
48 # the outputs. We also need to enable the remote,
49 # which should not be done by default.
51 (cfg.daemonSettings.TestDevices or false)
52 (enableRemote cfg.package.installedTests "fwupd-tests")
60 enable = lib.mkOption {
61 type = lib.types.bool;
64 Whether to enable fwupd, a DBus service that allows
65 applications to update firmware.
69 extraTrustedKeys = lib.mkOption {
70 type = lib.types.listOf lib.types.path;
72 example = lib.literalExpression "[ /etc/nixos/fwupd/myfirmware.pem ]";
74 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.
78 extraRemotes = lib.mkOption {
79 type = with lib.types; listOf str;
81 example = [ "lvfs-testing" ];
83 Enables extra remotes in fwupd. See `/etc/fwupd/remotes.d`.
87 package = lib.mkPackageOption pkgs "fwupd" { };
89 daemonSettings = lib.mkOption {
90 type = lib.types.submodule {
91 freeformType = format.type.nestedTypes.elemType;
93 DisabledDevices = lib.mkOption {
94 type = lib.types.listOf lib.types.str;
96 example = [ "2082b5e0-7a64-478a-b1b2-e3404fab6dad" ];
98 List of device GUIDs to be disabled.
102 DisabledPlugins = lib.mkOption {
103 type = lib.types.listOf lib.types.str;
105 example = [ "udev" ];
107 List of plugins to be disabled.
111 EspLocation = lib.mkOption {
112 type = lib.types.path;
113 default = config.boot.loader.efi.efiSysMountPoint;
114 defaultText = lib.literalExpression "config.boot.loader.efi.efiSysMountPoint";
116 The EFI system partition (ESP) path used if UDisks is not available
117 or if this partition is not mounted at /boot/efi, /boot, or /efi
121 TestDevices = lib.mkOption {
123 type = lib.types.bool;
126 Create virtual test devices and remote for validating daemon flows.
127 This is only intended for CI testing and development purposes.
134 Configurations for the fwupd daemon.
138 uefiCapsuleSettings = lib.mkOption {
139 type = lib.types.submodule {
140 freeformType = format.type.nestedTypes.elemType;
144 UEFI capsule configurations for the fwupd daemon.
151 (lib.mkRenamedOptionModule [ "services" "fwupd" "blacklistDevices"] [ "services" "fwupd" "daemonSettings" "DisabledDevices" ])
152 (lib.mkRenamedOptionModule [ "services" "fwupd" "blacklistPlugins"] [ "services" "fwupd" "daemonSettings" "DisabledPlugins" ])
153 (lib.mkRenamedOptionModule [ "services" "fwupd" "disabledDevices" ] [ "services" "fwupd" "daemonSettings" "DisabledDevices" ])
154 (lib.mkRenamedOptionModule [ "services" "fwupd" "disabledPlugins" ] [ "services" "fwupd" "daemonSettings" "DisabledPlugins" ])
155 (lib.mkRemovedOptionModule [ "services" "fwupd" "enableTestRemote" ] "This option was removed after being removed upstream. It only provided a method for testing fwupd functionality, and should not have been exposed for use outside of nix tests.")
158 ###### implementation
159 config = lib.mkIf cfg.enable {
160 # Disable test related plug-ins implicitly so that users do not have to care about them.
161 services.fwupd.daemonSettings = {
162 EspLocation = config.boot.loader.efi.efiSysMountPoint;
165 environment.systemPackages = [ cfg.package ];
167 # customEtc overrides some files from the package
168 environment.etc = originalEtc // customEtc // extraTrustedKeys // remotes;
170 services.dbus.packages = [ cfg.package ];
172 services.udev.packages = [ cfg.package ];
174 # required to update the firmware of disks
175 services.udisks2.enable = true;
178 packages = [ cfg.package ];
180 # fwupd-refresh expects a user that we do not create, so just run with DynamicUser
181 # instead and ensure we take ownership of /var/lib/fwupd
182 services.fwupd-refresh.serviceConfig = {
183 StateDirectory = "fwupd";
184 # Better for debugging, upstream sets stderr to null for some reason..
185 StandardError = "inherit";
188 timers.fwupd-refresh.wantedBy = [ "timers.target" ];
191 users.users.fwupd-refresh = {
193 group = "fwupd-refresh";
195 users.groups.fwupd-refresh = {};
197 security.polkit.enable = true;
201 maintainers = pkgs.fwupd.meta.maintainers;