diff --git a/appdaemon/devenv.nix b/appdaemon/devenv.nix new file mode 100644 index 0000000..38fefae --- /dev/null +++ b/appdaemon/devenv.nix @@ -0,0 +1,11 @@ +{ pkgs, config, ... }: { + # This is your devenv configuration + packages = [ pkgs.hello ]; + + enterShell = '' + export PS1="\[\033[01;34m\](AppDaemon)\[\033[00m\] \[\]\[\]\n\[\033[1;32m\][\[\e]0;\u@\h: \w\a\]\u@\h:\w]\$\[\033[0m\] \[\]\[\]" + echo "AppDaemon v$(uv pip show appdaemon | awk '/^Version:/ {print $2}') development shell started" + ''; + + processes.run.exec = "hello"; +} diff --git a/appdaemon/flake.nix b/appdaemon/flake.nix new file mode 100644 index 0000000..71b2907 --- /dev/null +++ b/appdaemon/flake.nix @@ -0,0 +1,68 @@ +{ + description = "AppDaemon development"; + + inputs = { + nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; + devenv.url = "github:cachix/devenv"; + }; + + # nixConfig = { + # extra-trusted-public-keys = "devenv.cachix.org-1:w1cLUi8dv3hnoSPGAuibQv+f9TZLr6cv/Hm9XgU50cw="; + # extra-substituters = "https://devenv.cachix.org"; + # }; + + outputs = { self, nixpkgs, devenv, ... } @ inputs: + let + system = "x86_64-linux"; + pkgs = nixpkgs.legacyPackages.${system}; + python = pkgs.python312; + adPath = "/usr/src/app"; + # uv = "${pkgs.uv}/bin/uv"; + in + { + packages.${system}.devenv-up = self.devShells.${system}.default.config.procfileScript; + packages.${system}.devenv-test = self.devShells.${system}.default.config.test; + + devShells.${system}.default = devenv.lib.mkShell { + inherit inputs pkgs; + modules = [ + ./devenv.nix + ]; + }; + + devShells.${system}.native = pkgs.mkShell { + nativeBuildInputs = with pkgs; [ + git + uv + python + ]; + + packages = with pkgs; [ + (writeShellScriptBin "cd-ad" "cd ${adPath}") + (writeShellScriptBin "full-build" '' + rm -rf ${adPath}/build ${adPath}/dist + ${pkgs.uv}/bin/uv build --wheel ${adPath} + docker build -t acockburn/appdaemon:local-dev ${adPath} + '') + ]; + + shellHook = '' + cd ${adPath} + echo "URL: $(${pkgs.git}/bin/git config --get remote.origin.url)" + echo "Branch: $(${pkgs.git}/bin/git rev-parse --abbrev-ref HEAD)" + echo "Hash: $(${pkgs.git}/bin/git rev-parse --short HEAD)" + + ${pkgs.uv}/bin/uv sync -U --all-extras + export UV_PYTHON="${adPath}/.venv/bin/python" + alias clean="rm -rf ${adPath}/dist ${adPath}/build" + alias appdaemon="${pkgs.uv}/bin/uv run --frozen python -m appdaemon" + alias ad="appdaemon" + + export PS1="\[\033[01;34m\](AppDaemon)\[\033[00m\] \[\]\[\]\n\[\033[1;32m\][\[\e]0;\u@\h: \w\a\]\u@\h:\w]\$\[\033[0m\] \[\]\[\]" + echo "AppDaemon v$(uv pip show appdaemon | awk '/^Version:/ {print $2}') development shell started" + ''; + + UV_LINK_MODE = "copy"; + }; + }; +} diff --git a/configuration.nix b/configuration.nix index 3af1b1a..2856a7b 100644 --- a/configuration.nix +++ b/configuration.nix @@ -18,10 +18,15 @@ in ./portainer.nix ./watchtower.nix ]; + nix.settings.experimental-features = [ "nix-command" "flakes" ]; environment.systemPackages = with pkgs; [ (pkgs.writeShellScriptBin "nrbs" "sudo nixos-rebuild switch") (pkgs.writeShellScriptBin "nrbsu" "sudo nix-channel --update && sudo nixos-rebuild switch") + (pkgs.writeShellScriptBin "ads" '' + cd ${adPath} + nix develop + '') (pkgs.writeShellScriptBin "ad-clone" '' if [ ! -d ${adPath} ]; then sudo git clone -b ${adBranch} ${adRepo} ${adPath} @@ -30,7 +35,7 @@ in echo "${adPath} already exists" fi '') - unstable.uv + # unstable.uv bash git eza diff --git a/shell.nix b/shell.nix index d3a8e28..2371bac 100644 --- a/shell.nix +++ b/shell.nix @@ -1,13 +1,26 @@ { pkgs ? import {}, unstable ? import {} }: - pkgs.mkShell { - buildInputs = [ - pkgs.python312 - unstable.uv - unstable.python312Packages.ipykernel - unstable.python312Packages.rich + packages = [ + pkgs.git + (pkgs.python312.withPackages (python-pkgs: with python-pkgs; [ + pip + setuptools + wheel + + # pyproject deps + aiohttp + astral + bcrypt + deepdiff + feedparser + iso8601 + paho-mqtt + requests + uvloop + pydantic + click + ])) ]; - shellHook = '' echo "Welcome to the Nix shell for AppDaemon development" cd /usr/src/app @@ -20,9 +33,5 @@ pkgs.mkShell { alias fbuild="build && dbuild" alias clean="cd /usr/src/app && rm -rf ./build ./dist" alias ad="python -m appdaemon" - - uv sync --all-extras --upgrade --inexact - source .venv/bin/activate - echo -e "Built and activated virtual environment\n" ''; }