Skip to content

Commit

Permalink
nix: simplify the update script using nix flake eval
Browse files Browse the repository at this point in the history
Signed-off-by: Avimitin <[email protected]>
  • Loading branch information
Avimitin committed Nov 17, 2023
1 parent 8954d5b commit 10d13ec
Showing 1 changed file with 4 additions and 21 deletions.
25 changes: 4 additions & 21 deletions nix/update_ts_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,11 @@

require 'json'

pkg = `nix eval --impure --raw --expr \
"with import <nixpkgs> { overlays = [(import ./overlay.nix)]; }; nvim-treesitter-parsers"`
puts "Updating dependencies for #{pkg}"
srcs = `nix eval --json .#nvim-treesitter-parsers --apply \
"drv: map (p: { name = p.pname; url = p.src.url; hash = p.src.outputHash; }) drv.tsParsers"`

drv_path = `nix-store --query --deriver "#{pkg}"`.strip
puts "Derivation for #{pkg}: #{drv_path}"

def filter_treesitter_drv(drv)
raw_output = `nix derivation show #{drv}^*`
JSON.parse(raw_output)[drv]['inputDrvs'].keys.select { |name| name.match(/tree-sitter-\w+-/) }
end

parser_inputs = filter_treesitter_drv(drv_path)
src_inputs = parser_inputs.map { |drv| filter_treesitter_drv(drv) }.flatten

srcs = src_inputs.map do |drv|
info = JSON.parse(`nix derivation show #{drv}^*`)[drv]['env']
{ name: info['name'], url: info['urls'], hash: info['outputHash'] }
end

srcs.each do |info|
name, url, hash = info.values_at(:name, :url, :hash)
JSON.parse(srcs).each do |info|
name, url, hash = info.values_at("name", "url", "hash")
puts "Downloading #{name} source from #{url}"
new_file = `nix-prefetch-url #{url} --print-path --type sha256 | tail -n1`.strip
new_hash = `nix hash file --base16 --type sha256 --sri #{new_file}`.strip
Expand Down

0 comments on commit 10d13ec

Please sign in to comment.