rename service-trigger rule to match service name
This commit is contained in:
37
modules/uevent-rule/default.nix
Normal file
37
modules/uevent-rule/default.nix
Normal file
@@ -0,0 +1,37 @@
|
||||
# this is unlikely to be the final form or location of this code, it's
|
||||
# an interim module which wraps the uevent-watch command
|
||||
|
||||
{ lib, pkgs, config, ... }:
|
||||
let
|
||||
inherit (lib) mkOption types;
|
||||
inherit (pkgs) liminix;
|
||||
# inherit (pkgs.liminix.services) bundle;
|
||||
in {
|
||||
options = {
|
||||
system.service.uevent-rule = mkOption {
|
||||
description = "a service which starts other services based on device state (sysfs)";
|
||||
type = liminix.lib.types.serviceDefn;
|
||||
};
|
||||
};
|
||||
config = {
|
||||
system.service.uevent-rule = config.system.callService ./rule.nix {
|
||||
serviceName = mkOption {
|
||||
description = "name of the service to run when the rule matches";
|
||||
type = types.str;
|
||||
};
|
||||
terms = mkOption {
|
||||
type = types.attrs;
|
||||
example = {
|
||||
devtype = "usb_device";
|
||||
attrs.idVendor = "8086";
|
||||
};
|
||||
default = {};
|
||||
};
|
||||
symlink = mkOption {
|
||||
description = "create symlink targeted on devpath";
|
||||
type = types.nullOr types.str;
|
||||
default = null;
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
23
modules/uevent-rule/rule.nix
Normal file
23
modules/uevent-rule/rule.nix
Normal file
@@ -0,0 +1,23 @@
|
||||
{
|
||||
liminix
|
||||
, uevent-watch
|
||||
, lib }:
|
||||
{
|
||||
serviceName, terms, symlink
|
||||
}:
|
||||
let
|
||||
inherit (liminix.services) longrun;
|
||||
inherit (lib.attrsets) collect mapAttrsRecursive;
|
||||
inherit (lib.strings) concatStringsSep;
|
||||
stringify = attrs :
|
||||
concatStringsSep " "
|
||||
(collect lib.isString
|
||||
(mapAttrsRecursive
|
||||
(path : value : "${concatStringsSep "." path}=${value}")
|
||||
attrs));
|
||||
termsString = stringify terms;
|
||||
in longrun {
|
||||
name = "watch-for-${serviceName}";
|
||||
restart-on-upgrade = true;
|
||||
run = "${uevent-watch}/bin/uevent-watch ${if symlink != null then "-n ${symlink}" else ""} -s ${serviceName} ${termsString}";
|
||||
}
|
Reference in New Issue
Block a user