Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flake and ghaf-robot wrapper script for running the Robot Framework test suites on Nix/NixOS #27

Merged
merged 6 commits into from
Sep 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
61 changes: 61 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

53 changes: 53 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{
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 = rec {
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;
};

# Development shell
devShell = pkgs.mkShell {
buildInputs = with pkgs; [
(python3.withPackages (ps:
with ps; [
robotframework
self.packages.${system}.robotframework-seriallibrary
self.packages.${system}.robotframework-advancedlogging
self.packages.${system}.PyP100
robotframework-sshlibrary
pyserial
]))
];
};

# Allows formatting files with `nix fmt`
formatter = pkgs.alejandra;
});
}
35 changes: 35 additions & 0 deletions pkgs/PyP100/default.nix
Original file line number Diff line number Diff line change
@@ -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;
};
}
29 changes: 29 additions & 0 deletions pkgs/ghaf-robot/default.nix
Original file line number Diff line number Diff line change
@@ -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 "$@"
'';
}
32 changes: 32 additions & 0 deletions pkgs/pkcs7/default.nix
Original file line number Diff line number Diff line change
@@ -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;
};
}
31 changes: 31 additions & 0 deletions pkgs/robotframework-advancedlogging/default.nix
Original file line number Diff line number Diff line change
@@ -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;
};
}
44 changes: 44 additions & 0 deletions pkgs/robotframework-seriallibrary/default.nix
Original file line number Diff line number Diff line change
@@ -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;
};
}