From 25b3311b5ac0fe75da92f398f0feb695092a856d Mon Sep 17 00:00:00 2001 From: Ryan Clark Date: Wed, 18 Dec 2024 11:39:41 -0600 Subject: [PATCH] Update default.nix and remove overlays for uv package management --- home/features/development/default.nix | 2 +- overlays/default.nix | 32 ----------- overlays/flake.nix | 38 ++++++++++++++ overlays/update-uv.sh | 76 ++++++++++++++++++++++----- overlays/uv-overlay.nix | 16 ++++++ 5 files changed, 117 insertions(+), 47 deletions(-) delete mode 100644 overlays/default.nix create mode 100644 overlays/flake.nix create mode 100644 overlays/uv-overlay.nix diff --git a/home/features/development/default.nix b/home/features/development/default.nix index e84aad41..1a7fc74e 100644 --- a/home/features/development/default.nix +++ b/home/features/development/default.nix @@ -23,7 +23,7 @@ tokei # code statistics cachix nix-prefetch-git # nix development - nix-prefetch-url # nix Development + uv # for python ]; } diff --git a/overlays/default.nix b/overlays/default.nix deleted file mode 100644 index 60a07708..00000000 --- a/overlays/default.nix +++ /dev/null @@ -1,32 +0,0 @@ -# This file defines overlays -{ - # inputs, - ... -}: - -{ - # https://nixos.wiki/wiki/Overlays - - # modifications = final: prev: { - # vscode = prev.vscode.overrideAttrs (_: rec { - # version = "1.90.2"; - # plat = "linux-x64"; - # archive_fmt = "tar.gz"; - # pname = "vscode"; - # src = prev.fetchurl { - # url = "https://update.code.visualstudio.com/${version}/${plat}/stable"; - # sha256 = "bc15c4bf497c569af0726c218328c6ffe85a2189f544897be52157a7a27e0c34"; - # name = "VSCode_${version}_${plat}.${archive_fmt}"; - # }; - # }); - - # # When applied, the unstable nixpkgs set (declared in the flake inputs) will - # # be accessible through 'pkgs.unstable' - # unstable-packages = final: prev: { - # unstable = import inputs.nixpkgs { - # inherit (final) system; - # config.allowUnfree = true; - # }; - # }; - # }; -} diff --git a/overlays/flake.nix b/overlays/flake.nix new file mode 100644 index 00000000..188c5f11 --- /dev/null +++ b/overlays/flake.nix @@ -0,0 +1,38 @@ +# This file defines overlays +{ + inputs, + ... +}: + +{ + # https://nixos.wiki/wiki/Overlays + + modifications = final: prev: { + + uv = prev.uv.overrideAttrs (_: rec { + version = "0.5.10"; + src = prev.fetchFromGitHub { + owner = "astral-sh"; + repo = "uv"; + rev = "refs/tags/${version}"; + hash = "sha256-GE/MgaX6JhzVVwrkz33fr1Vl83QD1WHhlB7vPdJ2W3c="; + }; + cargoDeps = prev.rustPlatform.fetchCargoTarball { + inherit src; + name = "uv-${version}"; + hash = "sha256-GE/MgaX6JhzVVwrkz33fr1Vl83QD1WHhlB7vPdJ2W3c="; + }; + }); + + }; + + # When applied, the unstable nixpkgs set (declared in the flake inputs) will + # be accessible through 'pkgs.unstable' + unstable-packages = final: prev: { + unstable = import inputs.nixpkgs { + inherit (final) system; + config.allowUnfree = true; + }; + }; + +} diff --git a/overlays/update-uv.sh b/overlays/update-uv.sh index 4e3e3ae6..296db7f2 100755 --- a/overlays/update-uv.sh +++ b/overlays/update-uv.sh @@ -1,30 +1,78 @@ #!/usr/bin/env bash -# Get the source hash using nix-prefetch-url -echo "Fetching source hash..." -src_hash=$(nix-prefetch-url --unpack https://github.com/astral-sh/uv/archive/refs/tags/0.5.10.tar.gz) -echo "Source hash obtained" +# Function to get latest version from GitHub releases +get_latest_version() { + curl -s https://api.github.com/repos/astral-sh/uv/releases/latest | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/' +} + +# Function to get hashes +get_hashes() { + local version=$1 + + # Get source hash + local src_hash=$(nix-prefetch-url --unpack https://github.com/astral-sh/uv/archive/refs/tags/${version}.tar.gz) + src_hash="sha256-$(nix-hash --type sha256 --to-base64 $src_hash)" -# Create a temporary Nix expression to get the cargo hash -cat > temp.nix << 'EOF' + # Create temporary nix file for cargo hash + cat > temp.nix << EOF { pkgs ? import {} }: pkgs.rustPlatform.fetchCargoTarball { src = pkgs.fetchFromGitHub { owner = "astral-sh"; repo = "uv"; - rev = "refs/tags/0.5.10"; + rev = "refs/tags/${version}"; hash = "sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA="; }; - name = "uv-0.5.10"; + name = "uv-${version}"; hash = "sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA="; } EOF -echo "Fetching cargo hash..." -cargo_hash=$(nix-build temp.nix 2>&1 | grep 'got:' | tail -n1 | awk '{print $2}') -rm temp.nix + # Get cargo hash + local cargo_hash=$(nix-build temp.nix 2>&1 | grep 'got:' | tail -n1 | awk '{print $2}') + rm temp.nix + + echo "${src_hash} ${cargo_hash}" +} + +# Function to update the overlay file +update_overlay() { + local version=$1 + local src_hash=$2 + local cargo_hash=$3 + local overlay_file="uv-overlay.nix" + + cat > "${overlay_file}" << EOF +final: prev: { + uv = prev.uv.overrideAttrs (oldAttrs: { + version = "${version}"; + src = prev.fetchFromGitHub { + owner = "astral-sh"; + repo = "uv"; + rev = "refs/tags/\${oldAttrs.version}"; + hash = "${src_hash}"; + }; + cargoDeps = prev.rustPlatform.fetchCargoTarball { + inherit (oldAttrs) src; + name = "uv-\${oldAttrs.version}"; + hash = "${cargo_hash}"; + }; + }); +} +EOF +} + +# Main execution +echo "Checking for latest uv version..." +LATEST_VERSION=$(get_latest_version) +echo "Latest version: ${LATEST_VERSION}" + +echo "Getting hashes..." +read src_hash cargo_hash <<< $(get_hashes "${LATEST_VERSION}") +echo "Source hash: ${src_hash}" +echo "Cargo hash: ${cargo_hash}" -echo "=== Results ===" -echo "Source hash: sha256-$(nix has convert --type sha256 --to-base64 $src_hash)" -echo "Cargo hash: $cargo_hash" +echo "Updating overlay..." +update_overlay "${LATEST_VERSION}" "${src_hash}" "${cargo_hash}" +echo "Overlay updated successfully!" \ No newline at end of file diff --git a/overlays/uv-overlay.nix b/overlays/uv-overlay.nix new file mode 100644 index 00000000..b2e6c816 --- /dev/null +++ b/overlays/uv-overlay.nix @@ -0,0 +1,16 @@ +final: prev: { + uv = prev.uv.overrideAttrs (oldAttrs: { + version = "0.5.10"; + src = prev.fetchFromGitHub { + owner = "astral-sh"; + repo = "uv"; + rev = "refs/tags/${oldAttrs.version}"; + hash = "sha256-GE/MgaX6JhzVVwrkz33fr1Vl83QD1WHhlB7vPdJ2W3c="; + }; + cargoDeps = prev.rustPlatform.fetchCargoTarball { + inherit (oldAttrs) src; + name = "uv-${oldAttrs.version}"; + hash = "sha256-GE/MgaX6JhzVVwrkz33fr1Vl83QD1WHhlB7vPdJ2W3c="; + }; + }); +}