started flakes

This commit is contained in:
John Lancaster
2024-12-04 22:03:18 -06:00
parent 809d4ee6c1
commit afbc973248
4 changed files with 105 additions and 12 deletions

11
appdaemon/devenv.nix Normal file
View File

@@ -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";
}

68
appdaemon/flake.nix Normal file
View File

@@ -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";
};
};
}

View File

@@ -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

View File

@@ -1,13 +1,26 @@
{ pkgs ? import <nixpkgs> {}, unstable ? import <nixpkgs-unstable> {} }:
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"
'';
}