summaryrefslogtreecommitdiffstats
path: root/pkgs/os-specific/windows/mingw-w64/update.nu
blob: 7bf26ffa38f5a917eae75d302cb6dc44b0ddf3e6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/usr/bin/env nix-shell
#! nix-shell -i nu -p nushell nix

use std/log

def replace [ p: path old: string new: string ] {
  open $p
  | str replace $old $new
  | save -f $p
}

def eval [ attr: string ] {
  with-env {
    NIXPKGS_ALLOW_UNSUPPORTED_SYSTEM: 1
  } {
    nix eval -f ./. $attr --json
  }
  | from json
}

def main [] {
  # List of all the link in the RSS feed for
  # https://sourceforge.net/projects/mingw-w64/files/mingw-w64/mingw-w64-release/
  let links = http get https://sourceforge.net/projects/mingw-w64/rss?path=/mingw-w64/mingw-w64-release/
  | from xml
  | get content.content.0
  | where tag == item
  | get content
  | flatten
  | where tag == title
  | get content
  | flatten
  | get content

  # Select only files ending in "tar.bz2", then select the largest value
  # We only consider values with at least two digits cause they are at
  # 13.0 and sorting strings doesn't work well if they aren't the same length
  let newest = $links
    | where { ($in | str ends-with "tar.bz2") and ($in =~ v[0-9][0-9]\.) }
    | sort -r
    | get 0

  # Extract the newest version out of the URL
  let new_version = $newest
    | split column /
    | get column3.0
    | split column -
    | get column2.0
    | str replace .tar.bz2 ""
    | str trim -c v

  # Get the current version in the drv
  let current_version = eval "windows.mingw_w64_headers.version"

  if $new_version == $current_version {
    log info "Current mingw-w64 version matches the latest, exiting..."
    return
  } else {
    log info $"Current version is ($current_version)\nLatest version is ($new_version)"
  }

  # Get the current hash
  let current_hash = eval "windows.mingw_w64_headers.src.outputHash"

  # Set to the new version
  replace ./pkgs/os-specific/windows/mingw-w64/headers.nix $current_version $new_version

  # The nix derivation creates the URL from the version, so just grab that.
  let new_url = eval "windows.mingw_w64_headers.src.url"

  # Prefetch to get the new hash
  let new_hash = nix-prefetch-url --type sha256 $new_url
  | nix hash to-sri --type sha256 $in

  # Set the hash
  replace ./pkgs/os-specific/windows/mingw-w64/headers.nix $current_hash $new_hash
}