Re: switch from i386 to AMD64 without a total rebuild?

From: Matthew Seaman <matthew_at_FreeBSD.org>
Date: Wed, 20 Sep 2023 15:08:31 UTC
On 20/09/2023 15:25, paul beard wrote:
> I don't think I understand pkg leaf. And to be fair, I am reluctant to 
> remove stuff if I don't know what it's doing/why it was installed. 
> Ideally build dependencies that are not needed at runtime are cleaned up 
> but I bet there is some cruft, given the very different totals given 
> below. pkg leaf | wc -l 184 pkg info | wc -l 531 Disk space is not an 
> issue, a 64Gb disk image is more than adequate here.

The idea of `pkg leaf` is to produce a list of all the packages 
installed on your system which no other packages depend on.  This 
implies they are software packages you installed specifically, rather 
than packages pulled in because something else needed them to run.

So, you should be able to tell pkg(8) to install just those leaf 
packages, and pkg will work out what else it needs to install to make 
the leaf packages work, and the end result should be a minimal working 
set of packages to enable your desired software load out.

Now, using "leaf" packages like this is only one way of guessing if a 
package is directly required.  pkg(8) actually records equivalent 
information itself using the 'automatic' flag.  So, if you `pkg install 
foo` and pkg works out it needs to install:

      foo-1.2.3
      bar-0.0.1

Then `bar-0.0.1` would be marked as 'automatic' -- this flag will be 
preserved if bar gets upgraded or reinstalled at a later date.

You can see the non-automatic packages you have installed by:

     pkg query -e '%a == 0' '%n-%v'

and this list can be used as an alternative to the output from `pkg 
leaf`  ('%a == 1' will show the automatic packages)

Should you at some future point decide to remove `foo-1.2.3` you can 
tidy up any automatically installed packages by:

    pkg autoremove -y

which in this example would remove `bar-0.0.1` so long as no other 
package depended on it.

You can toggle the automatic status of packages using pkg-set(8), and 
you can force a package to be marked automatic at install time by
`pkg install -A foo` --- this is very handy for temporary installations.

If you install packages by compiling from ports: eg.

    cd /usr/ports/devel/foo
    make install

then any build, run or test dependencies also installed as a result of 
that command will be marked as automatic.  If such a dependency is only 
required for build or test, but not run then you can delete it 
immediately by `pkg autoremove`

	Cheers,

	Matthew