Migrate packages
This commit is contained in:
42
pkgs/conda-direnv/default.nix
Normal file
42
pkgs/conda-direnv/default.nix
Normal file
@ -0,0 +1,42 @@
|
||||
{
|
||||
conda,
|
||||
yq,
|
||||
writeShellApplication,
|
||||
}:
|
||||
|
||||
writeShellApplication {
|
||||
name = "conda-direnv";
|
||||
|
||||
runtimeInputs = [
|
||||
conda
|
||||
yq
|
||||
];
|
||||
|
||||
text = ''
|
||||
if [ ! -f environment.yml ]; then
|
||||
echo "environment.yml does not exist! Exiting..."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
ENV_NAME=$(${yq}/bin/yq ".name" environment.yml -r)
|
||||
if [ "$ENV_NAME" == "" ] || [ "$ENV_NAME" == "null" ]; then
|
||||
echo "Property \"name\" not in environment.yml or empty! Exiting..."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo Welcome to your conda environment "$ENV_NAME"! Activating...
|
||||
|
||||
condanew() {
|
||||
conda env create -f environment.yml -n $ENV_NAME
|
||||
conda activate $ENV_NAME
|
||||
}
|
||||
|
||||
exec ${conda}/bin/conda-shell
|
||||
conda activate $ENV_NAME || condanew
|
||||
|
||||
echo "Environment active! To update it, run:"
|
||||
echo -e "\tconda env update -f environment.yml -n $ENV_NAME"
|
||||
|
||||
"$SHELL" # needs to be last line so that conda-shell actually enters a shell
|
||||
'';
|
||||
}
|
16
pkgs/default.nix
Normal file
16
pkgs/default.nix
Normal file
@ -0,0 +1,16 @@
|
||||
{
|
||||
pkgs ? import <nixpkgs> { },
|
||||
...
|
||||
}:
|
||||
{
|
||||
conda-direnv = pkgs.callPackage ./conda-direnv { };
|
||||
deploy-to-pianopi = pkgs.callPackage ./deploy-to-pianopi { };
|
||||
edit-config = pkgs.callPackage ./edit-config { };
|
||||
hyprshot-gui = pkgs.callPackage ./hyprshot-gui { };
|
||||
install = pkgs.callPackage ./install { };
|
||||
lntocp = pkgs.callPackage ./lntocp { };
|
||||
open-messaging = pkgs.callPackage ./open-messaging { };
|
||||
pulseaudio-popup = pkgs.callPackage ./pulseaudio-popup { };
|
||||
sos = pkgs.callPackage ./sos { };
|
||||
xwacomcalibrate = pkgs.callPackage ./xwacomcalibrate { };
|
||||
}
|
26
pkgs/deploy-to-pianopi/default.nix
Normal file
26
pkgs/deploy-to-pianopi/default.nix
Normal file
@ -0,0 +1,26 @@
|
||||
{
|
||||
rsync,
|
||||
writeShellApplication,
|
||||
}:
|
||||
|
||||
writeShellApplication {
|
||||
name = "deploy-to-pianopi";
|
||||
|
||||
runtimeInputs = [ rsync ];
|
||||
|
||||
text = ''
|
||||
set -e
|
||||
set -x
|
||||
|
||||
nix build .#packages.aarch64-linux.default --print-out-paths
|
||||
# copy dependencies etc
|
||||
nix copy --to ssh://julian@pianopi.local .#packages.aarch64-linux.default
|
||||
|
||||
# This should be expanded on the client side
|
||||
# shellcheck disable=SC2029
|
||||
# ssh julian@pianopi.local ln -sf "$DERIVATION_PATH"/bin/\* /home/julian/.local/bin
|
||||
# ssh julian@pianopi.local nix profile install "$DERIVATION_PATH"
|
||||
|
||||
rsync -ac result/bin/ julian@pianopi.local:/home/julian/.local/bin
|
||||
'';
|
||||
}
|
34
pkgs/edit-config/default.nix
Normal file
34
pkgs/edit-config/default.nix
Normal file
@ -0,0 +1,34 @@
|
||||
{
|
||||
writeShellApplication,
|
||||
fd,
|
||||
fzf,
|
||||
}:
|
||||
writeShellApplication {
|
||||
name = "edit-config";
|
||||
|
||||
runtimeInputs = [
|
||||
fd
|
||||
fzf
|
||||
];
|
||||
|
||||
text = ''
|
||||
if [[ $# == 0 ]]; then
|
||||
QUERY=""
|
||||
else
|
||||
QUERY="$1"
|
||||
fi
|
||||
|
||||
FILE=$(fd -H -t f . ~/.dotfiles | fzf --query "$QUERY")
|
||||
if [[ "$FILE" != "" ]]; then
|
||||
$EDITOR "$FILE"
|
||||
else
|
||||
exit 1
|
||||
fi
|
||||
|
||||
read -rp 'Run "home-manager switch"? [Yn]: ' yn
|
||||
case $yn in
|
||||
Y | y | Yes | yes | "" ) home-manager switch;;
|
||||
* ) echo "Not switching home-manager configuration";;
|
||||
esac
|
||||
'';
|
||||
}
|
44
pkgs/hyprshot-gui/default.nix
Normal file
44
pkgs/hyprshot-gui/default.nix
Normal file
@ -0,0 +1,44 @@
|
||||
{
|
||||
lib,
|
||||
stdenv,
|
||||
fetchFromGitHub,
|
||||
makeWrapper,
|
||||
bash,
|
||||
hyprshot,
|
||||
zenity,
|
||||
}:
|
||||
|
||||
stdenv.mkDerivation rec {
|
||||
pname = "hyprshot-gui";
|
||||
version = "2023-10-20";
|
||||
|
||||
src = fetchFromGitHub {
|
||||
owner = "ThatOneCalculator";
|
||||
repo = pname;
|
||||
rev = "30a9bc377c1c0a3ad05c63945f2fe92709a99d7b";
|
||||
sha256 = "sha256-XUy6+mFbNL+3zDfS4tWva4DiJeLnRM9S8ECRayTcPfI=";
|
||||
};
|
||||
|
||||
nativeBuildInputs = [ makeWrapper ];
|
||||
|
||||
buildInputs = [
|
||||
bash
|
||||
hyprshot
|
||||
zenity
|
||||
];
|
||||
|
||||
dontBuild = true;
|
||||
installPhase = ''
|
||||
mkdir -p $out/bin
|
||||
cp hyprshot-gui $out/bin/hyprshot-gui
|
||||
wrapProgram $out/bin/hyprshot-gui --prefix PATH : '${lib.makeBinPath buildInputs}'
|
||||
'';
|
||||
|
||||
meta = with lib; {
|
||||
description = "A simple shell script";
|
||||
homepage = "https://github.com/ThatOneCalculator/hyprshot-gui";
|
||||
platforms = platforms.all;
|
||||
mainProgram = "hyprshot-gui";
|
||||
# maintainers
|
||||
};
|
||||
}
|
27
pkgs/install/default.nix
Normal file
27
pkgs/install/default.nix
Normal file
@ -0,0 +1,27 @@
|
||||
{ writeShellScriptBin, gum, ... }:
|
||||
# https://github.com/IogaMaster/dotfiles/blob/main/packages/install/default.nix
|
||||
writeShellScriptBin "install" ''
|
||||
${gum}/bin/gum style --border normal --margin "1" --padding "1 2" --border-foreground 212 "✨ IogaMaster's dotfiles installer ✨"
|
||||
echo "This script will wipe the remote system!"
|
||||
${gum}/bin/gum confirm "Cancel..." && exit
|
||||
|
||||
echo
|
||||
echo "🔥 kexec into the NixOS Installer..."
|
||||
ssh root@$2 'curl -L https://github.com/nix-community/nixos-images/releases/download/nixos-unstable/nixos-kexec-installer-noninteractive-x86_64-linux.tar.gz | tar -xzf- -C /root'
|
||||
ssh root@$2 '/root/kexec/run'
|
||||
|
||||
echo
|
||||
echo "⏰ Waiting for host nixos to come online..."
|
||||
while true; do ping -c1 nixos > /dev/null && break; done
|
||||
|
||||
echo
|
||||
echo "📥 Grabbing hardware config..."
|
||||
ssh root@nixos 'nixos-generate-config --show-hardware-config --root /mnt' > systems/x86_64-linux/$1/hardware-configuration.nix
|
||||
|
||||
echo
|
||||
echo "✅ Installing..."
|
||||
nix run github:nix-community/nixos-anywhere -- --flake .#$1 root@nixos
|
||||
|
||||
echo
|
||||
echo "✨ Done!!!"
|
||||
''
|
61
pkgs/lntocp/default.nix
Normal file
61
pkgs/lntocp/default.nix
Normal file
@ -0,0 +1,61 @@
|
||||
{
|
||||
writeShellApplication,
|
||||
}:
|
||||
|
||||
writeShellApplication {
|
||||
name = "lntocp";
|
||||
|
||||
runtimeInputs = [ ];
|
||||
|
||||
text = ''
|
||||
#!/bin/bash
|
||||
# This script accepts any number of files or directories as input.
|
||||
# If the input is a symbolic link, it deletes the symlink and copies
|
||||
# the original file or folder (where the symlink points to) to the location
|
||||
# where the symlink was. Non-symlink files or directories are ignored.
|
||||
|
||||
# Function to copy original file/folder in place of the symlink
|
||||
process_symlink() {
|
||||
symlink="$1"
|
||||
|
||||
# Resolve the target (the file or directory the symlink points to)
|
||||
target=$(readlink "$symlink")
|
||||
|
||||
# Check if the target is absolute or relative
|
||||
if [[ ! "$target" =~ ^/ ]]; then
|
||||
# If the target is relative, compute the full path
|
||||
target="$(dirname "$symlink")/$target"
|
||||
fi
|
||||
|
||||
# Check if the target exists
|
||||
if [ -e "$target" ]; then
|
||||
echo "Processing symlink: $symlink -> $target"
|
||||
|
||||
# Remove the symlink
|
||||
rm "$symlink"
|
||||
|
||||
# Copy the original target to the symlink location
|
||||
if [ -d "$target" ]; then
|
||||
# If it's a directory, use 'cp -r'
|
||||
cp -r "$target" "$symlink"
|
||||
else
|
||||
# Otherwise, it's a file, use 'cp'
|
||||
cp "$target" "$symlink"
|
||||
fi
|
||||
echo "Copied $target to $symlink"
|
||||
else
|
||||
echo "Target $target does not exist!"
|
||||
fi
|
||||
}
|
||||
|
||||
# Loop through all arguments (files and directories passed to the script)
|
||||
for item in "$@"; do
|
||||
if [ -L "$item" ]; then
|
||||
# If the item is a symlink, process it
|
||||
process_symlink "$item"
|
||||
else
|
||||
echo "$item is not a symlink. Skipping."
|
||||
fi
|
||||
done
|
||||
'';
|
||||
}
|
24
pkgs/open-messaging/default.nix
Normal file
24
pkgs/open-messaging/default.nix
Normal file
@ -0,0 +1,24 @@
|
||||
{
|
||||
writeShellApplication,
|
||||
nheko,
|
||||
telegram-desktop,
|
||||
thunderbird,
|
||||
}:
|
||||
|
||||
writeShellApplication {
|
||||
name = "open-messaging";
|
||||
|
||||
runtimeInputs = [
|
||||
nheko
|
||||
telegram-desktop
|
||||
thunderbird
|
||||
];
|
||||
|
||||
text = ''
|
||||
thunderbird &
|
||||
sleep 0.1
|
||||
nheko &
|
||||
sleep 0.1
|
||||
telegram-desktop &
|
||||
'';
|
||||
}
|
40
pkgs/pulseaudio-popup/default.nix
Normal file
40
pkgs/pulseaudio-popup/default.nix
Normal file
@ -0,0 +1,40 @@
|
||||
{
|
||||
writeShellApplication,
|
||||
pavucontrol,
|
||||
jgmenu,
|
||||
pulseaudio,
|
||||
}:
|
||||
|
||||
writeShellApplication {
|
||||
name = "pulseaudio-popup";
|
||||
|
||||
runtimeInputs = [
|
||||
pavucontrol
|
||||
jgmenu
|
||||
pulseaudio
|
||||
];
|
||||
|
||||
# Do not insert e.g. pipefail
|
||||
bashOptions = [ ];
|
||||
|
||||
text = ''
|
||||
HDMI_SINK="alsa_output.pci-0000_00_1f.3-platform-skl_hda_dsp_generic.HiFi__hw_sofhdadsp_3__sink"
|
||||
LAPTOP_SINK="alsa_output.pci-0000_00_1f.3-platform-skl_hda_dsp_generic.HiFi__hw_sofhdadsp__sink"
|
||||
|
||||
HDMI_ICON=$(pactl info | grep -q $HDMI_SINK && echo "checkbox")
|
||||
LAPTOP_ICON=$(pactl info | grep -q $LAPTOP_SINK && echo "checkbox")
|
||||
|
||||
HDMI_VOLUME=$(pactl get-sink-volume $HDMI_SINK | head -n 1 | awk '{print $5}')
|
||||
LAPTOP_VOLUME=$(pactl get-sink-volume $LAPTOP_SINK | head -n 1 | awk '{print $5}')
|
||||
|
||||
read -r -d "" CONF <<EOF
|
||||
Open Pavucontrol,pavucontrol,pavucontrol
|
||||
|
||||
^sep()
|
||||
HDMI - $HDMI_VOLUME,pactl set-default-sink $HDMI_SINK,$HDMI_ICON
|
||||
Laptop - $LAPTOP_VOLUME,pactl set-default-sink $LAPTOP_SINK,$LAPTOP_ICON
|
||||
EOF
|
||||
|
||||
echo "$CONF" | jgmenu --simple --at-pointer
|
||||
'';
|
||||
}
|
30
pkgs/sos/default.nix
Normal file
30
pkgs/sos/default.nix
Normal file
@ -0,0 +1,30 @@
|
||||
{
|
||||
writeShellApplication,
|
||||
nix-output-monitor,
|
||||
jq,
|
||||
}:
|
||||
|
||||
writeShellApplication {
|
||||
name = "sos";
|
||||
|
||||
runtimeInputs = [
|
||||
nix-output-monitor
|
||||
jq
|
||||
];
|
||||
|
||||
# TODO: somehow avoid --no-check-sigs??
|
||||
text = ''
|
||||
#!/usr/bin/env sh
|
||||
# This script performs a nixos system update using the remote builder as remote store.
|
||||
# This should improve the system update performance drastically
|
||||
|
||||
echo "########## building... ##########"
|
||||
OUT=$(nom build "$FLAKE#nixosConfigurations.$(hostname).config.system.build.toplevel" --store ssh-ng://nix@builder.julian-mutter.de --eval-store auto --json | jq -r '.[0].outputs.out')
|
||||
echo "########## output is: $OUT ##########"
|
||||
echo "########## downloading... ##########"
|
||||
nix copy --no-check-sigs --from ssh-ng://nix@builder.julian-mutter.de "$OUT"
|
||||
|
||||
echo "########## activating... ##########"
|
||||
sudo "$OUT"/bin/switch-to-configuration switch
|
||||
'';
|
||||
}
|
21
pkgs/xwacomcalibrate/default.nix
Normal file
21
pkgs/xwacomcalibrate/default.nix
Normal file
@ -0,0 +1,21 @@
|
||||
{
|
||||
writeShellApplication,
|
||||
xf86_input_wacom,
|
||||
xorg,
|
||||
xdotool,
|
||||
bc,
|
||||
}:
|
||||
|
||||
writeShellApplication {
|
||||
name = "xwacomcalibrate";
|
||||
|
||||
runtimeInputs = [
|
||||
xf86_input_wacom
|
||||
xorg.xwininfo
|
||||
xorg.xrandr
|
||||
xdotool
|
||||
bc
|
||||
];
|
||||
|
||||
text = ./xwacomcalibrate.sh;
|
||||
}
|
216
pkgs/xwacomcalibrate/xwacomcalibrate.sh
Executable file
216
pkgs/xwacomcalibrate/xwacomcalibrate.sh
Executable file
@ -0,0 +1,216 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# https://aur.archlinux.org/packages/xwacomcalibrate
|
||||
|
||||
print_help () {
|
||||
printf "\nUsage: xwacomcalibrate [-h] [-d] [-f [screen]] [-r (cw | half | ccw)]\n\n"
|
||||
printf " h: prints this help\n"
|
||||
printf " d: Uses xdotool to continously run the script\n"
|
||||
printf " f: Uses whole X screen as window size. If xrandr screen name is given, limits itself to that monitor\n"
|
||||
printf " r: Chooses the device rotation. When given, needs either \"cw\" for clockwise, \"half\" for overhead, or \"ccw\" for counterclockwise as an argument\n"
|
||||
printf "\n"
|
||||
}
|
||||
|
||||
while getopts ":hdf:r:" opt
|
||||
do
|
||||
case $opt in
|
||||
h )
|
||||
print_help
|
||||
exit 0
|
||||
;;
|
||||
d )
|
||||
DAEMON=true
|
||||
;;
|
||||
f ) FULLSCREEN=true
|
||||
if [[ $OPTARG ]]
|
||||
then
|
||||
SCREEN=$OPTARG
|
||||
fi
|
||||
;;
|
||||
r ) if [[\
|
||||
$OPTARG == "cw"\
|
||||
|| $OPTARG == "half"\
|
||||
|| $OPTARG == "ccw"\
|
||||
]]
|
||||
then
|
||||
ROTATION=$OPTARG
|
||||
else
|
||||
echo "Invalid rotation: $arg" 1>&2
|
||||
exit 1
|
||||
fi
|
||||
;;
|
||||
: ) if [[ $OPTARG == "r" ]]
|
||||
then
|
||||
echo 'option requires an argument -- ' $OPTARG 1>&2
|
||||
print_help
|
||||
exit 1
|
||||
fi
|
||||
;;
|
||||
\? ) print_help
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
shift $(( OPTIND -1 ))
|
||||
|
||||
get_dev () {
|
||||
DEV=$(\
|
||||
xsetwacom --list devices\
|
||||
| grep "STYLUS"\
|
||||
| cut -d$'\t' -f 2\
|
||||
| tr -cd [:digit:]
|
||||
)
|
||||
if [[ ! $DEV ]]
|
||||
then
|
||||
echo "no device found"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
full_tablet_size () {
|
||||
xsetwacom --set $1 ResetArea
|
||||
TB_X=$( xsetwacom --get $1 Area | cut -d ' ' -f 1)
|
||||
TB_Y=$( xsetwacom --get $1 Area | cut -d ' ' -f 2)
|
||||
TB_WIDTH=$( xsetwacom --get $1 Area | cut -d ' ' -f 3)
|
||||
TB_HEIGHT=$( xsetwacom --get $1 Area | cut -d ' ' -f 4)
|
||||
}
|
||||
|
||||
set_rotation () {
|
||||
if [[ $2 ]]
|
||||
then
|
||||
xsetwacom --set $1 Rotate $2
|
||||
else
|
||||
xsetwacom --set $1 Rotate none
|
||||
fi
|
||||
}
|
||||
|
||||
set_output () {
|
||||
xsetwacom set $1 MapToOutput "${2}x${3}+${4}+${5}"
|
||||
}
|
||||
|
||||
set_area () {
|
||||
xsetwacom set $1 area "$2" "$3"\
|
||||
$( echo "$4 + $2" | bc )\
|
||||
$( echo "$5 + $3" | bc )
|
||||
}
|
||||
|
||||
get_x_screen_size () {
|
||||
W_X="0"
|
||||
W_Y="0"
|
||||
W_WIDTH=$( xwininfo -root | grep Width | tr -dc [:digit:])
|
||||
W_HEIGHT=$( xwininfo -root | grep Height | tr -dc [:digit:])
|
||||
}
|
||||
|
||||
get_screen_size () {
|
||||
local screen=$( xrandr -q | grep "$1 connected" | cut -d ' ' -f 3 )
|
||||
if [[ ! $screen ]]
|
||||
then
|
||||
echo "couldn't find screen: $1" 1>&2
|
||||
exit 1
|
||||
fi
|
||||
if [[ $screen == "primary" ]]
|
||||
then
|
||||
local screen=$( xrandr -q | grep "$1 connected" | cut -d ' ' -f 4 )
|
||||
fi
|
||||
IFS='x+' read -r -a array <<< "$screen"
|
||||
W_WIDTH="${array[0]}"
|
||||
W_HEIGHT="${array[1]}"
|
||||
W_X="${array[2]}"
|
||||
W_Y="${array[3]}"
|
||||
}
|
||||
|
||||
get_active_window_size () {
|
||||
W_X=$(\
|
||||
xdotool getactivewindow getwindowgeometry --shell\
|
||||
| grep X\
|
||||
| cut -d "=" -f2\
|
||||
)
|
||||
W_Y=$(\
|
||||
xdotool getactivewindow getwindowgeometry --shell\
|
||||
| grep Y\
|
||||
| cut -d "=" -f2\
|
||||
)
|
||||
W_WIDTH=$(\
|
||||
xdotool getactivewindow getwindowgeometry --shell\
|
||||
| grep WIDTH\
|
||||
| cut -d "=" -f2\
|
||||
)
|
||||
W_HEIGHT=$(\
|
||||
xdotool getactivewindow getwindowgeometry --shell\
|
||||
| grep HEIGHT\
|
||||
| cut -d "=" -f2\
|
||||
)
|
||||
}
|
||||
|
||||
calculate_new_tablet_size () {
|
||||
|
||||
if [[ $1 == "cw" || $1 == "ccw" ]]
|
||||
then
|
||||
twidth=$3
|
||||
theight=$2
|
||||
else
|
||||
twidth=$2
|
||||
theight=$3
|
||||
fi
|
||||
|
||||
tar=$( echo "scale=16; $twidth / $theight" | bc )
|
||||
war=$( echo "scale=16; $4 / $5" | bc )
|
||||
|
||||
if [[ $( echo "scale=16; $tar <= $war" | bc ) -eq "1" ]]
|
||||
then
|
||||
theight=$( echo "scale=0; $twidth / $war /1" | bc )
|
||||
else
|
||||
twidth=$( echo "scale=0; $theight * $war /1" | bc )
|
||||
fi
|
||||
|
||||
if [[ $1 == "cw" || $1 == "ccw" ]]
|
||||
then
|
||||
tmp=$twidth
|
||||
twidth=$theight
|
||||
theight=$tmp
|
||||
unset tmp
|
||||
fi
|
||||
|
||||
TB_X=$( echo "scale=0; ($TB_WIDTH - $twidth) / 2" | bc )
|
||||
TB_Y=$( echo "scale=0; ($TB_HEIGHT - $theight) / 2" | bc )
|
||||
|
||||
TB_WIDTH=$twidth
|
||||
TB_HEIGHT=$theight
|
||||
}
|
||||
|
||||
main () {
|
||||
get_dev
|
||||
set_rotation "$DEV" "$ROTATION"
|
||||
full_tablet_size "$DEV"
|
||||
if [[ $FULLSCREEN ]]
|
||||
then
|
||||
if [[ $SCREEN ]]
|
||||
then
|
||||
get_screen_size "$SCREEN"
|
||||
else
|
||||
get_x_screen_size
|
||||
fi
|
||||
else
|
||||
get_active_window_size
|
||||
fi
|
||||
calculate_new_tablet_size "$ROTATION"\
|
||||
"$TB_WIDTH" "$TB_HEIGHT"\
|
||||
"$W_WIDTH" "$W_HEIGHT"
|
||||
set_output "$DEV" "$W_WIDTH" "$W_HEIGHT" "$W_X" "$W_Y"
|
||||
set_area "$DEV" "$TB_X" "$TB_Y" "$TB_WIDTH" "$TB_HEIGHT"
|
||||
echo "${W_WIDTH}x${W_HEIGHT}+${W_X}+${W_Y} \
|
||||
${TB_WIDTH}x${TB_HEIGHT}+${TB_X}+${TB_Y} $ROTATIONATION"
|
||||
}
|
||||
|
||||
if [[ $DAEMON ]]
|
||||
then
|
||||
main
|
||||
xdotool search . behave %@ focus exec --sync\
|
||||
$(\
|
||||
echo 'xwacomcalibrate '\
|
||||
$( if [[ $ROTATION ]]; then echo '-r ' $ROTATION ; fi )\
|
||||
$( if [[ $FULLSCREEN ]]; then echo '-f'; fi )\
|
||||
)
|
||||
else
|
||||
main
|
||||
fi
|
Reference in New Issue
Block a user