{ config, lib, pkgs, ... }: let cfg = config.local.packages.linuxcnc-with-ethercat; inherit (builtins) filter map pathExists listToAttrs; in { options.local.packages.linuxcnc.enable = lib.mkEnableOption "Enable linuxcnc"; config = lib.mkIf cfg.enable { environment.systemPackages = with pkgs; [ linuxcnc-with-ethercat ]; security.wrappers = listToAttrs (map (f: { name = f; value = { setuid = true; owner = "root"; group = "root"; source = "${pkgs.linuxcnc-with-ethercat}/bin/${f}-nosetuid"; }; }) (filter (f: pathExists "${pkgs.linuxcnc-with-ethercat}/bin/${f}-nosetuid") pkgs.linuxcnc-with-ethercat.setuidApps)); }; }