From b2b38c56a76a1cf092b83d19ef9256df884340a6 Mon Sep 17 00:00:00 2001 From: Mika Tammi Date: Tue, 15 Aug 2023 11:40:46 +0300 Subject: [PATCH 1/6] Initial flake for running Robot Framework tests Signed-off-by: Mika Tammi --- Robot-Framework/default.nix | 1 + flake.lock | 61 +++++++++++++++++++++++++++++++++++++ flake.nix | 40 ++++++++++++++++++++++++ 3 files changed, 102 insertions(+) create mode 100644 Robot-Framework/default.nix create mode 100644 flake.lock create mode 100644 flake.nix diff --git a/Robot-Framework/default.nix b/Robot-Framework/default.nix new file mode 100644 index 0000000..043b140 --- /dev/null +++ b/Robot-Framework/default.nix @@ -0,0 +1 @@ +{hello}: hello diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..40d83ca --- /dev/null +++ b/flake.lock @@ -0,0 +1,61 @@ +{ + "nodes": { + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1689068808, + "narHash": "sha256-6ixXo3wt24N/melDWjq70UuHQLxGV8jZvooRanIHXw0=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "919d646de7be200f3bf08cb76ae1f09402b6f9b4", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1692134936, + "narHash": "sha256-Z68O969cioC6I3k/AFBxsuEwpJwt4l9fzwuAMUhCCs0=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "bfd953b2c6de4f550f75461bcc5768b6f966be10", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-23.05", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..ec7af84 --- /dev/null +++ b/flake.nix @@ -0,0 +1,40 @@ +{ + description = "A flake for for running Robot Framework tests"; + + inputs = { + nixpkgs.url = "github:nixos/nixpkgs/nixos-23.05"; + flake-utils.url = "github:numtide/flake-utils"; + }; + + outputs = { + self, + nixpkgs, + flake-utils, + }: let + systems = with flake-utils.lib.system; [ + x86_64-linux + aarch64-linux + ]; + in + flake-utils.lib.eachSystem systems (system: let + pkgs = nixpkgs.legacyPackages.${system}; + in { + packages.ghaf-robot = pkgs.callPackage ./Robot-Framework {}; + packages.default = self.packages.${system}.ghaf-robot; + + # Development shell + devShell = pkgs.mkShell { + buildInputs = with pkgs; [ + (python3.withPackages (ps: + with ps; [ + robotframework + robotframework-sshlibrary + pyserial + ])) + ]; + }; + + # Allows formatting files with `nix fmt` + formatter = pkgs.alejandra; + }); +} From 78524da66fdb468d7d5ec17572081202d6d06b26 Mon Sep 17 00:00:00 2001 From: "Alexander V. Nikolaev" Date: Tue, 15 Aug 2023 16:32:02 +0300 Subject: [PATCH 2/6] Make robotframework-seriallibrary installable Add patch from upstream's PR to make SerialLibrary installable Signed-off-by: Alexander V. Nikolaev --- flake.nix | 7 ++- pkgs/robotframework-seriallibrary/default.nix | 44 +++++++++++++++++++ 2 files changed, 49 insertions(+), 2 deletions(-) create mode 100644 pkgs/robotframework-seriallibrary/default.nix diff --git a/flake.nix b/flake.nix index ec7af84..93d8781 100644 --- a/flake.nix +++ b/flake.nix @@ -19,8 +19,10 @@ flake-utils.lib.eachSystem systems (system: let pkgs = nixpkgs.legacyPackages.${system}; in { - packages.ghaf-robot = pkgs.callPackage ./Robot-Framework {}; - packages.default = self.packages.${system}.ghaf-robot; + packages.ghaf-robot = pkgs.callPackage ./Robot-Framework {}; + packages.robotframework-seriallibrary = pkgs.python3Packages.callPackage ./pkgs/robotframework-seriallibrary { + packages.default = self.packages.${system}.ghaf-robot; + }; # Development shell devShell = pkgs.mkShell { @@ -28,6 +30,7 @@ (python3.withPackages (ps: with ps; [ robotframework + self.packages.${system}.robotframework-seriallibrary robotframework-sshlibrary pyserial ])) diff --git a/pkgs/robotframework-seriallibrary/default.nix b/pkgs/robotframework-seriallibrary/default.nix new file mode 100644 index 0000000..bcf334a --- /dev/null +++ b/pkgs/robotframework-seriallibrary/default.nix @@ -0,0 +1,44 @@ +{ + lib, + buildPythonPackage, + fetchpatch2, + fetchPypi, + robotframework, + pyserial, + poetry-core +}: +buildPythonPackage rec { + version = "0.4.3"; + pname = "robotframework-seriallibrary"; + format = "pyproject"; + + src = fetchPypi { + inherit pname version; + sha256 = "sha256-8gvv5cEQbdjdyp9govGL9ex9Xwb28JoD+ma65Ud35rs"; + }; + + patches = [ + (fetchpatch2 { + url = "https://patch-diff.githubusercontent.com/raw/whosaysni/robotframework-seriallibrary/pull/23.diff"; + sha256 = "sha256-fuPH+LkCuZBFCWRc1oCsTiqq/i2EsYJwaUh4hrdIJnw="; + }) + ]; + + # unit tests are impure + # doCheck = false; + + nativeBuildInputs = [ + poetry-core + ]; + + propagatedBuildInputs = [ + robotframework + pyserial + ]; + + meta = with lib; { + description = "Robot Framework test library for serial connection"; + homepage = "https://github.com/whosaysni/robotframework-seriallibrary/blob/develop"; + license = licenses.asl20; + }; +} From 4ff291ae3fd3f47a907e9c79e0eee52be736aa27 Mon Sep 17 00:00:00 2001 From: "Alexander V. Nikolaev" Date: Wed, 16 Aug 2023 16:47:06 +0300 Subject: [PATCH 3/6] Package Py100 and its requirements Signed-off-by: Alexander V. Nikolaev --- flake.nix | 10 +++++++--- pkgs/PyP100/default.nix | 35 +++++++++++++++++++++++++++++++++++ pkgs/pkcs7/default.nix | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 74 insertions(+), 3 deletions(-) create mode 100644 pkgs/PyP100/default.nix create mode 100644 pkgs/pkcs7/default.nix diff --git a/flake.nix b/flake.nix index 93d8781..2820429 100644 --- a/flake.nix +++ b/flake.nix @@ -19,9 +19,12 @@ flake-utils.lib.eachSystem systems (system: let pkgs = nixpkgs.legacyPackages.${system}; in { - packages.ghaf-robot = pkgs.callPackage ./Robot-Framework {}; - packages.robotframework-seriallibrary = pkgs.python3Packages.callPackage ./pkgs/robotframework-seriallibrary { - packages.default = self.packages.${system}.ghaf-robot; + packages = rec { + ghaf-robot = pkgs.callPackage ./Robot-Framework {}; + robotframework-seriallibrary = pkgs.python3Packages.callPackage ./pkgs/robotframework-seriallibrary { }; + pkcs7 = pkgs.python3Packages.callPackage ./pkgs/pkcs7 { }; # Requirement of PyP100 + PyP100 = pkgs.python3Packages.callPackage ./pkgs/PyP100 { inherit pkcs7; }; + default = ghaf-robot; }; # Development shell @@ -31,6 +34,7 @@ with ps; [ robotframework self.packages.${system}.robotframework-seriallibrary + self.packages.${system}.PyP100 robotframework-sshlibrary pyserial ])) diff --git a/pkgs/PyP100/default.nix b/pkgs/PyP100/default.nix new file mode 100644 index 0000000..3b1b600 --- /dev/null +++ b/pkgs/PyP100/default.nix @@ -0,0 +1,35 @@ +{ + lib, + buildPythonPackage, + fetchFromGitHub, + pycryptodome, + pkcs7, + requests +}: +buildPythonPackage rec { + version = "0.1.2"; + pname = "PyP100"; + format = "setuptools"; + + src = fetchFromGitHub { + owner = "fishbigger"; + repo = "TapoP100"; + rev = "43f51a03ab7a647f81682f7b39ceb2afdd04d3a1"; + sha256 = "sha256-aMrjoh4n5Ygu1hT8BYW2Zez4s33FZqoscN9O2Uga4Ls="; + }; + + # unit tests are impure + # doCheck = false; + + propagatedBuildInputs = [ + pycryptodome + pkcs7 + requests + ]; + + meta = with lib; { + description = "A library for controlling the Tp-link Tapo P100/P105/P110 plugs and L530/L510E bulbs."; + homepage = "https://github.com/fishbigger/TapoP100"; + license = licenses.mit; + }; +} diff --git a/pkgs/pkcs7/default.nix b/pkgs/pkcs7/default.nix new file mode 100644 index 0000000..06cdb36 --- /dev/null +++ b/pkgs/pkcs7/default.nix @@ -0,0 +1,32 @@ +{ + lib, + buildPythonPackage, + fetchFromGitHub, +}: +buildPythonPackage rec { + version = "0.1.2"; + pname = "pkcs7"; + format = "setuptools"; + + src = fetchFromGitHub { + owner = "jeppeter"; + repo = "pypkcs7"; + rev = "f8ec81ef4dc7ef061cb15e35b869dccc544e6ddc"; + sha256 = "sha256-MAta84Z0q/C5AUU+tNAPQuqPFLgPDbw8J3OCN4g4LB4="; + }; + + postPatch = '' + python make_setup.py + # Move sources to folder, where setup.py search for them + mv src/pkcs7 pkcs7 + ''; + + # unit tests are impure + # doCheck = false; + + meta = with lib; { + description = "python package pkcs7 conform for the RFC5652."; + homepage = ""https://github.com/jeppeter/pypkcs7; + license = licenses.mit; + }; +} From 3d66f4c3a119b1338bd4440e09bf1d2f0bca4a18 Mon Sep 17 00:00:00 2001 From: "Alexander V. Nikolaev" Date: Wed, 16 Aug 2023 19:10:02 +0300 Subject: [PATCH 4/6] Add robotframework-advancedlogging package Signed-off-by: Alexander V. Nikolaev --- flake.nix | 2 ++ .../default.nix | 31 +++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 pkgs/robotframework-advancedlogging/default.nix diff --git a/flake.nix b/flake.nix index 2820429..0580b9f 100644 --- a/flake.nix +++ b/flake.nix @@ -22,6 +22,7 @@ packages = rec { ghaf-robot = pkgs.callPackage ./Robot-Framework {}; robotframework-seriallibrary = pkgs.python3Packages.callPackage ./pkgs/robotframework-seriallibrary { }; + robotframework-advancedlogging = pkgs.python3Packages.callPackage ./pkgs/robotframework-advancedlogging { }; pkcs7 = pkgs.python3Packages.callPackage ./pkgs/pkcs7 { }; # Requirement of PyP100 PyP100 = pkgs.python3Packages.callPackage ./pkgs/PyP100 { inherit pkcs7; }; default = ghaf-robot; @@ -34,6 +35,7 @@ with ps; [ robotframework self.packages.${system}.robotframework-seriallibrary + self.packages.${system}.robotframework-advancedlogging self.packages.${system}.PyP100 robotframework-sshlibrary pyserial diff --git a/pkgs/robotframework-advancedlogging/default.nix b/pkgs/robotframework-advancedlogging/default.nix new file mode 100644 index 0000000..d87ad70 --- /dev/null +++ b/pkgs/robotframework-advancedlogging/default.nix @@ -0,0 +1,31 @@ +{ + lib, + buildPythonPackage, + fetchFromGitHub, + robotframework +}: +buildPythonPackage rec { + version = "2.0.0"; + pname = "robotframework-advancedlogging"; + format = "setuptools"; + + src = fetchFromGitHub { + owner = "peterservice-rnd"; + repo = "robotframework-advancedlogging"; + rev = "4f982c09804024273f25de946b43a3a72428a296"; + sha256 = "sha256-eMdlj8zWP7DVh+U6DHJFiPNFyPENrLDWBh0qF2g6dWM="; + }; + + # unit tests are impure + # doCheck = false; + + propagatedBuildInputs = [ + robotframework + ]; + + meta = with lib; { + description = "RobotFramework Advanced Logging Library."; + homepage = "RobotFramework Advanced Logging Library"; + license = licenses.asl20; + }; +} From ffea6bb710c788fe8ff27ddedad091fa8362a4d1 Mon Sep 17 00:00:00 2001 From: Mika Tammi Date: Wed, 16 Aug 2023 19:41:45 +0300 Subject: [PATCH 5/6] Add ghaf-robot wrapper script The `ghaf-robot` wrapper script wraps Robot Framework's `robot`-command, to be run inside environment which has all the necessary Python packages. Signed-off-by: Mika Tammi --- Robot-Framework/default.nix | 1 - flake.nix | 14 +++++---- pkgs/PyP100/default.nix | 2 +- pkgs/ghaf-robot/default.nix | 29 +++++++++++++++++++ pkgs/pkcs7/default.nix | 2 +- .../default.nix | 2 +- pkgs/robotframework-seriallibrary/default.nix | 2 +- 7 files changed, 42 insertions(+), 10 deletions(-) delete mode 100644 Robot-Framework/default.nix create mode 100644 pkgs/ghaf-robot/default.nix diff --git a/Robot-Framework/default.nix b/Robot-Framework/default.nix deleted file mode 100644 index 043b140..0000000 --- a/Robot-Framework/default.nix +++ /dev/null @@ -1 +0,0 @@ -{hello}: hello diff --git a/flake.nix b/flake.nix index 0580b9f..e7e6350 100644 --- a/flake.nix +++ b/flake.nix @@ -20,11 +20,15 @@ pkgs = nixpkgs.legacyPackages.${system}; in { packages = rec { - ghaf-robot = pkgs.callPackage ./Robot-Framework {}; - robotframework-seriallibrary = pkgs.python3Packages.callPackage ./pkgs/robotframework-seriallibrary { }; - robotframework-advancedlogging = pkgs.python3Packages.callPackage ./pkgs/robotframework-advancedlogging { }; - pkcs7 = pkgs.python3Packages.callPackage ./pkgs/pkcs7 { }; # Requirement of PyP100 - PyP100 = pkgs.python3Packages.callPackage ./pkgs/PyP100 { inherit pkcs7; }; + ghaf-robot = pkgs.callPackage ./pkgs/ghaf-robot { + PyP100 = self.packages.${system}.PyP100; + robotframework-advancedlogging = self.packages.${system}.robotframework-advancedlogging; + robotframework-seriallibrary = self.packages.${system}.robotframework-seriallibrary; + }; + robotframework-seriallibrary = pkgs.python3Packages.callPackage ./pkgs/robotframework-seriallibrary {}; + robotframework-advancedlogging = pkgs.python3Packages.callPackage ./pkgs/robotframework-advancedlogging {}; + pkcs7 = pkgs.python3Packages.callPackage ./pkgs/pkcs7 {}; # Requirement of PyP100 + PyP100 = pkgs.python3Packages.callPackage ./pkgs/PyP100 {inherit pkcs7;}; default = ghaf-robot; }; diff --git a/pkgs/PyP100/default.nix b/pkgs/PyP100/default.nix index 3b1b600..c7b47bf 100644 --- a/pkgs/PyP100/default.nix +++ b/pkgs/PyP100/default.nix @@ -4,7 +4,7 @@ fetchFromGitHub, pycryptodome, pkcs7, - requests + requests, }: buildPythonPackage rec { version = "0.1.2"; diff --git a/pkgs/ghaf-robot/default.nix b/pkgs/ghaf-robot/default.nix new file mode 100644 index 0000000..08fa8fa --- /dev/null +++ b/pkgs/ghaf-robot/default.nix @@ -0,0 +1,29 @@ +{ + PyP100, + python3, + robotframework-advancedlogging, + robotframework-seriallibrary, + stdenv, + writeShellApplication, +}: +writeShellApplication { + name = "ghaf-robot"; + runtimeInputs = [ + (python3.withPackages (ps: [ + # These are taken from nixpkgs + ps.robotframework + ps.robotframework-sshlibrary + ps.pyserial + + # These are taken from this flake + robotframework-advancedlogging + robotframework-seriallibrary + PyP100 + ])) + ]; + text = '' + # A shell script which runs Robot Framework in an environment where all the + # required dependency Python modules are present. + exec robot "$@" + ''; +} diff --git a/pkgs/pkcs7/default.nix b/pkgs/pkcs7/default.nix index 06cdb36..51fc1a2 100644 --- a/pkgs/pkcs7/default.nix +++ b/pkgs/pkcs7/default.nix @@ -26,7 +26,7 @@ buildPythonPackage rec { meta = with lib; { description = "python package pkcs7 conform for the RFC5652."; - homepage = ""https://github.com/jeppeter/pypkcs7; + homepage = "https://github.com/jeppeter/pypkcs7"; license = licenses.mit; }; } diff --git a/pkgs/robotframework-advancedlogging/default.nix b/pkgs/robotframework-advancedlogging/default.nix index d87ad70..c8cb843 100644 --- a/pkgs/robotframework-advancedlogging/default.nix +++ b/pkgs/robotframework-advancedlogging/default.nix @@ -2,7 +2,7 @@ lib, buildPythonPackage, fetchFromGitHub, - robotframework + robotframework, }: buildPythonPackage rec { version = "2.0.0"; diff --git a/pkgs/robotframework-seriallibrary/default.nix b/pkgs/robotframework-seriallibrary/default.nix index bcf334a..25f1780 100644 --- a/pkgs/robotframework-seriallibrary/default.nix +++ b/pkgs/robotframework-seriallibrary/default.nix @@ -5,7 +5,7 @@ fetchPypi, robotframework, pyserial, - poetry-core + poetry-core, }: buildPythonPackage rec { version = "0.4.3"; From 8cf0c58ac206daab9ef2317643ec8126d3354fe7 Mon Sep 17 00:00:00 2001 From: Mika Tammi Date: Thu, 17 Aug 2023 01:24:38 +0300 Subject: [PATCH 6/6] README.md: Add section for ghaf-robot Signed-off-by: Mika Tammi --- README.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/README.md b/README.md index b4fd354..edb0bb0 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,21 @@ Jenkinsfiles, Robot framework suites, libraries and requirements for running tests to ghaf-project nixOS with real HW. +## Nix Flake usage + +### Basic test running + +To enter a shell which has the `ghaf-robot` wrapper for running the Robot +Framework, run `nix shell`. + +Alternatively, you can build the package with `nix build` and the wrapper will +appear at `result/bin/ghaf-robot`. + +### Devshell + +To enter a devshell, where you can run `robot` (instead of the wrapper) and all +the Python dependencies are available, run `nix develop`. + ## drcontrol.py For more information, see [drcontrol-README.md](./drcontrol/drcontrol-README.md).