go2nix icon indicating copy to clipboard operation
go2nix copied to clipboard

Add support for sub-packages

Open rushmorem opened this issue 7 years ago • 3 comments

If you have a number of sub-packages that share a common repo, it can be very inconvenient to have to run go2nix save in each package separately.

rushmorem avatar Aug 24 '16 09:08 rushmorem

i've hacked together this script and it is a helper in getting the deps together.

using https://github.com/nixcloud/nix-beautify we can now generate nice and unique deps.nix files:

uniqueDeps.sh

#!/usr/bin/env bash

#https://groups.google.com/forum/#!topic/golang-nuts/611QEJqkDKw
#deps=$(go list -f {{.Deps}})
pushd nixcloud.io/auth-server/
deps=$(go list -f '{{join .Deps "\n"}}' |  xargs go list -f '{{if not .Standard}}{{.ImportPath}}{{end}} ' | sort | uniq)
popd
  
rm -Rf mydeps
mkdir mydeps

for i in $deps; do
  echo $i
  pushd $i
  go2nix save
  popd
  d=$(echo $i | base64)
  cp $i/deps.nix mydeps/$d.nix
done

pushd mydeps
cat * | grep -v '\[' | grep -v '\]' | grep -v "This file was generated" > deps.nix
echo '[' > deps.nix_
cat deps.nix >> deps.nix_
echo ']' >> deps.nix_
mv deps.nix_ deps.nix
nix-instantiate --eval --strict -E 'let pkgs=import <nixpkgs>{}; in pkgs.lib.unique (import ./deps.nix)' | sed -e 's/};/};\n/g' | sed -e 's/} /}\n/g' | sed -e 's/{/{\n/g' | sed -e 's/; /;\n/g' > deps.nix_
popd

cat deps.nix_ | nix-beautify > deps.nix

qknight avatar Nov 28 '17 23:11 qknight

@kamilchm might interest you, i've hacked https://github.com/nixcloud/dep2nix together

qknight avatar Feb 16 '18 02:02 qknight

I'm less in Go now and I couldn't find time to complete my dep branch. I'm glad someone did it 👍

kamilchm avatar Feb 16 '18 12:02 kamilchm