NixOS / nixpkgs

Nix Packages collection & NixOS
MIT License
18.07k stars 14.13k forks source link

ActivityWatch #97379

Closed voobscout closed 1 year ago

voobscout commented 4 years ago

Project description

ActivityWatch is an app that automatically tracks how you spend time on your devices.

It is open source, privacy-first, cross-platform, and a great alternative to services like RescueTime, ManicTime, and WakaTime.

It can be used to keep track of your productivity, time spent on different projects, bad screen habits, or just to understand how you spend your time.

Metadata

Screenshots

cyphase commented 4 years ago

Docs on installing from source: https://docs.activitywatch.net/en/latest/installing-from-source.html

stale[bot] commented 3 years ago

I marked this as stale due to inactivity. → More info

jtojnar commented 3 years ago

I have an expression for the server in my configs repo. https://github.com/jtojnar/nixfiles/pull/2 Unfortunately, it currently depends on unstable rust so it cannot be packaged in nixpkgs easily.

Edit: Now I packaged the rest too: https://github.com/jtojnar/nixfiles/blob/92406b6eda10c4e2c36b5fd7256ef3bcbfbaa085/pkgs/activitywatch/default.nix

skogsbrus commented 3 years ago

@jtojnar Do you know if it should be possible to get this published on nixpkgs if we get a derivation based on the python server working?

jtojnar commented 3 years ago

@skogsbrus It might even be possible to package the Rust server using the RUSTC_BOOTSTRAP = 1 hack. Another concern is the webui, which will require replacing npmlock2nix by something to avoid IFD, which is not allowed in Nixpkgs either.

skogsbrus commented 3 years ago

Made some progress tonight on this with the python server. I can install all modules and run aw-qt. The flask server responds to requests from the chrome extension, but I get 404s :thinking: Probably some paths that aren't included in the install somehow

Current state: https://github.com/skogsbrus/os/pull/6/files

As for the web ui, I don't think we need to include it? AFAIK it's just the code for the web extensions. The official releases don't even include it.

Copied most of the modules from yours @jtojnar, so really thanks for your work! :pray:

Edit: So I think the 404s are due to me not packaging aw-webui... Guess we'll need it after all. Seems to be included in the official releases under the aw-server* components

skogsbrus commented 3 years ago

Status update:

Tried adding aw-webui with mkYarnPackage, but have gotten stock on this obscure error (PR above has been updated):

johanan@voidm ~/os/home/pkgs/activitywatch nix-build
these 3 derivations will be built:
  /nix/store/ryj0li9bzcz6ap2k1cl4b2zskv80fbam-aw-webui.drv
  /nix/store/f066h4rcl9jc3xlliw3iqaqk8insgg0x-aw-server-johanan-beta1.drv
  /nix/store/4w12q82p7gfcy4pa06ga3mb27bllmlxf-activitywatch-johanan-beta1.drv
building '/nix/store/ryj0li9bzcz6ap2k1cl4b2zskv80fbam-aw-webui.drv'...
unpacking sources
unpacking source archive /nix/store/a6fjf7fl63qqk7bwssfk8agr50sw09j5-source/aw-server/aw-webui/.
source root is ./
patching sources
configuring
mv: cannot copy a directory, '/build', into itself, '/build/temp'
error: builder for '/nix/store/ryj0li9bzcz6ap2k1cl4b2zskv80fbam-aw-webui.drv' failed with exit code 1;
       last 6 log lines:
       > unpacking sources
       > unpacking source archive /nix/store/a6fjf7fl63qqk7bwssfk8agr50sw09j5-source/aw-server/aw-webui/.
       > source root is ./
       > patching sources
       > configuring
       > mv: cannot copy a directory, '/build', into itself, '/build/temp'
       For full logs, run 'nix log /nix/store/ryj0li9bzcz6ap2k1cl4b2zskv80fbam-aw-webui.drv'.
error: 1 dependencies of derivation '/nix/store/4w12q82p7gfcy4pa06ga3mb27bllmlxf-activitywatch-johanan-beta1.drv' failed to build
johanan@voidm ~/os/home/pkgs/activitywatch

I barely know what I'm doing here so this will take quite a few iterations... :)

skogsbrus commented 3 years ago

@meain helped me solve the above issue. Now I'm just trying to get the static folder that is built by aw-webui to be installed in the same folder as the aw_server site package, since it's looking for a static folder in the same path as server.py.

skogsbrus commented 2 years ago

So, lots of time has past but I've got a local derivation working now. Haven't had the time to look into how to create a service that can be uploaded to nixpkgs, but this works locally with (pkgs.callPackage ./activitywatch {}) (assuming the zip contents exist in ./activitywatch.

Hopefully this is enough for anyone Nix-knowledgeable to package this into something sensible? Otherwise I might be able to do it in a few more months... :)

aw.zip:

Note: Unlike @jtojnar's derivation, this uses the python server. Uses yarn2nix though - not sure how well that plays with "which will require replacing npmlock2nix by something to avoid IFD".

voobscout commented 2 years ago

@skogsbrus Thank you for the derivation, perhaps you could use it like this:

{
  home-manager.sharedModules = [
    ({ config, lib, pkgs, ... }:
      with lib;
      let
        cfg = config.programs.activitywatch;
      in
      {
        options.programs.activitywatch = with types; {
          enable = mkEnableOption "Enable activitywatch";
          package = mkOption { type = package; default = pkgs.activitywatch; };
        };

        config = mkMerge [
          (mkIf cfg.enable {
            systemd.user.services.activitywatch = {
              Unit.Description = "activitywatch tray-icon";
              Service.ExecStart = (pkgs.writeShellScript "activitywatch-start" ''
                export PATH=$PATH:${makeBinPath [cfg.package]}
                aw-qt
              '').outPath;
              Service.Restart = "on-failure";
              Install.WantedBy = [ "graphical-session.target" ];
            };
          })
        ];
      }
    )
  ];
}
skogsbrus commented 2 years ago

@voobscout nice, I'll try it out. Would that then be a separate MR to the home-manager repo?

skogsbrus commented 2 years ago

Large release yesterday: https://github.com/ActivityWatch/activitywatch/releases/tag/v0.12.0