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

apt: fix runtime state paths #18

Open
milahu opened this issue Dec 24, 2023 · 0 comments
Open

apt: fix runtime state paths #18

milahu opened this issue Dec 24, 2023 · 0 comments

Comments

@milahu
Copy link
Owner

milahu commented Dec 24, 2023

currently, apt uses /nix/store paths as default runtime state paths

$ sudo apt update 
Reading package lists... Done
Building dependency tree... Done
All packages are up to date.
W: chmod 0700 of directory /nix/store/zrypwimnzv5y7j8bdbsnp6fq2an26b6x-apt-2.7.3/var/lib/apt/lists/partial failed - SetupAPTPartialDirectory (30: Read-only file system)
W: Not using locking for read only lock file /nix/store/zrypwimnzv5y7j8bdbsnp6fq2an26b6x-apt-2.7.3/var/lib/apt/lists/lock
W: No sandbox user '_apt' on the system, can not drop privileges

expected: apt should use FHS paths as default runtime state paths

for example

- /nix/store/zrypwimnzv5y7j8bdbsnp6fq2an26b6x-apt-2.7.3/var/lib/apt
+ /var/lib/apt

running apt on nixos will usually use custom runtime state paths
but anyway, the default paths should be fixed

APT_CONFIG=$HOME/.config/apt/apt.conf

$HOME/.config/apt/apt.conf

Dir "/home/user";
Dir::Etc ".config/apt";
Dir::State ".lib/apt";
Dir::Cache ".cache/apt";
APT::Default-Release "unstable";
APT::Sandbox::User "nobody";

the patchPhase could be shorter...
this whole block is removed from CMakeLists.txt
so this could be done with a regex (perl regex for multiline)

# Create our directories.
install_empty_directories(
  ${CONF_DIR}/apt.conf.d
  ${CONF_DIR}/auth.conf.d
  ${CONF_DIR}/preferences.d
  ${CONF_DIR}/sources.list.d
  ${CONF_DIR}/trusted.gpg.d
  ${CACHE_DIR}/archives/partial
  ${STATE_DIR}/lists/partial
  ${STATE_DIR}/mirrors/partial
  ${STATE_DIR}/periodic
  ${LOG_DIR}
)

milahu/nur-packages@86e6f89

commit 86e6f89b307c4f79b2a3d672affacee9c2b29632
Author: Milan Hauth <[email protected]>
Date:   Fri Dec 22 15:40:45 2023 +0100

    apt: fix runtime state paths

diff --git a/pkgs/tools/package-management/apt/apt.nix b/pkgs/tools/package-management/apt/apt.nix
index 6991a5a..fd8b53a 100644
--- a/pkgs/tools/package-management/apt/apt.nix
+++ b/pkgs/tools/package-management/apt/apt.nix
@@ -76,6 +76,36 @@ stdenv.mkDerivation rec {
     "-DWITH_DOC=${if withDocs then "ON" else "OFF"}"
   ];
 
+  # dont use /nix/store for these paths
+  # dont create these paths: /etc/apt/apt.conf.d ...
+  # TODO substituteInPlace with regex? or perl regex?
+  # TODO allow to pass multiple paths instead of $out/libexec/apt
+  # so we can use more handlers than /libexec/apt/methods/http etc
+  postPatch = ''
+    substituteInPlace CMakeLists.txt \
+      --replace '"''${CMAKE_INSTALL_FULL_LOCALSTATEDIR}/lib/apt"' '"/var/lib/apt"' \
+      --replace '"''${CMAKE_INSTALL_FULL_LOCALSTATEDIR}/cache/apt"' '/var/cache/apt' \
+      --replace '"''${CMAKE_INSTALL_FULL_LOCALSTATEDIR}/log/apt"' '/var/log/apt' \
+      --replace '"''${CMAKE_INSTALL_FULL_SYSCONFDIR}/apt"' '/etc/apt' \
+      --replace '"''${CMAKE_INSTALL_FULL_LIBEXECDIR}/apt"' "$out/libexec/apt" \
+      --replace $'  ''${CONF_DIR}/apt.conf.d\n' "" \
+      --replace $'  ''${CONF_DIR}/auth.conf.d\n' "" \
+      --replace $'  ''${CONF_DIR}/preferences.d\n' "" \
+      --replace $'  ''${CONF_DIR}/sources.list.d\n' "" \
+      --replace $'  ''${CONF_DIR}/trusted.gpg.d\n' "" \
+      --replace $'  ''${CACHE_DIR}/archives/partial\n' "" \
+      --replace $'  ''${STATE_DIR}/lists/partial\n' "" \
+      --replace $'  ''${STATE_DIR}/mirrors/partial\n' "" \
+      --replace $'  ''${STATE_DIR}/periodic\n' "" \
+      --replace $'  ''${LOG_DIR}\n' "" \
+      --replace $'\n# Create our directories.\ninstall_empty_directories(\n)\n' ""
+
+    substituteInPlace apt-pkg/init.cc \
+      --replace \
+        'Cnf.CndSet("APT::Sandbox::User", "_apt");' \
+        'Cnf.CndSet("APT::Sandbox::User", "nobody");'
+  '';
+
   meta = with lib; {
     homepage = "https://salsa.debian.org/apt-team/apt";
     description = "Command-line package management tools used on Debian-based systems";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant