better flake using devenv

This commit is contained in:
John Lancaster
2024-12-05 00:06:59 -06:00
parent afbc973248
commit cc6cb9ffcc
4 changed files with 374 additions and 72 deletions

View File

@@ -1,68 +1,78 @@
{
description = "AppDaemon development";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
devenv.url = "github:cachix/devenv";
nixpkgs-python = {
url = "github:cachix/nixpkgs-python";
inputs = { nixpkgs.follows = "nixpkgs"; };
};
};
# nixConfig = {
# extra-trusted-public-keys = "devenv.cachix.org-1:w1cLUi8dv3hnoSPGAuibQv+f9TZLr6cv/Hm9XgU50cw=";
# extra-substituters = "https://devenv.cachix.org";
# };
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;
let
system = "x86_64-linux";
pkgs = nixpkgs.legacyPackages.${system};
adPath = "/usr/src/app";
in
{
packages.${system} = {
devenv-up = self.devShells.${system}.default.config.procfileScript;
devenv-test = self.devShells.${system}.default.config.test;
};
devShells.${system}.default = devenv.lib.mkShell {
inherit inputs pkgs;
modules = [
./devenv.nix
];
devShells.${system}.default = devenv.lib.mkShell {
inherit inputs pkgs;
modules = [
({ pkgs, config, ... }: {
# This is your devenv configuration
pre-commit.hooks = {
end-of-file-fixer.enable = true;
trim-trailing-whitespace.enable = true;
};
languages.python = {
enable = true;
version = "3.12.7";
uv = {
enable = true;
sync = {
enable = true;
allExtras = true;
arguments = [ "-U" ];
};
};
};
packages = with pkgs; [
git
(writeShellScriptBin "full-build" ''
cd ${adPath}
${pkgs.uv}/bin/uv build --wheel
docker build -t acockburn/appdaemon:local-dev ${adPath}
'')
];
enterShell = ''
alias appdaemon="${pkgs.uv}/bin/uv run --frozen python -m appdaemon"
alias ad="appdaemon"
export PS1="\[\e[0;34m\](AppDaemon)\[\e[0m\] ''${PS1-}"
export VIRTUAL_ENV=$UV_PROJECT_ENVIRONMENT
echo -e "URL: \e[34m$(${pkgs.git}/bin/git config --get remote.origin.url)\e[0m"
echo -e "Branch: \e[32m$(${pkgs.git}/bin/git rev-parse --abbrev-ref HEAD)\e[0m"
echo -e "Hash: \e[33m$(${pkgs.git}/bin/git rev-parse --short HEAD)\e[0m"
echo "AppDaemon v$(${pkgs.uv}/bin/uv pip show appdaemon | awk '/^Version:/ {print $2}') development shell started"
'';
})
];
};
};
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";
};
};
}
}