From 93c026494ad5e2902d9e1afc10015f453c77f918 Mon Sep 17 00:00:00 2001 From: nikstur Date: Thu, 11 May 2023 16:28:11 +0200 Subject: [PATCH 1/2] rshim-user-space: init at 2.0.7 --- pkgs/tools/misc/rshim-user-space/default.nix | 60 ++++++++++++++++++++ pkgs/top-level/all-packages.nix | 2 + 2 files changed, 62 insertions(+) create mode 100644 pkgs/tools/misc/rshim-user-space/default.nix diff --git a/pkgs/tools/misc/rshim-user-space/default.nix b/pkgs/tools/misc/rshim-user-space/default.nix new file mode 100644 index 000000000000..86ef8f3c67e2 --- /dev/null +++ b/pkgs/tools/misc/rshim-user-space/default.nix @@ -0,0 +1,60 @@ +{ stdenv +, lib +, fetchFromGitHub +, autoreconfHook +, autoconf +, automake +, pkg-config +, pciutils +, libusb1 +, fuse +}: + +stdenv.mkDerivation rec { + pname = "rshim-user-space"; + version = "2.0.7"; + + src = fetchFromGitHub { + owner = "Mellanox"; + repo = pname; + rev = "rshim-${version}"; + hash = "sha256-Dyc16UrRxbC9jRNVZ/sCgidY2hSIX0PrWmHf68x07nE="; + }; + + nativeBuildInputs = [ + autoreconfHook + autoconf + automake + pkg-config + ]; + + buildInputs = [ + pciutils + libusb1 + fuse + ]; + + strictDeps = true; + + preConfigure = "./bootstrap.sh"; + + installPhase = '' + mkdir -p "$out"/bin + cp -a src/rshim "$out"/bin/ + ''; + + meta = with lib; { + description = "user-space rshim driver for the BlueField SoC"; + longDescription = '' + The rshim driver provides a way to access the rshim resources on the + BlueField target from external host machine. The current version + implements device files for boot image push and virtual console access. + It also creates virtual network interface to connect to the BlueField + target and provides a way to access the internal rshim registers. + ''; + homepage = "https://github.com/Mellanox/rshim-user-space"; + license = licenses.gpl2; + platforms = platforms.linux; + maintainers = with maintainers; [ nikstur ]; + }; +} diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 4b52924cb15e..a7fe8c156b3c 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -11919,6 +11919,8 @@ with pkgs; rshijack = callPackage ../tools/networking/rshijack { }; + rshim-user-space = callPackage ../tools/misc/rshim-user-space { }; + rsibreak = libsForQt5.callPackage ../applications/misc/rsibreak { }; rslint = callPackage ../development/tools/rslint { }; From 5435eaaa4d34d941c9493da7a3918d4925162469 Mon Sep 17 00:00:00 2001 From: nikstur Date: Fri, 12 May 2023 14:45:27 +0200 Subject: [PATCH 2/2] nixos/rshim: init --- .../manual/release-notes/rl-2305.section.md | 2 + nixos/modules/module-list.nix | 1 + nixos/modules/services/misc/rshim.nix | 99 +++++++++++++++++++ pkgs/tools/misc/rshim-user-space/default.nix | 2 - 4 files changed, 102 insertions(+), 2 deletions(-) create mode 100644 nixos/modules/services/misc/rshim.nix diff --git a/nixos/doc/manual/release-notes/rl-2305.section.md b/nixos/doc/manual/release-notes/rl-2305.section.md index 2d3736241282..03aff0e7ec7a 100644 --- a/nixos/doc/manual/release-notes/rl-2305.section.md +++ b/nixos/doc/manual/release-notes/rl-2305.section.md @@ -104,6 +104,8 @@ In addition to numerous new and upgraded packages, this release has the followin - [v2rayA](https://v2raya.org), a Linux web GUI client of Project V which supports V2Ray, Xray, SS, SSR, Trojan and Pingtunnel. Available as [services.v2raya](options.html#opt-services.v2raya.enable). +- [rshim](https://github.com/Mellanox/rshim-user-space), the user-space rshim driver for the BlueField SoC. Available as [services.rshim](options.html#opt-services.rshim.enable). + - [wstunnel](https://github.com/erebe/wstunnel), a proxy tunnelling arbitrary TCP or UDP traffic through a WebSocket connection. Instances may be configured via [services.wstunnel](options.html#opt-services.wstunnel.enable). - [ulogd](https://www.netfilter.org/projects/ulogd/index.html), a userspace logging daemon for netfilter/iptables related logging. Available as [services.ulogd](options.html#opt-services.ulogd.enable). diff --git a/nixos/modules/module-list.nix b/nixos/modules/module-list.nix index 0b0634884c71..c9923c395024 100644 --- a/nixos/modules/module-list.nix +++ b/nixos/modules/module-list.nix @@ -687,6 +687,7 @@ ./services/misc/ripple-data-api.nix ./services/misc/rippled.nix ./services/misc/rmfakecloud.nix + ./services/misc/rshim.nix ./services/misc/safeeyes.nix ./services/misc/sdrplay.nix ./services/misc/serviio.nix diff --git a/nixos/modules/services/misc/rshim.nix b/nixos/modules/services/misc/rshim.nix new file mode 100644 index 000000000000..169f1fa5793b --- /dev/null +++ b/nixos/modules/services/misc/rshim.nix @@ -0,0 +1,99 @@ +{ config, lib, pkgs, ... }: + +let + cfg = config.services.rshim; + + rshimCommand = lib.escapeShellArgs ([ "${cfg.package}/bin/rshim" ] + ++ lib.optionals (cfg.backend != null) [ "--backend ${cfg.backend}" ] + ++ lib.optionals (cfg.device != null) [ "--device ${cfg.device}" ] + ++ lib.optionals (cfg.index != null) [ "--index ${builtins.toString cfg.index}" ] + ++ [ "--log-level ${builtins.toString cfg.log-level}" ]) + ; +in +{ + options.services.rshim = { + enable = lib.mkEnableOption (lib.mdDoc "User-space rshim driver for the BlueField SoC"); + + package = lib.mkPackageOptionMD pkgs "rshim-user-space" { }; + + backend = lib.mkOption { + type = with lib.types; nullOr (enum [ "usb" "pcie" "pcie_lf" ]); + description = lib.mdDoc '' + Specify the backend to attach. If not specified, the driver will scan + all rshim backends unless the `device` option is given with a device + name specified. + ''; + default = null; + example = "pcie"; + }; + + device = lib.mkOption { + type = with lib.types; nullOr str; + description = lib.mdDoc '' + Specify the device name to attach. The backend driver can be deduced + from the device name, thus the `backend` option is not needed. + ''; + default = null; + example = "pcie-04:00.2"; + }; + + index = lib.mkOption { + type = with lib.types; nullOr int; + description = lib.mdDoc '' + Specify the index to create device path `/dev/rshim`. It's also + used to create network interface name `tmfifo_net`. This option + is needed when multiple rshim instances are running. + ''; + default = null; + example = 1; + }; + + log-level = lib.mkOption { + type = lib.types.int; + description = lib.mdDoc '' + Specify the log level (0:none, 1:error, 2:warning, 3:notice, 4:debug). + ''; + default = 2; + example = 4; + }; + + config = lib.mkOption { + type = with lib.types; attrsOf (oneOf [ int str ]); + description = lib.mdDoc '' + Structural setting for the rshim configuration file + (`/etc/rshim.conf`). It can be used to specify the static mapping + between rshim devices and rshim names. It can also be used to ignore + some rshim devices. + ''; + default = { }; + example = { + DISPLAY_LEVEL = 0; + rshim0 = "usb-2-1.7"; + none = "usb-1-1.4"; + }; + }; + }; + + config = lib.mkIf cfg.enable { + environment.etc = lib.mkIf (cfg.config != { }) { + "rshim.conf".text = lib.generators.toKeyValue + { mkKeyValue = lib.generators.mkKeyValueDefault { } " "; } + cfg.config; + }; + + systemd.services.rshim = { + after = [ "network.target" ]; + serviceConfig = { + Restart = "always"; + Type = "forking"; + ExecStart = [ + (lib.concatStringsSep " \\\n" rshimCommand) + ]; + KillMode = "control-group"; + }; + wantedBy = [ "multi-user.target" ]; + }; + }; + + meta.maintainers = with lib.maintainers; [ nikstur ]; +} diff --git a/pkgs/tools/misc/rshim-user-space/default.nix b/pkgs/tools/misc/rshim-user-space/default.nix index 86ef8f3c67e2..605e6ff325f1 100644 --- a/pkgs/tools/misc/rshim-user-space/default.nix +++ b/pkgs/tools/misc/rshim-user-space/default.nix @@ -1,7 +1,6 @@ { stdenv , lib , fetchFromGitHub -, autoreconfHook , autoconf , automake , pkg-config @@ -22,7 +21,6 @@ stdenv.mkDerivation rec { }; nativeBuildInputs = [ - autoreconfHook autoconf automake pkg-config