Skip to content

Commit

Permalink
Add generic-device-plugin package and module
Browse files Browse the repository at this point in the history
Signed-off-by: magic_rb <[email protected]>
  • Loading branch information
MagicRB committed Dec 17, 2024
1 parent 45fc112 commit de21981
Show file tree
Hide file tree
Showing 4 changed files with 124 additions and 0 deletions.
1 change: 1 addition & 0 deletions modules/list.nix
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,5 @@
./services/synapse.nix
./services/dnsmasq.nix
./services/attic.nix
./services/generic-device-plugin.nix
]
91 changes: 91 additions & 0 deletions modules/services/generic-device-plugin.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
# SPDX-FileCopyrightText: 2021 Richard Brežák and NixNG contributors
#
# SPDX-License-Identifier: MPL-2.0
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
{
pkgs,
config,
lib,
nglib,
...
}:
let
cfg = config.services.genericDevicePlugin;
settingsFormat = pkgs.formats.json { };
usageLink = "https://github.com/squat/generic-device-plugin/tree/main?tab=readme-ov-file#usage";
in
{
options.services.genericDevicePlugin = {
enable = lib.mkEnableOption "Whether to enable the generic-device-plugin";

package = lib.mkPackageOption pkgs "generic-device-plugin" { };

settings = {
devices = lib.mkOption {
type = lib.types.listOf (settingsFormat.type);
default = [ ];
description = ''
See [upstream documentation](${usageLink});
'';
example = lib.literalExpression ''
[
{
name = "zigbee";
groups = lib.singleton { paths = lib.singleton { path = "/dev/ttyZigbee"; }; };
}
{
name = "ender3";
groups = lib.singleton { paths = lib.singleton { path = "/dev/ttyEnder3"; }; };
}
]
'';
};
domain = lib.mkOption {
type = lib.types.nullOr lib.types.str;
default = null;
description = ''
See [upstream documentation](${usageLink}). If `null`, upstream default is used.
'';
};
listen = lib.mkOption {
type = lib.types.nullOr lib.types.str;
default = null;
description = ''
See [upstream documentation](${usageLink}). If `null`, upstream default is used.
'';
};
logLevel = lib.mkOption {
type = lib.types.enum [
"all"
"debug"
"info"
"warn"
"error"
"none"
"info"
];
default = "info";
description = ''
Log level to use.
'';
};
pluginDirectory = lib.mkOption {
type = lib.types.nullOr lib.types.path;
default = null;
description = ''
See [upstream documentation](${usageLink}). If `null`, upstream default is used.
'';
};
};
};
config = lib.mkIf cfg.enable {
init.services.generic-device-plugin = {
shutdownOnExit = true;
enabled = true;
execStart = "${lib.getExe cfg.package} --config ${settingsFormat.generate "settings.json" cfg.settings}";
};
};
}
1 change: 1 addition & 0 deletions overlay/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ in
systemdStandalone = callPackage ./systemd-minimal.nix { };
systemdTmpfilesD = callPackage ./systemd-tmpfiles.d.nix { };
dinit = callPackage ./dinit.nix { };
generic-device-plugin = callPackage ./generic-device-plugin.nix { };

util-linuxSystemdFree = prev.util-linux.override {
systemdSupport = false;
Expand Down
31 changes: 31 additions & 0 deletions overlay/generic-device-plugin.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
buildGoModule,
fetchFromGitHub,
lib,
...
}:

buildGoModule {
pname = "generic-device-plugin";
version = "20241207-unstable";

src = fetchFromGitHub {
owner = "squat";
repo = "generic-device-plugin";
rev = "36bfc606bba2064de6ede0ff2764cbb52edff70d";
hash = "sha256-xztISJxFWKFWvanWY6WBx7KBIbJdUUkVX+YM0xLgBzk=";
};

vendorHash = "sha256-L0OYB6iI4z1o4FEmzpL0Qbc9uamyJZ89HWV77D10p3M=";

# requires a docker instance running
doCheck = false;

meta = with lib; {
description = "The generic-device-plugin enables allocating generic Linux devices, such as serial devices, the FUSE device, or video cameras, to Kubernetes Pods.";
homepage = "https://github.com/squat/generic-device-plugin";
license = licenses.asl20;
maintainers = with maintainers; [ ];
mainProgram = "generic-device-plugin";
};
}

0 comments on commit de21981

Please sign in to comment.