diff --git a/.forgejo/workflows/build.yml b/.forgejo/workflows/build.yml index 093fc99..c12789f 100644 --- a/.forgejo/workflows/build.yml +++ b/.forgejo/workflows/build.yml @@ -58,6 +58,10 @@ jobs: run: | nix build '.#vuetorrent' attic push ${{ secrets.ATTIC_CACHE }} $(nix-store -qR --include-outputs $(nix-store -qd ./result) | grep -v '\.drv$') + - name: Build weewx + run: | + nix build '.#weewx' + attic push ${{ secrets.ATTIC_CACHE }} $(nix-store -qR --include-outputs $(nix-store -qd ./result) | grep -v '\.drv$') build-arm64-linux: runs-on: nix-arm64 diff --git a/flake.lock b/flake.lock index 0884750..49e8de5 100644 --- a/flake.lock +++ b/flake.lock @@ -18,13 +18,52 @@ "type": "github" } }, + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1710146030, + "narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nix-github-actions": { + "inputs": { + "nixpkgs": [ + "poetry2nix", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1703863825, + "narHash": "sha256-rXwqjtwiGKJheXB43ybM8NwWB8rO2dSRrEqes0S7F5Y=", + "owner": "nix-community", + "repo": "nix-github-actions", + "rev": "5163432afc817cf8bd1f031418d1869e4c9d5547", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "nix-github-actions", + "type": "github" + } + }, "nixpkgs": { "locked": { - "lastModified": 1719540504, - "narHash": "sha256-SIbmh3yyPmzLI+qHlMC/pJVfo4ISFu1OORo5YLFk8o0=", + "lastModified": 1719629854, + "narHash": "sha256-BheGh2LLDet7B7VX+S56M99LuwAMsqJhdBTRw3gr95o=", "owner": "nixos", "repo": "nixpkgs", - "rev": "33be72b31b7cc5a0b43cc3b6c005cf4e4d47d899", + "rev": "5e87fb56fd499ee4090e6ed939561a9470ac5f53", "type": "github" }, "original": { @@ -46,10 +85,85 @@ "url": "https://github.com/NixOS/nixpkgs/archive/eb9ceca17df2ea50a250b6b27f7bf6ab0186f198.tar.gz" } }, + "poetry2nix": { + "inputs": { + "flake-utils": "flake-utils", + "nix-github-actions": "nix-github-actions", + "nixpkgs": [ + "nixpkgs" + ], + "systems": "systems_2", + "treefmt-nix": "treefmt-nix" + }, + "locked": { + "lastModified": 1719549552, + "narHash": "sha256-efvBV+45uQA6r7aov48H6MhvKp1QUIyIX5gh9oueUzs=", + "owner": "nix-community", + "repo": "poetry2nix", + "rev": "4fd045cdb85f2a0173021a4717dc01d92d7ab2b2", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "poetry2nix", + "type": "github" + } + }, "root": { "inputs": { "flake-parts": "flake-parts", - "nixpkgs": "nixpkgs" + "nixpkgs": "nixpkgs", + "poetry2nix": "poetry2nix" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, + "systems_2": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "id": "systems", + "type": "indirect" + } + }, + "treefmt-nix": { + "inputs": { + "nixpkgs": [ + "poetry2nix", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1718522839, + "narHash": "sha256-ULzoKzEaBOiLRtjeY3YoGFJMwWSKRYOic6VNw2UyTls=", + "owner": "numtide", + "repo": "treefmt-nix", + "rev": "68eb1dc333ce82d0ab0c0357363ea17c31ea1f81", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "treefmt-nix", + "type": "github" } } }, diff --git a/flake.nix b/flake.nix index a3f6752..d41cb4c 100644 --- a/flake.nix +++ b/flake.nix @@ -4,6 +4,11 @@ nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable-small"; flake-parts.url = "github:hercules-ci/flake-parts"; + + poetry2nix = { + url = "github:nix-community/poetry2nix"; + inputs.nixpkgs.follows = "nixpkgs"; + }; }; outputs = inputs@{ flake-parts, ... }: @@ -24,6 +29,8 @@ let inherit (pkgs) callPackage; + poetry2nix = inputs.poetry2nix.lib.mkPoetry2Nix { inherit pkgs; }; + darwinPackages = if lib.hasSuffix "darwin" system then { cliclick = callPackage ./packages/cliclick.nix { }; @@ -43,6 +50,7 @@ rexit = callPackage ./packages/rexit.nix { }; tg-archive = callPackage ./packages/tg-archive.nix { }; vuetorrent = callPackage ./packages/vuetorrent.nix { }; + weewx = callPackage ./packages/weewx.nix { inherit poetry2nix; }; weewx-proxy = callPackage ./packages/weewx-proxy.nix { }; } // darwinPackages; diff --git a/packages/weewx.nix b/packages/weewx.nix new file mode 100644 index 0000000..9b30d8e --- /dev/null +++ b/packages/weewx.nix @@ -0,0 +1,105 @@ +{ pkgs, lib, poetry2nix }: + +let + python = pkgs.python311; + pythonPackages = pkgs.python311Packages; + + weewx = pkgs.fetchFromGitHub { + owner = "weewx"; + repo = "weewx"; + rev = "v5.0.2"; + hash = "sha256-UVHoi+hXcpbledeXlZ+7TDwIeLIXYazmpDcwW3QW5BY="; + }; + + plugin-weewx-mqtt = pkgs.fetchurl { + url = "https://github.com/matthewwall/weewx-mqtt/archive/d1739f3d57f07f402ddd3c20ac10ad5f874be1e9.zip"; + hash = "sha256-mNfZlrJPCo/vD5Dgt8PYa6ZHN+rTqqIA6c7MozY9Vss="; + }; + + plugin-weewx-mqtt-subscribe = pkgs.fetchurl { + url = "https://github.com/bellrichm/weewx-mqttsubscribe/archive/refs/tags/v2.3.1.zip"; + hash = "sha256-co9fTm6vBZzg2jSKi7kmi7n//pi/bLE3rJhTT2O1ZtE="; + }; + + plugin-weewx-gts = pkgs.fetchurl { + url = "https://github.com/roe-dl/weewx-GTS/archive/3d9c04d4fc2541b555c2a3274c4dc093126fab2e.zip"; + hash = "sha256-h5tomXhi0Me+tJtfrvgePGLDo4sQm+0SkrndOWjVUzw="; + }; + + plugin-weewx-purpleair = pkgs.fetchurl { + url = "https://github.com/bakerkj/weewx-purpleair/archive/refs/tags/v0.9.zip"; + hash = "sha256-L7mzbsb/Ewzd6kCrceOESMzEJDLjshFohgVK2U5/ZsM="; + }; + + plugin-weewx-aqi = pkgs.fetchurl { + url = "https://github.com/jonathankoren/weewx-aqi/archive/refs/tags/v1.4.1.zip"; + hash = "sha256-jDZPfhkLm2aRqeeevJadqNZBHgcYcHvYBxW6HFmJQUE="; + }; + + plugin-weewx-wdc = pkgs.fetchurl { + url = "https://github.com/Daveiano/weewx-wdc/releases/download/v3.5.1/weewx-wdc-v3.5.1.zip"; + hash = "sha256-MPjh/a6+f668yfD5AyCWFmyD1Q5p8nxCzESOUKx7wkQ="; + }; +in +poetry2nix.mkPoetryApplication { + inherit python; + projectDir = weewx; + + overrides = poetry2nix.defaultPoetryOverrides.extend (final: prev: { + ct3 = prev.ct3.overridePythonAttrs (old: { + buildInputs = (old.buildInputs or [ ]) ++ [ prev.setuptools ]; + }); + + pyserial = prev.pyserial.overridePythonAttrs (old: { + buildInputs = (old.buildInputs or [ ]) ++ [ prev.setuptools ]; + }); + }); + + nativeBuildInputs = with pythonPackages; [ + # Poetry (?) + cachecontrol + cleo + crashtest + dulwich + fastjsonschema + keyring + pexpect + pkginfo + platformdirs + poetry-core + requests-toolbelt + shellingham + tomlkit + trove-classifiers + virtualenv + xattr + + pkgs.poetry + pkgs.poetryPlugins.poetry-plugin-export + pkgs.unzip + ]; + + buildInputs = with pythonPackages; [ + paho-mqtt + requests + ]; + + postPatch = '' + substituteInPlace pyproject.toml --replace-fail "poetry.masonry" "poetry.core.masonry" + ''; + + postInstall = '' + mkdir -p $out/home/weewx-data + cp $out/lib/*/site-packages/weewx_data/weewx.conf $out/home/weewx-data/ + + mkdir $TMPDIR/weewx-wdc/ + unzip ${plugin-weewx-wdc} -d $TMPDIR/weewx-wdc/ + + HOME=$out/home $out/bin/weectl extension install ${plugin-weewx-mqtt} --yes + HOME=$out/home $out/bin/weectl extension install ${plugin-weewx-mqtt-subscribe} --yes + HOME=$out/home $out/bin/weectl extension install ${plugin-weewx-gts} --yes + HOME=$out/home $out/bin/weectl extension install ${plugin-weewx-purpleair} --yes + HOME=$out/home $out/bin/weectl extension install ${plugin-weewx-aqi} --yes + HOME=$out/home $out/bin/weectl extension install $TMPDIR/weewx-wdc/ --yes + ''; +}