executable_guix-refresh.sh 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. #!/usr/bin/env bash
  2. set -o errexit -o pipefail -o xtrace
  3. if [[ $GUIX_VERSION_STRATEGY == "guix-expression" ]]
  4. then
  5. guix_version_expression()
  6. {
  7. cat <<EOF
  8. (use-modules ${GUILE_MODULES[@]}
  9. (guix utils))
  10. (display "version: ")
  11. (display (version-major+minor+point (package-version $GUIX_BUILD_PACKAGE)))
  12. (newline)
  13. EOF
  14. }
  15. guix_version()
  16. {
  17. ./pre-inst-env guix repl <<< "$(guix_version_expression)" \
  18. | awk '/version: / { print $NF }'
  19. }
  20. else
  21. guix_version()
  22. {
  23. ./pre-inst-env guix show "$GUIX_BUILD_PACKAGE" \
  24. | recsel -Pversion
  25. }
  26. fi
  27. nix_expr()
  28. {
  29. cat <<EOF
  30. (builtins.getFlake "nixpkgs").legacyPackages.$NIX_SYSTEM.$NIX_BUILD_PACKAGE.version
  31. EOF
  32. }
  33. nix_version()
  34. {
  35. nix eval --raw --impure --expr "$(nix_expr)"
  36. }
  37. guix_version_output="$(guix_version)"
  38. nix_version_output="$(nix_version)"
  39. build()
  40. {
  41. ./pre-inst-env guix build --keep-failed --no-grafts "$GUIX_BUILD_PACKAGE"
  42. }
  43. guix_location()
  44. {
  45. ./pre-inst-env guix show "$GUIX_BUILD_PACKAGE" \
  46. | recsel -Plocation \
  47. | cut -d: -f1
  48. }
  49. guix_location_output="$(guix_location)"
  50. message()
  51. {
  52. cat <<EOF
  53. gnu: ${GUIX_BUILD_PACKAGE}: Update to ${nix_version_output}.
  54. * ${guix_location_output#"${PWD}/"} (${GUIX_BUILD_PACKAGE}): Update to ${nix_version_output}.
  55. EOF
  56. }
  57. commit()
  58. {
  59. git add "$guix_location_output"
  60. git commit -m "$(message)"
  61. }
  62. if [[ $guix_version_output == "$nix_version_output" ]]
  63. then
  64. echo "$guix_version_output"
  65. if [[ $(git diff) == "" ]]
  66. then
  67. :
  68. else
  69. build
  70. commit
  71. fi
  72. exit 0
  73. else
  74. echo "${guix_version_output} does not match ${nix_version_output}"
  75. fi
  76. sed -i "s@${guix_version_output}@${nix_version_output}@g" "$guix_location_output"
  77. guix_build()
  78. {
  79. ./pre-inst-env guix build -S "$GUIX_BUILD_PACKAGE"
  80. }
  81. set +e
  82. guix_build_output="$(guix_build 2>&1)"
  83. set -e
  84. expected_hash="$(echo "$guix_build_output" | awk '/expected hash/ { print $NF }')"
  85. actual_hash="$(echo "$guix_build_output" | awk '/actual hash/ { print $NF }')"
  86. sed -i "s@${expected_hash}@${actual_hash}@" "$guix_location_output"
  87. build
  88. commit