Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow adding / installing packages with --asdeps #58

Open
funketh opened this issue Sep 24, 2019 · 5 comments
Open

Allow adding / installing packages with --asdeps #58

funketh opened this issue Sep 24, 2019 · 5 comments

Comments

@funketh
Copy link

funketh commented Sep 24, 2019

pacman allows you to install packages with the option --asdeps to mark them as dependencies.
This is useful for optional dependencies as pacman can then recognize them as orphans when the packages that optionally required them are removed.
Supporting this flag might also help with the limitations mentioned in the README.

@CyberShadow
Copy link
Owner

CyberShadow commented Sep 24, 2019

Let's assume hypothetically that AddPackage --asdeps is added to aconfmgr, and you add a package in that way to your configuration.

  • What do you expect to happen when you run aconfmgr apply, and that package is not installed on the system, nor is it required by any other package in your configuration?

  • What do you expect to happen when you run aconfmgr apply, and that package is installed on the system, but it is not required by any other package in your configuration?

@funketh
Copy link
Author

funketh commented Sep 25, 2019

Well I think that for consistency's sake there are two options:

  • install/keep
  • don't install/remove

Either way, you should get a warning.
Removing/not installing the package seems to be the better solution because the package shouldn't have a purpose and is therefore a mistake in the configuration.
If the user needs the package even though no packages depend on it then that package is not a dependency and should be explicitly installed.

@OJFord
Copy link

OJFord commented May 30, 2020

I'd like this - aconfmgr doing something sensible with it would actually make --asdeps more useful to me than it is today.

@CyberShadow CyberShadow changed the title [Feature Request] Make it possible to specify the installation reason for a package Allow adding / installing packages with --asdeps Nov 22, 2021
@CyberShadow
Copy link
Owner

I think this makes sense on paper, but it would make certain aspects of aconfmgr's implementation much more complicated.

For now, I suggest a pragmatic approach: place each instance of such a dependency beneath its main package in the configuration file (along with said package's other configuration). When you no longer need the main package, you would also remove the dependency.

It is valid to specify a package more than once, so the dependency can be specified as often as necessary.

@m-wells
Copy link

m-wells commented Apr 4, 2024

What if there is a 98-asdeps.sh?
This could be populated via a script that is run before aconfmgr save

#!/bin/bash

outfile="${XDG_CONFIG_HOME}/aconfmgr/98-asdeps.sh"
pacman -Qd --native | awk '{print "AddAsDeps "$1}' > "$outfile"
printf '\n\n# Foreign dependencies\n\n\n' >> "$outfile"
pacman -Qd --foreign | awk '{print "AddAsDeps --foreign "$1}' >> "$outfile"

where

#!/bin/bash

function AddAsDeps() {
    local fn='dependencies.txt'
    if [[ "$1" == "--foreign" ]]
    then
        shift
        fn="foreign-dependencies.txt"
    fi
    printf '%q\n' "$@" >> "${output_dir}/${fn}"
}

Then these can be processed with

#!/bin/bash

# this would get called on each line of `dependencies.txt`
function resolve_dependency() {
  # check if the provided package is installed
  if pacman -q -Qs "^$1\$" > /dev/null; then
    pacman -D --asdeps "$1"
  else
    pacman -S --asdeps "$1"
  fi
}

and a complementary version for foreign-dependencies.txt.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants