2020-04-24 23:36:52 +00:00
|
|
|
# fwupd daemon.
|
|
|
|
|
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.services.fwupd;
|
2020-06-18 07:06:33 +00:00
|
|
|
|
2022-12-17 10:02:37 +00:00
|
|
|
format = pkgs.formats.ini {
|
|
|
|
listToValue = l: lib.concatStringsSep ";" (map (s: generators.mkValueStringDefault {} s) l);
|
|
|
|
mkKeyValue = generators.mkKeyValueDefault {} "=";
|
|
|
|
};
|
|
|
|
|
2020-06-18 07:06:33 +00:00
|
|
|
customEtc = {
|
|
|
|
"fwupd/daemon.conf" = {
|
2022-12-17 10:02:37 +00:00
|
|
|
source = format.generate "daemon.conf" {
|
|
|
|
fwupd = cfg.daemonSettings;
|
|
|
|
};
|
2020-06-18 07:06:33 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
originalEtc =
|
|
|
|
let
|
|
|
|
mkEtcFile = n: nameValuePair n { source = "${cfg.package}/etc/${n}"; };
|
|
|
|
in listToAttrs (map mkEtcFile cfg.package.filesInstalledToEtc);
|
|
|
|
extraTrustedKeys =
|
|
|
|
let
|
|
|
|
mkName = p: "pki/fwupd/${baseNameOf (toString p)}";
|
|
|
|
mkEtcFile = p: nameValuePair (mkName p) { source = p; };
|
|
|
|
in listToAttrs (map mkEtcFile cfg.extraTrustedKeys);
|
|
|
|
|
2022-10-21 18:38:19 +00:00
|
|
|
enableRemote = base: remote: {
|
|
|
|
"fwupd/remotes.d/${remote}.conf" = {
|
|
|
|
source = pkgs.runCommand "${remote}-enabled.conf" {} ''
|
2020-04-24 23:36:52 +00:00
|
|
|
sed "s,^Enabled=false,Enabled=true," \
|
2022-10-21 18:38:19 +00:00
|
|
|
"${base}/etc/fwupd/remotes.d/${remote}.conf" > "$out"
|
2020-04-24 23:36:52 +00:00
|
|
|
'';
|
|
|
|
};
|
2022-10-21 18:38:19 +00:00
|
|
|
};
|
|
|
|
remotes = (foldl'
|
|
|
|
(configFiles: remote: configFiles // (enableRemote cfg.package remote))
|
|
|
|
{}
|
|
|
|
cfg.extraRemotes
|
|
|
|
) // (
|
|
|
|
# We cannot include the file in $out and rely on filesInstalledToEtc
|
|
|
|
# to install it because it would create a cyclic dependency between
|
|
|
|
# the outputs. We also need to enable the remote,
|
|
|
|
# which should not be done by default.
|
|
|
|
if cfg.enableTestRemote then (enableRemote cfg.package.installedTests "fwupd-tests") else {}
|
|
|
|
);
|
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
in {
|
|
|
|
|
|
|
|
###### interface
|
|
|
|
options = {
|
|
|
|
services.fwupd = {
|
|
|
|
enable = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2020-04-24 23:36:52 +00:00
|
|
|
Whether to enable fwupd, a DBus service that allows
|
|
|
|
applications to update firmware.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
extraTrustedKeys = mkOption {
|
|
|
|
type = types.listOf types.path;
|
|
|
|
default = [];
|
2021-10-06 13:57:05 +00:00
|
|
|
example = literalExpression "[ /etc/nixos/fwupd/myfirmware.pem ]";
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2020-04-24 23:36:52 +00:00
|
|
|
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.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2022-10-21 18:38:19 +00:00
|
|
|
extraRemotes = mkOption {
|
|
|
|
type = with types; listOf str;
|
|
|
|
default = [];
|
|
|
|
example = [ "lvfs-testing" ];
|
|
|
|
description = lib.mdDoc ''
|
|
|
|
Enables extra remotes in fwupd. See `/etc/fwupd/remotes.d`.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
enableTestRemote = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2020-04-24 23:36:52 +00:00
|
|
|
Whether to enable test remote. This is used by
|
2022-08-12 12:06:08 +00:00
|
|
|
[installed tests](https://github.com/fwupd/fwupd/blob/master/data/installed-tests/README.md).
|
2020-04-24 23:36:52 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
package = mkOption {
|
|
|
|
type = types.package;
|
|
|
|
default = pkgs.fwupd;
|
2021-10-06 13:57:05 +00:00
|
|
|
defaultText = literalExpression "pkgs.fwupd";
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2020-04-24 23:36:52 +00:00
|
|
|
Which fwupd package to use.
|
|
|
|
'';
|
|
|
|
};
|
2022-12-17 10:02:37 +00:00
|
|
|
|
|
|
|
daemonSettings = mkOption {
|
|
|
|
type = types.submodule {
|
|
|
|
freeformType = format.type.nestedTypes.elemType;
|
|
|
|
options = {
|
|
|
|
DisabledDevices = mkOption {
|
|
|
|
type = types.listOf types.str;
|
|
|
|
default = [];
|
|
|
|
example = [ "2082b5e0-7a64-478a-b1b2-e3404fab6dad" ];
|
|
|
|
description = lib.mdDoc ''
|
|
|
|
List of device GUIDs to be disabled.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
DisabledPlugins = mkOption {
|
|
|
|
type = types.listOf types.str;
|
|
|
|
default = [];
|
|
|
|
example = [ "udev" ];
|
|
|
|
description = lib.mdDoc ''
|
|
|
|
List of plugins to be disabled.
|
|
|
|
'';
|
|
|
|
};
|
2023-02-02 18:25:31 +00:00
|
|
|
|
|
|
|
EspLocation = mkOption {
|
|
|
|
type = types.path;
|
|
|
|
default = config.boot.loader.efi.efiSysMountPoint;
|
|
|
|
defaultText = lib.literalExpression "config.boot.loader.efi.efiSysMountPoint";
|
|
|
|
description = lib.mdDoc ''
|
|
|
|
The EFI system partition (ESP) path used if UDisks is not available
|
|
|
|
or if this partition is not mounted at /boot/efi, /boot, or /efi
|
|
|
|
'';
|
|
|
|
};
|
2022-12-17 10:02:37 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
default = {};
|
|
|
|
description = lib.mdDoc ''
|
|
|
|
Configurations for the fwupd daemon.
|
|
|
|
'';
|
|
|
|
};
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2020-11-12 09:05:59 +00:00
|
|
|
imports = [
|
2022-12-17 10:02:37 +00:00
|
|
|
(mkRenamedOptionModule [ "services" "fwupd" "blacklistDevices"] [ "services" "fwupd" "daemonSettings" "DisabledDevices" ])
|
|
|
|
(mkRenamedOptionModule [ "services" "fwupd" "blacklistPlugins"] [ "services" "fwupd" "daemonSettings" "DisabledPlugins" ])
|
|
|
|
(mkRenamedOptionModule [ "services" "fwupd" "disabledDevices" ] [ "services" "fwupd" "daemonSettings" "DisabledDevices" ])
|
|
|
|
(mkRenamedOptionModule [ "services" "fwupd" "disabledPlugins" ] [ "services" "fwupd" "daemonSettings" "DisabledPlugins" ])
|
2020-11-12 09:05:59 +00:00
|
|
|
];
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
###### implementation
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
# Disable test related plug-ins implicitly so that users do not have to care about them.
|
2023-02-02 18:25:31 +00:00
|
|
|
services.fwupd.daemonSettings = {
|
|
|
|
DisabledPlugins = cfg.package.defaultDisabledPlugins;
|
|
|
|
EspLocation = config.boot.loader.efi.efiSysMountPoint;
|
|
|
|
};
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
environment.systemPackages = [ cfg.package ];
|
|
|
|
|
2020-06-18 07:06:33 +00:00
|
|
|
# customEtc overrides some files from the package
|
2022-10-21 18:38:19 +00:00
|
|
|
environment.etc = originalEtc // customEtc // extraTrustedKeys // remotes;
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
services.dbus.packages = [ cfg.package ];
|
|
|
|
|
|
|
|
services.udev.packages = [ cfg.package ];
|
|
|
|
|
2023-01-11 07:51:40 +00:00
|
|
|
# required to update the firmware of disks
|
|
|
|
services.udisks2.enable = true;
|
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
systemd.packages = [ cfg.package ];
|
2022-09-09 14:08:57 +00:00
|
|
|
|
|
|
|
security.polkit.enable = true;
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
meta = {
|
|
|
|
maintainers = pkgs.fwupd.meta.maintainers;
|
|
|
|
};
|
|
|
|
}
|