|
| 1 | +# coding=utf-8 |
| 2 | +# |
| 3 | +# The Qubes OS Project, http://www.qubes-os.org |
| 4 | +# |
| 5 | +# This program is free software; you can redistribute it and/or |
| 6 | +# modify it under the terms of the GNU General Public License |
| 7 | +# as published by the Free Software Foundation; either version 2 |
| 8 | +# of the License, or (at your option) any later version. |
| 9 | +# |
| 10 | +# This program is distributed in the hope that it will be useful, |
| 11 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | +# GNU General Public License for more details. |
| 14 | +# |
| 15 | +# You should have received a copy of the GNU General Public License |
| 16 | +# along with this program; if not, write to the Free Software |
| 17 | +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, |
| 18 | +# USA. |
| 19 | + |
| 20 | +from typing import List, Dict |
| 21 | + |
| 22 | +from source.common.package_manager import PackageManager |
| 23 | +from source.common.process_result import ProcessResult |
| 24 | + |
| 25 | + |
| 26 | +class NIXOSCLI(PackageManager): |
| 27 | + def __init__(self, log_handler, log_level): |
| 28 | + super().__init__(log_handler, log_level) |
| 29 | + self.package_manager = "qubes-nixos-rebuild" |
| 30 | + |
| 31 | + def refresh(self, hard_fail: bool) -> ProcessResult: |
| 32 | + """ |
| 33 | + Use package manager to refresh available packages. |
| 34 | +
|
| 35 | + Note: Is a no-op in NixOS because the qubes-nixos-rebuild |
| 36 | + wrapper takes care of it, and having just sync could cause problems. |
| 37 | +
|
| 38 | + :return: (exit_code, stdout, stderr) |
| 39 | + """ |
| 40 | + cmd = ["true"] |
| 41 | + return self.run_cmd(cmd) |
| 42 | + |
| 43 | + def get_packages(self) -> Dict[str, List[str]]: |
| 44 | + """ |
| 45 | + Use nix to return the installed packages and their versions. |
| 46 | + """ |
| 47 | + |
| 48 | + cmd = ["qubes-nixos-get-packages"] |
| 49 | + # EXAMPLE OUTPUT: |
| 50 | + # qubes-core-agent-linux: ∅ → 4.3.5, +1413.6 KiB |
| 51 | + # python3: ∅ → 3.11.9, 3.12.4, +229814.3 KiB |
| 52 | + # dns-root-data: ∅ → 2024-06-20 |
| 53 | + |
| 54 | + result = self.run_cmd(cmd, realtime=False) |
| 55 | + |
| 56 | + packages: Dict[str, List[str]] = {} |
| 57 | + for line in result.out.splitlines(): |
| 58 | + package, info = line.split(":", 1) |
| 59 | + versions = info.lstrip("∅ → ").split(", ") |
| 60 | + for version in versions: |
| 61 | + if not version.startswith("+"): |
| 62 | + packages.setdefault(package, []).append(version) |
| 63 | + |
| 64 | + return packages |
| 65 | + |
| 66 | + def get_action(self, remove_obsolete) -> List[str]: |
| 67 | + """ |
| 68 | + qubes-nixos-rebuild will handle obsoletions itself |
| 69 | + """ |
| 70 | + return [] |
0 commit comments