mirror of
https://codeberg.org/muon/home.git
synced 2026-03-08 03:25:16 +00:00
Fix hr script
This commit is contained in:
parent
4e694a33ce
commit
da692f477c
4 changed files with 117 additions and 135 deletions
|
|
@ -9,7 +9,7 @@
|
|||
./development.nix
|
||||
./tools.nix
|
||||
./yazi.nix
|
||||
./hr.nix
|
||||
./hr
|
||||
./helix
|
||||
./nvim
|
||||
./zellij
|
||||
|
|
|
|||
|
|
@ -1,134 +0,0 @@
|
|||
{
|
||||
pkgs,
|
||||
lib,
|
||||
config,
|
||||
...
|
||||
}: let
|
||||
cfg = config.mods.terminal;
|
||||
|
||||
hr-script = pkgs.writeShellScriptBin "hr" ''
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -e
|
||||
|
||||
if [ "$1" = "init" ] && [ "$2" = "py" ]; then
|
||||
echo "Initializing python devenv..."
|
||||
|
||||
# 1. Init devenv
|
||||
if [ -f .gitignore ]; then
|
||||
cp .gitignore .gitignore.bak
|
||||
fi
|
||||
|
||||
if command -v devenv >/dev/null; then
|
||||
devenv init
|
||||
echo "Direnv allowed"
|
||||
else
|
||||
echo "Error: devenv not found in path."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ -f .gitignore.bak ]; then
|
||||
mv .gitignore.bak .gitignore
|
||||
elif [ -f .gitignore ]; then
|
||||
rm .gitignore
|
||||
fi
|
||||
|
||||
# 2. Replace devenv.nix
|
||||
cat <<EOF > devenv.nix
|
||||
{pkgs, ...}: {
|
||||
packages = [ pkgs.google-cloud-sdk ];
|
||||
|
||||
languages.python = {
|
||||
enable = true;
|
||||
venv.enable = true;
|
||||
uv = {
|
||||
enable = true;
|
||||
sync.enable = false;
|
||||
};
|
||||
};
|
||||
|
||||
# We use the named index "google" defined in pyproject.toml
|
||||
# This environment variable overrides the URL for that index, allow it to be configured here
|
||||
env.UV_INDEX_GOOGLE_URL = "https://europe-west1-python.pkg.dev/mk2-prod/python-packages/simple/";
|
||||
env.UV_INDEX_GOOGLE_USERNAME = "oauth2accesstoken";
|
||||
|
||||
enterShell = \'\'
|
||||
if ! gcloud auth print-access-token >/dev/null 2>&1; then
|
||||
echo "⚠️ gcloud not authenticated. Run 'gcloud auth login' to access Google Artifact Registry."
|
||||
else
|
||||
export UV_INDEX_GOOGLE_PASSWORD=$(gcloud auth print-access-token)
|
||||
fi
|
||||
uv sync
|
||||
\'\';
|
||||
}
|
||||
EOF
|
||||
|
||||
# 3. Add to local git exclude
|
||||
if git rev-parse --git-dir > /dev/null 2>&1; then
|
||||
EXCLUDE_FILE=$(git rev-parse --git-path info/exclude)
|
||||
mkdir -p "$(dirname "$EXCLUDE_FILE")"
|
||||
|
||||
IGNORES=(
|
||||
".devenv\*"
|
||||
".direnv"
|
||||
"devenv.nix"
|
||||
"devenv.yaml"
|
||||
"devenv.lock"
|
||||
"uv.lock"
|
||||
".envrc"
|
||||
)
|
||||
|
||||
for file in "''${IGNORES[@]}"; do
|
||||
if ! grep -q "^$file$" "$EXCLUDE_FILE"; then
|
||||
echo "$file" >> "$EXCLUDE_FILE"
|
||||
echo "Added $file to local git exclude ($EXCLUDE_FILE)"
|
||||
fi
|
||||
done
|
||||
else
|
||||
echo "Warning: Not a git repository. Skipping git ignore setup."
|
||||
fi
|
||||
|
||||
# 5. Install dependencies
|
||||
echo "Installing dependencies..."
|
||||
|
||||
direnv exec . pip install keyrings.google-artifactregistry-auth==1.1.2
|
||||
|
||||
if [ -f pyproject.toml ]; then
|
||||
# Extract optional dependencies from [project.optional-dependencies]
|
||||
OPTIONALS=$(sed -n '/^\[project.optional-dependencies\]/,/^\[/p' pyproject.toml | grep -v '^\[' | grep '=' | cut -d= -f1 | tr -d ' \t' | tr '\n' ',' | sed 's/,$//')
|
||||
|
||||
if [ -n "$OPTIONALS" ]; then
|
||||
echo "Found optional dependencies: $OPTIONALS"
|
||||
direnv exec . pip install -e ".[$OPTIONALS]"
|
||||
else
|
||||
echo "No optional dependencies found in pyproject.toml."
|
||||
direnv exec . pip install -e .
|
||||
fi
|
||||
elif [ -f requirements.txt ]; then
|
||||
echo "Installing from requirements.txt..."
|
||||
pip install -r requirements.txt
|
||||
fi
|
||||
|
||||
# 4. Allow direnv
|
||||
if command -v direnv >/dev/null; then
|
||||
direnv allow
|
||||
echo "Direnv allowed"
|
||||
else
|
||||
echo "Error: direnv not found in path."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
else
|
||||
echo "Usage: hr init py"
|
||||
echo " init py Initialize a python devenv environment (git-ignored)"
|
||||
exit 1
|
||||
fi
|
||||
'';
|
||||
in {
|
||||
options.mods.terminal.hr.enable = lib.mkEnableOption "Hefring (Work Tooling)";
|
||||
|
||||
config = lib.mkIf cfg.hr.enable {
|
||||
home.packages = [hr-script];
|
||||
};
|
||||
}
|
||||
16
modules/home/terminal/hr/default.nix
Normal file
16
modules/home/terminal/hr/default.nix
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
{
|
||||
pkgs,
|
||||
lib,
|
||||
config,
|
||||
...
|
||||
}: let
|
||||
cfg = config.mods.terminal;
|
||||
|
||||
hr = pkgs.writeShellScriptBin "hr" (builtins.readFile ./hr.sh);
|
||||
in {
|
||||
options.mods.terminal.hr.enable = lib.mkEnableOption "Hefring (Work Tooling)";
|
||||
|
||||
config = lib.mkIf cfg.hr.enable {
|
||||
home.packages = [hr];
|
||||
};
|
||||
}
|
||||
100
modules/home/terminal/hr/hr.sh
Normal file
100
modules/home/terminal/hr/hr.sh
Normal file
|
|
@ -0,0 +1,100 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
set -e
|
||||
|
||||
if [ "$1" = "py" ] && [ "$2" = "init" ]; then
|
||||
echo "Initializing python devenv..."
|
||||
|
||||
# 1. Init devenv
|
||||
if [ -f .gitignore ]; then
|
||||
cp .gitignore .gitignore.bak
|
||||
fi
|
||||
|
||||
if command -v devenv >/dev/null; then
|
||||
devenv init
|
||||
echo "Direnv allowed"
|
||||
else
|
||||
echo "Error: devenv not found in path."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ -f .gitignore.bak ]; then
|
||||
mv .gitignore.bak .gitignore
|
||||
elif [ -f .gitignore ]; then
|
||||
rm .gitignore
|
||||
fi
|
||||
|
||||
# 2. Replace devenv.nix
|
||||
cat <<EOF >devenv.nix
|
||||
{pkgs, ...}: {
|
||||
packages = [ pkgs.google-cloud-sdk ];
|
||||
|
||||
languages.python = {
|
||||
enable = true;
|
||||
venv.enable = true;
|
||||
uv = {
|
||||
enable = true;
|
||||
sync.enable = false;
|
||||
};
|
||||
};
|
||||
|
||||
# We use the named index "google" defined in uv.toml
|
||||
env.UV_INDEX_GOOGLE_USERNAME = "oauth2accesstoken";
|
||||
|
||||
enterShell = ''
|
||||
if ! gcloud auth print-access-token >/dev/null 2>&1; then
|
||||
echo "⚠️ gcloud not authenticated. Run 'gcloud auth login' to access Google Artifact Registry."
|
||||
else
|
||||
export UV_INDEX_GOOGLE_PASSWORD=\$(gcloud auth print-access-token)
|
||||
fi
|
||||
uv sync
|
||||
'';
|
||||
}
|
||||
EOF
|
||||
|
||||
cat <<EOF >uv.toml
|
||||
[[index]]
|
||||
name = "google"
|
||||
url = "https://europe-west1-python.pkg.dev/mk2-prod/python-packages/simple/"
|
||||
EOF
|
||||
|
||||
# 3. Add to local git exclude
|
||||
if git rev-parse --git-dir >/dev/null 2>&1; then
|
||||
EXCLUDE_FILE=$(git rev-parse --git-path info/exclude)
|
||||
mkdir -p "$(dirname "$EXCLUDE_FILE")"
|
||||
|
||||
IGNORES=(
|
||||
".devenv*"
|
||||
".direnv"
|
||||
"devenv.nix"
|
||||
"devenv.yaml"
|
||||
"devenv.lock"
|
||||
"uv.lock"
|
||||
"uv.toml"
|
||||
".envrc"
|
||||
)
|
||||
|
||||
for file in "${IGNORES[@]}"; do
|
||||
if ! grep -q "^$file$" "$EXCLUDE_FILE"; then
|
||||
echo "$file" >>"$EXCLUDE_FILE"
|
||||
echo "Added $file to local git exclude ($EXCLUDE_FILE)"
|
||||
fi
|
||||
done
|
||||
else
|
||||
echo "Warning: Not a git repository. Skipping git ignore setup."
|
||||
fi
|
||||
|
||||
# 4. Allow direnv
|
||||
if command -v direnv >/dev/null; then
|
||||
direnv allow
|
||||
echo "Direnv allowed"
|
||||
else
|
||||
echo "Error: direnv not found in path."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
else
|
||||
echo "Usage: hr py init"
|
||||
echo " py init Initialize a python devenv environment (git-ignored)"
|
||||
exit 1
|
||||
fi
|
||||
Loading…
Add table
Add a link
Reference in a new issue