Skip to content

Commit

Permalink
activitywatch: init at 0.12.1
Browse files Browse the repository at this point in the history
  • Loading branch information
huantianad committed Feb 26, 2023
1 parent 7d5c11b commit f1d2216
Show file tree
Hide file tree
Showing 3 changed files with 235 additions and 0 deletions.
16 changes: 16 additions & 0 deletions pkgs/applications/office/activitywatch/commit-hash.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
diff --git a/vue.config.js b/vue.config.js
index 02c0699..0c4a014 100644
--- a/vue.config.js
+++ b/vue.config.js
@@ -4,10 +4,7 @@ const CopyWebpackPlugin = require('copy-webpack-plugin');
const { argv } = require('yargs');

// get git info from command line
-const _COMMIT_HASH = require('child_process')
- .execSync('git rev-parse --short HEAD')
- .toString()
- .trim();
+const _COMMIT_HASH = "@commit_hash@";
console.info('Commit hash:', _COMMIT_HASH);

module.exports = {
213 changes: 213 additions & 0 deletions pkgs/applications/office/activitywatch/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,213 @@
{ lib
, fetchFromGitHub
, rustPlatform
, makeWrapper
, pkg-config
, perl
, openssl
, python3
, qt6
, substituteAll
, buildNpmPackage
}:

let
version = "0.12.1";
sources = fetchFromGitHub {
owner = "ActivityWatch";
repo = "activitywatch";
rev = "v${version}";
sha256 = "sha256-pK+upMSpJlg7J8WTmImLm8TW8pMHrCihMeiT+1/nbPM=";
fetchSubmodules = true;
};
in
rec {
aw-watcher-afk = python3.pkgs.buildPythonApplication {
pname = "aw-watcher-afk";
inherit version;

format = "pyproject";

src = "${sources}/aw-watcher-afk";

postPatch = ''
sed -E 's#build-backend = "poetry.masonry.api"#build-backend = "poetry.core.masonry.api"#g' -i pyproject.toml
'';

nativeBuildInputs = [
python3.pkgs.poetry-core
];

propagatedBuildInputs = with python3.pkgs; [
aw-client
xlib
pynput
];

meta = with lib; {
description = "Watches keyboard and mouse activity to determine if you are AFK or not (for use with ActivityWatch)";
homepage = "https://github.com/ActivityWatch/aw-watcher-afk";
maintainers = with maintainers; [ huantian ];
license = licenses.mpl20;
};
};

aw-watcher-window = python3.pkgs.buildPythonApplication {
pname = "aw-watcher-window";
inherit version;

format = "pyproject";

src = "${sources}/aw-watcher-window";

postPatch = ''
sed -E 's#build-backend = "poetry.masonry.api"#build-backend = "poetry.core.masonry.api"#g' -i pyproject.toml
'';

nativeBuildInputs = [
python3.pkgs.poetry-core
];

propagatedBuildInputs = with python3.pkgs; [
aw-client
xlib
];

meta = with lib; {
description = "Cross-platform window watcher (for use with ActivityWatch)";
homepage = "https://github.com/ActivityWatch/aw-watcher-window";
maintainers = with maintainers; [ huantian ];
license = licenses.mpl20;
};
};

aw-qt = python3.pkgs.buildPythonApplication {
pname = "aw-qt";
inherit version;

format = "pyproject";

src = "${sources}/aw-qt";

nativeBuildInputs = [
python3.pkgs.poetry-core
qt6.wrapQtAppsHook
];

propagatedBuildInputs = with python3.pkgs; [
aw-core
qt6.qtbase # Needed for qt6.wrapQtAppsHook
qt6.qtsvg # Rendering icons in the trayicon menu
pyqt6
click
];

# Prevent double wrapping
dontWrapQtApps = true;

postPatch = ''
sed -E 's#PyQt6 = "6.3.1"#PyQt6 = "^6.4.0"#g' -i pyproject.toml
sed -E 's#build-backend = "poetry.masonry.api"#build-backend = "poetry.core.masonry.api"#g' -i pyproject.toml
'';

postInstall = ''
install -D resources/aw-qt.desktop $out/share/applications/aw-qt.desktop
# For the actual tray icon, see
# https://github.com/ActivityWatch/aw-qt/blob/8ec5db941ede0923bfe26631acf241a4a5353108/aw_qt/trayicon.py#L211-L218
install -D media/logo/logo.png $out/lib/python3.10/site-packages/media/logo/logo.png
# For .desktop file and your desktop environment
install -D media/logo/logo.svg $out/share/icons/hicolor/scalable/apps/activitywatch.svg
install -D media/logo/logo.png $out/share/icons/hicolor/512x512/apps/activitywatch.png
install -D media/logo/logo-128.png $out/share/icons/hicolor/128x128/apps/activitywatch.png
'';

preFixup = ''
makeWrapperArgs+=(
"''${qtWrapperArgs[@]}"
)
'';

meta = with lib; {
description = "Tray icon that manages ActivityWatch processes, built with Qt";
homepage = "https://github.com/ActivityWatch/aw-qt";
maintainers = with maintainers; [ huantian ];
license = licenses.mpl20;
};
};

aw-server-rust = rustPlatform.buildRustPackage {
name = "aw-server-rust";
inherit version;

src = "${sources}/aw-server-rust";

cargoHash = "sha256-KWefX7AU+nOWy5cmE9FYAG6OToWYQ72gBaDqrtJCzxM=";

# Bypass rust nightly features not being available on rust stable
RUSTC_BOOTSTRAP = 1;

nativeBuildInputs = [
makeWrapper
pkg-config
perl
];

buildInputs = [
openssl
];

postFixup = ''
wrapProgram "$out/bin/aw-server" \
--prefix XDG_DATA_DIRS : "$out/share"
mkdir -p "$out/share/aw-server"
ln -s "${aw-webui}" "$out/share/aw-server/static"
'';

preCheck = ''
# Fake home folder for tests that use ~/.cache and ~/.local/share
export HOME="$TMP/fake-test-home"
'';

meta = with lib; {
description = "High-performance implementation of the ActivityWatch server, written in Rust";
homepage = "https://github.com/ActivityWatch/aw-server-rust";
maintainers = with maintainers; [ huantian ];
mainProgram = "aw-server";
platforms = platforms.linux;
license = licenses.mpl20;
};
};

aw-webui = buildNpmPackage {
pname = "aw-webui";
inherit version;

src = "${sources}/aw-server-rust/aw-webui";

npmDepsHash = "sha256-yds2P2PKfTB6yUGnc+P73InV5+MZP9kmz2ZS4CRqlmA=";

patches = [
# Hardcode version to avoid the need to have the Git repo available at build time.
(substituteAll {
src = ./commit-hash.patch;
commit_hash = sources.rev;
})
];

installPhase = ''
runHook preInstall
mv dist $out
runHook postInstall
'';

meta = with lib; {
description = "A web-based UI for ActivityWatch, built with Vue.js";
homepage = "https://github.com/ActivityWatch/aw-webui/";
maintainers = with maintainers; [ huantian ];
license = licenses.mpl20;
};
};
}
6 changes: 6 additions & 0 deletions pkgs/top-level/all-packages.nix
Original file line number Diff line number Diff line change
Expand Up @@ -28168,6 +28168,12 @@ with pkgs;

acorn = callPackage ../applications/networking/cluster/acorn {};

inherit (callPackage ../applications/office/activitywatch { })
aw-qt
aw-server-rust
aw-watcher-afk
aw-watcher-window;

adobe-reader = pkgsi686Linux.callPackage ../applications/misc/adobe-reader { };

adl = callPackage ../applications/video/adl { };
Expand Down

0 comments on commit f1d2216

Please sign in to comment.