Last active
May 18, 2021 16:44
-
-
Save Schokokex/3942fbff6f84cc9576591b73b57601fd to your computer and use it in GitHub Desktop.
script for installing nix software in a soft sandbox
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
which /bin/sh &>/dev/null || echo /bin/sh not found!! Try putting /bin/bash at begin of script! | |
which /bin/sh &>/dev/null || exit | |
read -e -p "Nix package name: " -i "firefox" nixPackageName || exit | |
read -e -p "Sandbox home folder: " -i "$HOME/.home/$nixPackageName" sandboxHome || exit | |
read -e -p "App calling command: " -i "$nixPackageName" appCmd || exit | |
echo downloading package... | |
nix-shell -p $nixPackageName --command exit | |
echo preparing sandbox home... | |
mkdir -p $sandboxHome || exit | |
##################################################################################################### | |
# run.sh # | |
##################################################################################################### | |
printf "#!/bin/sh # | |
# | |
export package=$nixPackageName # | |
export homefolder=$sandboxHome # | |
export cmd=\"$appCmd $@\" # | |
# | |
# | |
export HOME=\$homefolder # | |
mkdir -p ~/.config/nixpkgs/ # | |
printf \"{ allowUnfree = true; }\" > ~/.config/nixpkgs/config.nix # | |
nix-shell -p \$package --command \"\$cmd\"" > $sandboxHome/run.sh && chmod +x $sandboxHome/run.sh # | |
##################################################################################################### | |
echo | |
echo "continuing will create a launcher link. Cancel with Ctrl+C" | |
read -e -p "Launcher Link: " -i "$HOME/.local/share/applications/$nixPackageName.desktop" launcherFile || exit | |
read -e -p "Launcher Name: " -i "$(echo $nixPackageName | sed 's/./\u&/')" launcherName || exit | |
cp $(find /nix/store/*$nixPackageName* -name "*png" | head -n 1) $sandboxHome/icon.png | |
##################################### | |
# launch.desktop # | |
##################################### | |
printf "[Desktop Entry] # | |
Type=Application # | |
Encoding=UTF-8 # | |
Name=$launcherName # | |
Icon=$sandboxHome/icon.png # | |
Exec=$sandboxHome/run.sh # | |
Terminal=false;" > $launcherFile # | |
##################################### |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment