Skip to content

Commit

Permalink
Update default.nix and remove overlays for uv package management
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanwclark committed Dec 18, 2024
1 parent 98c834d commit 25b3311
Show file tree
Hide file tree
Showing 5 changed files with 117 additions and 47 deletions.
2 changes: 1 addition & 1 deletion home/features/development/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
tokei # code statistics
cachix
nix-prefetch-git # nix development
nix-prefetch-url # nix Development
uv # for python
];

}
32 changes: 0 additions & 32 deletions overlays/default.nix

This file was deleted.

38 changes: 38 additions & 0 deletions overlays/flake.nix
Original file line number Diff line number Diff line change
@@ -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;
};
};

}
76 changes: 62 additions & 14 deletions overlays/update-uv.sh
Original file line number Diff line number Diff line change
@@ -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 <nixpkgs> {} }:
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!"
16 changes: 16 additions & 0 deletions overlays/uv-overlay.nix
Original file line number Diff line number Diff line change
@@ -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=";
};
});
}

0 comments on commit 25b3311

Please sign in to comment.