diff --git a/pkgs/applications/backup/timeshift/timeshift-launcher.patch b/pkgs/applications/backup/timeshift/timeshift-launcher.patch deleted file mode 100644 index 765c101e1629..000000000000 --- a/pkgs/applications/backup/timeshift/timeshift-launcher.patch +++ /dev/null @@ -1,26 +0,0 @@ -diff --git a/src/timeshift-launcher b/src/timeshift-launcher -index 29b8fc4..5f6cb17 100755 ---- a/src/timeshift-launcher -+++ b/src/timeshift-launcher -@@ -1,6 +1,6 @@ - #!/bin/bash - --app_command='timeshift-gtk' -+app_command=''"$(realpath "$(dirname "$0")")"'/timeshift-gtk' - - if [ "$(id -u)" -eq 0 ]; then - # user is admin -@@ -14,11 +14,11 @@ else - # script is running in non-interactive mode - if [ "$XDG_SESSION_TYPE" = "wayland" ] ; then - xhost +SI:localuser:root -- pkexec ${app_command} -+ pkexec env DISPLAY="$DISPLAY" XAUTHORITY="$XAUTHORITY" "${app_command}" - xhost -SI:localuser:root - xhost - elif command -v pkexec >/dev/null 2>&1; then -- pkexec ${app_command} -+ pkexec env DISPLAY="$DISPLAY" XAUTHORITY="$XAUTHORITY" "${app_command}" - elif command -v sudo >/dev/null 2>&1; then - x-terminal-emulator -e "sudo ${app_command}" - elif command -v su >/dev/null 2>&1; then diff --git a/pkgs/applications/backup/timeshift/unwrapped.nix b/pkgs/applications/backup/timeshift/unwrapped.nix index a318e07793c4..571672dd0d1e 100644 --- a/pkgs/applications/backup/timeshift/unwrapped.nix +++ b/pkgs/applications/backup/timeshift/unwrapped.nix @@ -27,17 +27,20 @@ stdenv.mkDerivation rec { hash = "sha256-umMekxP9bvV01KzfIh2Zxa9Xb+tR5x+tG9dOnBIOkjY="; }; - patches = [ - ./timeshift-launcher.patch - ]; - postPatch = '' - while IFS="" read -r -d $'\0' FILE; do + for FILE in src/Core/Main.vala src/Utility/Device.vala; do substituteInPlace "$FILE" \ - --replace "/sbin/blkid" "${util-linux}/bin/blkid" - done < <(find ./src -mindepth 1 -name "*.vala" -type f -print0) + --replace-fail "/sbin/blkid" "${lib.getExe' util-linux "blkid"}" + done + substituteInPlace ./src/Utility/IconManager.vala \ - --replace "/usr/share" "$out/share" + --replace-fail "/usr/share" "$out/share" + + # Substitute app_command to look for the `timeshift-gtk` in $out. + # Substitute the `pkexec ...` as a hack to run a GUI application like Timeshift as root without setting up the corresponding pkexec policy. + substituteInPlace ./src/timeshift-launcher \ + --replace-fail "app_command='timeshift-gtk'" "app_command=$out/bin/timeshift-gtk" \ + --replace-fail ${lib.escapeShellArg ''pkexec ''${app_command}''} ${lib.escapeShellArg ''pkexec env DISPLAY="$DISPLAY" XAUTHORITY="$XAUTHORITY" "''${app_command}"''} ''; nativeBuildInputs = [ diff --git a/pkgs/applications/backup/timeshift/wrapper.nix b/pkgs/applications/backup/timeshift/wrapper.nix index 5bbfffb94d46..fcef826ebd34 100644 --- a/pkgs/applications/backup/timeshift/wrapper.nix +++ b/pkgs/applications/backup/timeshift/wrapper.nix @@ -45,6 +45,11 @@ stdenvNoCC.mkDerivation { ) wrapProgram "$out/bin/timeshift" "''${makeWrapperArgs[@]}" wrapProgram "$out/bin/timeshift-gtk" "''${gappsWrapperArgs[@]}" + # Substitute app_command to look for the `timeshift-gtk` in $out. + unlink "$out/bin/timeshift-launcher" + substitute ${lib.getExe' timeshift-unwrapped "timeshift-launcher"} "$out/bin/timeshift-launcher" \ + --replace-fail "app_command=${lib.getExe' timeshift-unwrapped "timeshift-gtk"}" "app_command=$out/bin/timeshift-gtk" + chmod +x "$out/bin/timeshift-launcher" ''; inherit (timeshift-unwrapped) meta; diff --git a/pkgs/by-name/ch/choose-gui/package.nix b/pkgs/by-name/ch/choose-gui/package.nix index bbf1ff2a8578..da7d1e6e7be9 100644 --- a/pkgs/by-name/ch/choose-gui/package.nix +++ b/pkgs/by-name/ch/choose-gui/package.nix @@ -3,7 +3,7 @@ stdenv, fetchFromGitHub, xcbuild, - darwin, + apple-sdk_11, }: stdenv.mkDerivation rec { @@ -19,11 +19,11 @@ stdenv.mkDerivation rec { nativeBuildInputs = [ xcbuild ]; - buildInputs = [ darwin.apple_sdk.frameworks.Cocoa ]; + buildInputs = [ apple-sdk_11 ]; buildPhase = '' runHook preBuild - xcodebuild -arch ${stdenv.hostPlatform.darwinArch} -configuration Release SYMROOT="./output" build + xcodebuild -configuration Release SYMROOT="./output" HOME="$(mktemp -d)" build cp ./output/Release/choose choose runHook postBuild ''; diff --git a/pkgs/by-name/rm/rmfakecloud/package.nix b/pkgs/by-name/rm/rmfakecloud/package.nix index be0d53852c3e..b76e3a3b9567 100644 --- a/pkgs/by-name/rm/rmfakecloud/package.nix +++ b/pkgs/by-name/rm/rmfakecloud/package.nix @@ -2,36 +2,52 @@ lib, fetchFromGitHub, buildGoModule, - callPackage, enableWebui ? true, + pnpm_9, + nodejs, nixosTests, }: buildGoModule rec { pname = "rmfakecloud"; - version = "0.0.21"; + version = "0.0.23"; src = fetchFromGitHub { owner = "ddvk"; - repo = pname; + repo = "rmfakecloud"; rev = "v${version}"; - hash = "sha256-Opx39FUo4Kzezi96D9iraA8gkqCPVfMf4LhxtVpsuNQ="; + hash = "sha256-XlKqh6GKGreWLPjS8XfEUJCMMxiOw8pP2qX8otD+RCo="; }; vendorHash = "sha256-9tfxE03brUvCYusmewiqNpCkKyIS9qePqylrzDWrJLY="; - ui = callPackage ./webui.nix { inherit version src; }; + # if using webUI build it + # use env because of https://github.com/NixOS/nixpkgs/issues/358844 + env.pnpmRoot = "ui"; + env.pnpmDeps = pnpm_9.fetchDeps { + inherit pname version src; + sourceRoot = "${src.name}/ui"; + pnpmLock = "${src}/ui/pnpm-lock.yaml"; + hash = "sha256-VNmCT4um2W2ii8jAm+KjQSjixYEKoZkw7CeRwErff/o="; + }; + preBuild = lib.optionals enableWebui '' + # using sass-embedded fails at executing node_modules/sass-embedded-linux-x64/dart-sass/src/dart + rm -r ui/node_modules/sass-embedded ui/node_modules/.pnpm/sass-embedded* - postPatch = - if enableWebui then - '' - mkdir -p ui/build - cp -r ${ui}/* ui/build - '' - else - '' - sed -i '/go:/d' ui/assets.go - ''; + # avoid re-running pnpm i... + touch ui/pnpm-lock.yaml + + make ui/dist + ''; + nativeBuildInputs = lib.optionals enableWebui [ + nodejs + pnpm_9.configHook + ]; + + # ... or don't embed it in the server + postPatch = lib.optionals (!enableWebui) '' + sed -i '/go:/d' ui/assets.go + ''; ldflags = [ "-s" diff --git a/pkgs/by-name/rm/rmfakecloud/webui.nix b/pkgs/by-name/rm/rmfakecloud/webui.nix deleted file mode 100644 index 928a624cba2b..000000000000 --- a/pkgs/by-name/rm/rmfakecloud/webui.nix +++ /dev/null @@ -1,37 +0,0 @@ -{ version, src, stdenv, lib, fetchYarnDeps, fixup-yarn-lock, yarn, nodejs }: - -stdenv.mkDerivation rec { - inherit version src; - - pname = "rmfakecloud-webui"; - - yarnOfflineCache = fetchYarnDeps { - yarnLock = "${src}/ui/yarn.lock"; - hash = "sha256-9//uQ4ZLLTf2N1WSwsOwFjBuDmThuMtMXU4SzMljAMM="; - }; - - nativeBuildInputs = [ fixup-yarn-lock yarn nodejs ]; - - buildPhase = '' - export HOME=$(mktemp -d) - cd ui - fixup-yarn-lock yarn.lock - yarn config --offline set yarn-offline-mirror ${yarnOfflineCache} - yarn install --offline --frozen-lockfile --ignore-engines --ignore-scripts --no-progress - patchShebangs node_modules - export PATH=$PWD/node_modules/.bin:$PATH - ./node_modules/.bin/react-scripts build - mkdir -p $out - cd .. - ''; - - installPhase = '' - cp -r ui/build/* $out - ''; - - meta = with lib; { - description = "Only the webui files for rmfakecloud"; - homepage = "https://ddvk.github.io/rmfakecloud/"; - license = licenses.agpl3Only; - }; -} diff --git a/pkgs/by-name/up/upbound/package.nix b/pkgs/by-name/up/upbound/package.nix index 51046a403ff2..caa377efe0f3 100644 --- a/pkgs/by-name/up/upbound/package.nix +++ b/pkgs/by-name/up/upbound/package.nix @@ -9,7 +9,10 @@ let inherit (stdenvNoCC.hostPlatform) system; sources = - if "${version-channel}" == "main" then import ./sources-main.nix else import ./sources-stable.nix; + if "${version-channel}" == "main" then + lib.importJSON ./sources-main.json + else + lib.importJSON ./sources-stable.json; arch = sources.archMap.${system}; in @@ -18,13 +21,13 @@ stdenvNoCC.mkDerivation { version = sources.version; srcs = [ (fetchurl { - url = sources.fetchurlAttrSet.${system}.docker-credential-up.url; - sha256 = sources.fetchurlAttrSet.${system}.docker-credential-up.hash; + url = sources.fetchurlAttrSet.docker-credential-up.${system}.url; + sha256 = sources.fetchurlAttrSet.docker-credential-up.${system}.hash; }) (fetchurl { - url = sources.fetchurlAttrSet.${system}.up.url; - sha256 = sources.fetchurlAttrSet.${system}.up.hash; + url = sources.fetchurlAttrSet.up.${system}.url; + sha256 = sources.fetchurlAttrSet.up.${system}.hash; }) ]; @@ -63,12 +66,13 @@ stdenvNoCC.mkDerivation { doCheck = false; passthru.updateScript = [ - ./update.sh + ./update "${version-channel}" ]; meta = { description = "CLI for interacting with Upbound Cloud, Upbound Enterprise, and Universal Crossplane (UXP)"; + changelog = "https://docs.upbound.io/reference/cli/rel-notes/#whats-changed"; homepage = "https://upbound.io"; license = lib.licenses.unfree; maintainers = with lib.maintainers; [ diff --git a/pkgs/by-name/up/upbound/sources-main.json b/pkgs/by-name/up/upbound/sources-main.json new file mode 100644 index 000000000000..a99993068f14 --- /dev/null +++ b/pkgs/by-name/up/upbound/sources-main.json @@ -0,0 +1,53 @@ +{ + "archMap": { + "aarch64-darwin": "darwin_arm64", + "aarch64-linux": "linux_arm64", + "x86_64-darwin": "darwin_amd64", + "x86_64-linux": "linux_amd64" + }, + "fetchurlAttrSet": { + "docker-credential-up": { + "aarch64-darwin": { + "hash": "sha256-3fx/wjBoFxmeo55QbRw9cl4GFCFehGpZeVAw1bvooSk=", + "url": "https://cli.upbound.io/main/v0.38.0-0.rc.0.29.g59359e0/bundle/docker-credential-up/darwin_arm64.tar.gz" + }, + "aarch64-linux": { + "hash": "sha256-FeF7D8WLpK8S6b7QCLaOI7Dm2EzbDqJVp9tfh13BJuU=", + "url": "https://cli.upbound.io/main/v0.38.0-0.rc.0.29.g59359e0/bundle/docker-credential-up/linux_arm64.tar.gz" + }, + "x86_64-darwin": { + "hash": "sha256-00y9wGMwu5ZsTzlNkSvdwEse5eV4xzLiwQjgSTnmW5w=", + "url": "https://cli.upbound.io/main/v0.38.0-0.rc.0.29.g59359e0/bundle/docker-credential-up/darwin_amd64.tar.gz" + }, + "x86_64-linux": { + "hash": "sha256-oObO/T/2yOFDaNVJGQCqna130Tyx/sEOCAQMDYhVlNI=", + "url": "https://cli.upbound.io/main/v0.38.0-0.rc.0.29.g59359e0/bundle/docker-credential-up/linux_amd64.tar.gz" + } + }, + "up": { + "aarch64-darwin": { + "hash": "sha256-Bf6O6rsth3D5h5olxqHxULuxxPtNhxP+gN69mJnlQTg=", + "url": "https://cli.upbound.io/main/v0.38.0-0.rc.0.29.g59359e0/bundle/up/darwin_arm64.tar.gz" + }, + "aarch64-linux": { + "hash": "sha256-svTHCjw2ZrTEscNpizOmg9leQAbzhWcPfst3nMUhUXg=", + "url": "https://cli.upbound.io/main/v0.38.0-0.rc.0.29.g59359e0/bundle/up/linux_arm64.tar.gz" + }, + "x86_64-darwin": { + "hash": "sha256-1LxqRHQjNlRFTGhEyOR9uW407LkqdpVjB3w57hNT/Zk=", + "url": "https://cli.upbound.io/main/v0.38.0-0.rc.0.29.g59359e0/bundle/up/darwin_amd64.tar.gz" + }, + "x86_64-linux": { + "hash": "sha256-ZLjhD7uCpBURYozX1IjUTJDzPuKFedIZQhRvMqMMsLY=", + "url": "https://cli.upbound.io/main/v0.38.0-0.rc.0.29.g59359e0/bundle/up/linux_amd64.tar.gz" + } + } + }, + "platformList": [ + "aarch64-darwin", + "aarch64-linux", + "x86_64-darwin", + "x86_64-linux" + ], + "version": "0.38.0-0.rc.0.29.g59359e0" +} diff --git a/pkgs/by-name/up/upbound/sources-main.nix b/pkgs/by-name/up/upbound/sources-main.nix deleted file mode 100644 index acf3aee01529..000000000000 --- a/pkgs/by-name/up/upbound/sources-main.nix +++ /dev/null @@ -1,54 +0,0 @@ -# Generated by "update.sh main" - do not update manually! -{ - version = "0.37.0-0.rc.0.38.g797e121"; - - platformList = [ - "aarch64-linux" - "x86_64-linux" - "x86_64-darwin" - "aarch64-darwin" - ]; - - archMap = { - aarch64-linux = "linux_arm64"; - x86_64-linux = "linux_amd64"; - x86_64-darwin = "darwin_amd64"; - aarch64-darwin = "darwin_arm64"; - }; - - fetchurlAttrSet = { - - aarch64-linux.docker-credential-up = { - hash = "sha256-nZXniTuLzmV7tK/Pd4BjUzqYYH2OmQKC4yoCHOhZ3C8="; - url = "https://cli.upbound.io/main/v0.37.0-0.rc.0.38.g797e121/bundle/docker-credential-up/linux_arm64.tar.gz"; - }; - x86_64-linux.docker-credential-up = { - hash = "sha256-LILaT+vn2CdKzNWxYOeda+Zid9V11I94+vwDGkGwxuQ="; - url = "https://cli.upbound.io/main/v0.37.0-0.rc.0.38.g797e121/bundle/docker-credential-up/linux_amd64.tar.gz"; - }; - x86_64-darwin.docker-credential-up = { - hash = "sha256-7eUWveGIbimxbwOGtA6qrU7F8p8EpOCTHXN4vj74qqA="; - url = "https://cli.upbound.io/main/v0.37.0-0.rc.0.38.g797e121/bundle/docker-credential-up/darwin_amd64.tar.gz"; - }; - aarch64-darwin.docker-credential-up = { - hash = "sha256-XTgSZjbHXyt1BXNeaHXqdi4gs8eeD/7rE657oAeQKv4="; - url = "https://cli.upbound.io/main/v0.37.0-0.rc.0.38.g797e121/bundle/docker-credential-up/darwin_arm64.tar.gz"; - }; - aarch64-linux.up = { - hash = "sha256-cNk4uaXcdH3EucwGnGXGsPbmKGGO+ig3xfJ+fAcwEbo="; - url = "https://cli.upbound.io/main/v0.37.0-0.rc.0.38.g797e121/bundle/up/linux_arm64.tar.gz"; - }; - x86_64-linux.up = { - hash = "sha256-3h+Jtl84UdWvs2cbrDsbtqlCCpvvYjzXZLmzDY/9aXE="; - url = "https://cli.upbound.io/main/v0.37.0-0.rc.0.38.g797e121/bundle/up/linux_amd64.tar.gz"; - }; - x86_64-darwin.up = { - hash = "sha256-WzngxshyHnR1H7Rhkbw/wkN1i3TWyV8CcBTwLNVggdU="; - url = "https://cli.upbound.io/main/v0.37.0-0.rc.0.38.g797e121/bundle/up/darwin_amd64.tar.gz"; - }; - aarch64-darwin.up = { - hash = "sha256-KLcxE4847DE6e0AznjlNZnS6GNhT1JJaCnYDecTZ6EQ="; - url = "https://cli.upbound.io/main/v0.37.0-0.rc.0.38.g797e121/bundle/up/darwin_arm64.tar.gz"; - }; - }; -} diff --git a/pkgs/by-name/up/upbound/sources-stable.json b/pkgs/by-name/up/upbound/sources-stable.json new file mode 100644 index 000000000000..cbf434da428d --- /dev/null +++ b/pkgs/by-name/up/upbound/sources-stable.json @@ -0,0 +1,53 @@ +{ + "archMap": { + "aarch64-darwin": "darwin_arm64", + "aarch64-linux": "linux_arm64", + "x86_64-darwin": "darwin_amd64", + "x86_64-linux": "linux_amd64" + }, + "fetchurlAttrSet": { + "docker-credential-up": { + "aarch64-darwin": { + "hash": "sha256-WuNC7E1i/Yikwe3uq1Hxf4mpAzgqe9T6tI2DFqJFYq8=", + "url": "https://cli.upbound.io/stable/v0.37.0/bundle/docker-credential-up/darwin_arm64.tar.gz" + }, + "aarch64-linux": { + "hash": "sha256-b5ylPJxIVkI3EDY5IFTHll/4F6KDtQLm7eq8J7eGmtA=", + "url": "https://cli.upbound.io/stable/v0.37.0/bundle/docker-credential-up/linux_arm64.tar.gz" + }, + "x86_64-darwin": { + "hash": "sha256-jJV0SX96Isz7+E0MOQ6aq3KDwFZt4knTVuDU3iSIC+4=", + "url": "https://cli.upbound.io/stable/v0.37.0/bundle/docker-credential-up/darwin_amd64.tar.gz" + }, + "x86_64-linux": { + "hash": "sha256-Ek8xTUKFjYekaee+8rjjOKSQQ1jX3asyvVa/jATWR5c=", + "url": "https://cli.upbound.io/stable/v0.37.0/bundle/docker-credential-up/linux_amd64.tar.gz" + } + }, + "up": { + "aarch64-darwin": { + "hash": "sha256-jDhAB0b1XMAwGgTeL1uXIIg4YoBgpgI9KBdsbyBXjF4=", + "url": "https://cli.upbound.io/stable/v0.37.0/bundle/up/darwin_arm64.tar.gz" + }, + "aarch64-linux": { + "hash": "sha256-mVS1knNDtQjbxj2FXIyx/m/HVUhUSuN2E7HNmdxgtd4=", + "url": "https://cli.upbound.io/stable/v0.37.0/bundle/up/linux_arm64.tar.gz" + }, + "x86_64-darwin": { + "hash": "sha256-5nr+5tCbqoVel97ROn2OamV0s90O6QS9vrbSXIjhJoo=", + "url": "https://cli.upbound.io/stable/v0.37.0/bundle/up/darwin_amd64.tar.gz" + }, + "x86_64-linux": { + "hash": "sha256-MZgQlxi4MrzXG59Q4g5Bjb240E5pf5l1bHGASqSc+OU=", + "url": "https://cli.upbound.io/stable/v0.37.0/bundle/up/linux_amd64.tar.gz" + } + } + }, + "platformList": [ + "aarch64-darwin", + "aarch64-linux", + "x86_64-darwin", + "x86_64-linux" + ], + "version": "0.37.0" +} diff --git a/pkgs/by-name/up/upbound/sources-stable.nix b/pkgs/by-name/up/upbound/sources-stable.nix deleted file mode 100644 index 1dfc1b574cd2..000000000000 --- a/pkgs/by-name/up/upbound/sources-stable.nix +++ /dev/null @@ -1,54 +0,0 @@ -# Generated by "update.sh stable" - do not update manually! -{ - version = "0.36.1"; - - platformList = [ - "aarch64-linux" - "x86_64-linux" - "x86_64-darwin" - "aarch64-darwin" - ]; - - archMap = { - aarch64-linux = "linux_arm64"; - x86_64-linux = "linux_amd64"; - x86_64-darwin = "darwin_amd64"; - aarch64-darwin = "darwin_arm64"; - }; - - fetchurlAttrSet = { - - aarch64-linux.docker-credential-up = { - hash = "sha256-BnEQWK1Y4rCDEk5BgkUIeF0oK6C77AQZh6KWhS+MfqM="; - url = "https://cli.upbound.io/stable/v0.36.1/bundle/docker-credential-up/linux_arm64.tar.gz"; - }; - x86_64-linux.docker-credential-up = { - hash = "sha256-4A0Di92G/vi9NR/pH20E8aaSn/jYhduQbYH6aLL2R3E="; - url = "https://cli.upbound.io/stable/v0.36.1/bundle/docker-credential-up/linux_amd64.tar.gz"; - }; - x86_64-darwin.docker-credential-up = { - hash = "sha256-/i4VsDUk0B+htRv0UCjCLT1ByewO8UNHOMbbxqIfvvE="; - url = "https://cli.upbound.io/stable/v0.36.1/bundle/docker-credential-up/darwin_amd64.tar.gz"; - }; - aarch64-darwin.docker-credential-up = { - hash = "sha256-gaaaOfn8oOxjlYruGePFZ+e65cUgRJSlsr4iweVYdSE="; - url = "https://cli.upbound.io/stable/v0.36.1/bundle/docker-credential-up/darwin_arm64.tar.gz"; - }; - aarch64-linux.up = { - hash = "sha256-mxuDhdO0nZkozMsKiKcDPBscgrY0pSChJP5TUJz729E="; - url = "https://cli.upbound.io/stable/v0.36.1/bundle/up/linux_arm64.tar.gz"; - }; - x86_64-linux.up = { - hash = "sha256-oZ1RpPZAKzChRWKUhUcKPRXhqmf3FBXvpFCICMsWh+w="; - url = "https://cli.upbound.io/stable/v0.36.1/bundle/up/linux_amd64.tar.gz"; - }; - x86_64-darwin.up = { - hash = "sha256-a4QsXlfmmFhRYxC0yZ7yVIHmP8VUgggfOZSenMXGlKA="; - url = "https://cli.upbound.io/stable/v0.36.1/bundle/up/darwin_amd64.tar.gz"; - }; - aarch64-darwin.up = { - hash = "sha256-PPHlADbIiQ/CAF746lulvuHjwwo1V563K9Haf/7IjEI="; - url = "https://cli.upbound.io/stable/v0.36.1/bundle/up/darwin_arm64.tar.gz"; - }; - }; -} diff --git a/pkgs/by-name/up/upbound/update b/pkgs/by-name/up/upbound/update new file mode 100755 index 000000000000..d65588ec3579 --- /dev/null +++ b/pkgs/by-name/up/upbound/update @@ -0,0 +1,4 @@ +#!/usr/bin/env bash + +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd) +exec "$SCRIPT_DIR"/update.hs "$(realpath "$0")" "$1" diff --git a/pkgs/by-name/up/upbound/update.hs b/pkgs/by-name/up/upbound/update.hs new file mode 100755 index 000000000000..d7406f8717a9 --- /dev/null +++ b/pkgs/by-name/up/upbound/update.hs @@ -0,0 +1,96 @@ +#!/usr/bin/env nix-shell +#!nix-shell -i runhaskell --packages 'haskellPackages.ghcWithPackages (ps: [ps.aeson ps.aeson-pretty ps.directory ps.process ps.optparse-applicative])' + +{-# LANGUAGE OverloadedStrings #-} +{-# LANGUAGE RecordWildCards #-} + +module Main where + +import Options.Applicative +import System.FilePath (takeDirectory, ()) +import System.Process (readProcess) +import Data.Aeson (object, (.=)) +import Data.Aeson.Encode.Pretty (encodePretty', Config(..), defConfig, Indent(..), keyOrder) +import qualified Data.ByteString.Lazy.Char8 as BL +import qualified Data.Map.Strict as Map +import Control.Monad (forM) +import qualified Data.Text as T + +data Options = Options + { scriptPath :: FilePath + , channel :: String + } + +optionsParser :: Parser Options +optionsParser = Options + <$> argument str + ( metavar "SCRIPT_PATH" + <> help "The path to the script" ) + <*> argument channelReader + ( metavar "CHANNEL" + <> help "The release channel (main or stable)" ) + +channelReader :: ReadM String +channelReader = eitherReader $ \arg -> + if arg `elem` ["main", "stable"] + then Right arg + else Left "CHANNEL must be one of: main, stable" + +-- Custom configuration for pretty-printing JSON +prettyConfig :: Config +prettyConfig = defConfig + { confIndent = Spaces 2 + , confCompare = keyOrder ["archMap", "fetchurlAttrSet", "platformList", "version"] + } + +main :: IO () +main = do + let opts = info (optionsParser <**> helper) + ( fullDesc + <> progDesc "Updates the sources-{main|stable}.json files based on the upstream release channel" + <> header "update.hs - Haskell script with argument parsing" ) + + -- Parse the command-line arguments + Options {..} <- execParser opts + + -- Process the arguments + let scriptDir = takeDirectory scriptPath + let outputFile = scriptDir ("sources-" ++ channel ++ ".json") + + -- Fetch current version + let baseUrl = "https://cli.upbound.io/" ++ channel + currentVersion <- readProcess "curl" ["-s", baseUrl ++ "/current/version"] "" + let version = filter (\x -> x /= 'v' && x /= '\n') currentVersion -- Remove the leading 'v' and the new line char + + -- Architecture mapping + let archMapping = Map.fromList + [ ("aarch64-darwin", "darwin_arm64") + , ("x86_64-darwin", "darwin_amd64") + , ("aarch64-linux", "linux_arm64") + , ("x86_64-linux", "linux_amd64") + ] + + -- Build platformList + let platformList = Map.keys archMapping + + -- Build fetchurlAttrSet + fetchurlAttrSet <- fmap Map.fromList $ forM ["docker-credential-up", "up"] $ \cmd -> do + attrs <- forM (Map.toList archMapping) $ \(key, arch) -> do + let url = baseUrl ++ "/v" ++ version ++ "/bundle/" ++ cmd ++ "/" ++ arch ++ ".tar.gz" + _hash <- readProcess "nix-prefetch-url" [url] "" + let hash = T.unpack $ T.strip $ T.pack _hash + _sha256Hash <- readProcess "nix" ["hash", "convert", hash, "--hash-algo", "sha256"] "" + let sha256Hash = T.unpack $ T.strip $ T.pack _sha256Hash + return (key, object ["hash" .= sha256Hash, "url" .= url]) + return (cmd, object attrs) + + -- Write output to JSON + let output = object + [ "version" .= version + , "platformList" .= platformList + , "archMap" .= archMapping + , "fetchurlAttrSet" .= fetchurlAttrSet + ] + BL.writeFile outputFile $ BL.snoc (encodePretty' prettyConfig output) '\n' + + putStrLn $ "Output written to: " ++ outputFile diff --git a/pkgs/by-name/up/upbound/update.sh b/pkgs/by-name/up/upbound/update.sh deleted file mode 100755 index ad0460aaade0..000000000000 --- a/pkgs/by-name/up/upbound/update.sh +++ /dev/null @@ -1,83 +0,0 @@ -#!/usr/bin/env nix-shell -#!nix-shell -i bash -p curl - -#set -euo pipefail - -SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd) - -# value can be main | stable -# Ensure at least one argument is passed -if [[ $# -lt 1 ]]; then - echo "Error: No argument provided. Please specify 'main' or 'stable'." - exit 1 -fi - -# Check if the first argument is 'main' or 'stable' -if [[ "$1" == "main" || "$1" == "stable" ]]; then - echo "Valid input: $1" -else - echo "Error: Invalid input. Please specify 'main' or 'stable'." - exit 1 -fi -channel=$1 - -baseUrl="https://cli.upbound.io/${channel}" -currentVersion=$(curl ${baseUrl}/current/version) - -version="${currentVersion:1}" - -declare -A archMapping -archMapping["aarch64-darwin"]="darwin_arm64" -archMapping["x86_64-darwin"]="darwin_amd64" -archMapping["aarch64-linux"]="linux_arm64" -archMapping["x86_64-linux"]="linux_amd64" - -archMapBlock= -for key in "${!archMapping[@]}"; do - line=$(printf "$key = \"${archMapping[$key]}\"; ") - archMapBlock="$archMapBlock$line" -done - -platformListBlock= -for key in "${!archMapping[@]}"; do - platformListBlock="$platformListBlock\"$key\" " -done - -cmds=("docker-credential-up" "up") -fetchurlAttrSetBlock= -for cmd in "${cmds[@]}"; do - for key in "${!archMapping[@]}"; do - arch=${archMapping[$key]} - url="${baseUrl}/v${version}/bundle/$cmd/${arch}.tar.gz"; - hash=$(nix-prefetch-url $url) - hash=$(nix hash convert "${hash}" --hash-algo sha256) - fetchurlAttrSetBlock=" - ${fetchurlAttrSetBlock} - $key.$cmd = { - hash = \"${hash}\"; - url = ${url}; - };" - done -done - -OUT_FILE="$SCRIPT_DIR/sources-${channel}.nix" -cat >$OUT_FILE <