spacepaste

  1.  
  2. #! /bin/sh
  3. nix-instantiate --find-file nixpkgs >/dev/null || {
  4. echo "Could not find nixpkgs, please set up your NIX_PATH"
  5. exit 1
  6. }
  7. NIX_DO_STASH="${NIX_DO_STASH:-$HOME/.local/share/nix-do}"
  8. NIX_DO_PROFILE="${NIX_DO_PROFILE:-$(readlink $HOME/.nix-profile)}"
  9. mkdir -p "$NIX_DO_STASH"
  10. op="$1"; shift
  11. case "$op" in
  12. pull)
  13. cd "$(nix-instantiate --find-file nixpkgs)";
  14. git remote update
  15. git pull -v
  16. ;;
  17. expression)
  18. echo "let
  19. pkgs = import <nixpkgs> {};
  20. fullEnv = packages:
  21. pkgs.buildEnv {
  22. name = ''$USER-profile-env'';
  23. paths = packages;
  24. ignoreCollisions = true;
  25. pathsToLink = [''/''];
  26. };
  27. in
  28. fullEnv [
  29. $(for p in "$NIX_DO_STASH"/*/output*; do
  30. test -e "$p" && readlink -f "$p"
  31. done)
  32. ]
  33. "
  34. ;;
  35. rebuild)
  36. nix-env --set -p "$NIX_DO_PROFILE" "$(nix-instantiate -E "$("$0" expression)")"
  37. ;;
  38. install)
  39. for p in "$@"; do
  40. nix-build "<nixpkgs>" -A "$p.all" -o "$NIX_DO_STASH/$p/output"
  41. done
  42. "$0" rebuild
  43. ;;
  44. upgrade)
  45. "$0" install $("$0" list)
  46. ;;
  47. remove)
  48. ( cd "$NIX_DO_STASH"; for p in "$@"; do rm -rf "$p"; done);
  49. "$0" rebuild
  50. ;;
  51. clean)
  52. nix-collect-garbage -d
  53. ;;
  54. list)
  55. ( cd "$NIX_DO_STASH"; ls )
  56. ;;
  57. esac
  58.