Skip to content

Commit

Permalink
nixos/hardware: add FreeJoy udev rules
Browse files Browse the repository at this point in the history
  • Loading branch information
Pandapip1 committed Jan 14, 2025
1 parent 3dad153 commit 865aa10
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions nixos/modules/hardware/freejoy.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
{
lib,
config,
options,
...
}:
let
cfg = config.hardware.freejoy;
opt = options.hardware.freejoy;
in
{
options.hardware.stlink = {
enable = lib.mkEnableOption "udev rules for FreeJoy USB devices";
owner = lib.mkOption {
type = lib.types.str;
default = "root";
example = "nobody";
description = "Owner of FreeJoy devices";
};
group = lib.mkOption {
type = lib.types.str;
default = "plugdev";
example = "nobody";
description = "Group of FreeJoy devices";
};
mode = lib.mkOption {
type = lib.types.str;
default = "0660";
example = "0640";
description = "Mode of FreeJoy devices";
};
};

config = lib.mkMerge [
(lib.mkIf cfg.enable {
assertions = [
{
assertion = builtins.hasAttr cfg.owner config.users.users;
message = "Owner '${cfg.owner}' set in `${opt.owner}` is not configured via `${options.users.users}.\"${cfg.owner}\"`.";
}
{
assertion = (cfg.group == opt.group.default) || (builtins.hasAttr cfg.group config.users.groups);
message = "Group '${cfg.group}' set in `${opt.group}` is not configured via `${options.users.groups}.\"${cfg.group}\"`.";
}
];
services.udev.extraRules = ''
ENV{ID_VENDOR}=="FreeJoy", OWNER="${cfg.owner}", GROUP="${cfg.group}", MODE="${cfg.mode}"
'';
users.groups.plugdev = lib.mkIf (config.group == "plugdev") { };
})
];

meta.maintainers = with lib.maintainers; [ pandapip1 ];
}

0 comments on commit 865aa10

Please sign in to comment.