Files
old-nixos-dotfiles/newpkg.sh

64 lines
1.6 KiB
Bash

#!/bin/bash
echo "newpkg.sh: create minimal nix file in current directory"
if [ -z "$NIXOSSYSCONFIG" ]; then
echo "Error: Env Variable Missing, NIXOSSYSCONFIG"
exit 1
fi
if [ -z "$NIXOSHOMECONFIG" ]; then
echo "Error: Env Variable Missing, NIXOSHOMECONFIG"
exit 1
fi
if [ -z "$EDITOR" ]; then
echo "Error: Env Variable Missing, EDITOR"
exit 1
fi
echo -e "Select installation destination:\n[1]: System\n[2]: User\n[q]: quit"
read dest
echo "Specifiy the package to add:"
read pkgName
touch "$PWD/${pkgName}.nix"
if [[ $dest -eq 1 ]]; then
echo -e "{ pkgs, ... }:\n{\n environment.systemPackages = with pkgs; [\n ${pkgName}\n ];\n}" > "$PWD/${pkgName}.nix"
echo "Open editor to modify system imports? [y/N]: "
read doEdit
if [ "$doEdit" == "y" ] || [ "$doEdit" == "Y" ]; then
$EDITOR $NIXOSSYSCONFIG
fi
elif [[ $dest -eq 2 ]]; then
echo -e "{ pkgs, ... }:\n{\n home.packages = with pkgs; [\n ${pkgName}\n ];\n}" > "$PWD/${pkgName}.nix"
echo "Open editor to modify home imports? [y/N]: "
read doEdit
if [ "$doEdit" == "y" ] || [ "$doEdit" == "Y" ]; then
$EDITOR $NIXOSHOMECONFIG
fi
elif [[ $dest == "q" ]]; then
exit 0
else
echo "Error: Non-numeric or Out-ranged value inputed"
exit 1
fi
echo "Would you like to edit new nix file for further configuration? [y/N]: "
read doNixEdit
if [ "$doNixEdit" == "y" ] || [ "$doNixEdit" == "Y" ]; then
$EDITOR "$PWD/${pkgName}.nix"
fi
echo "Would you like to execute nixos-rebuild? [y/N]: "
read doExec
if [ "$doExec" == "y" ] || [ "$doExec" == "Y" ]; then
cd ~/.dotfiles
sudo nixos-rebuild --flake '.#system'
else
echo "Exiting"
exit 0
fi