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

munge: Fix installation paths #319401

Merged
merged 2 commits into from
Jun 21, 2024
Merged

munge: Fix installation paths #319401

merged 2 commits into from
Jun 21, 2024

Conversation

jtojnar
Copy link
Member

@jtojnar jtojnar commented Jun 12, 2024

Description of changes

Removing src/etc/Makefile is overly intrusive, as the file is responsible for installing pkg-config file. The issue when it would try to write to the specified out-of-store paths can be easily resolved by overriding them to ones within $out during installation.

Also set sysconfdir path properly to allow configuring it with environment.etc. There should be no problem with missing files, as nothing was installed to $out/etc previously either, other than an empty munge directory.

runstatedir defaults to $(localstatedir)/run but that has long been deprecated in favour of /run, so let’s fix that as well.

pkgconfigdir and sysconfigdir (not to be confused with the standard sysconfdir) rely on FHS for proper detection and systemdunitdir tries to run systemd --version, let’s just hardcode them. sysconfigdir is mentioned in the newly installed munge.service and a file within is loaded as EnvironmentFile when it exists so let’s override the path for installation so the file can serve as a template in $out. The other two are installation-only so we can directly set them to $out subdirectories.

Also clean up the expression.

Things done

  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandboxing enabled in nix.conf? (See Nix manual)
    • sandbox = relaxed
    • sandbox = true
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • 24.11 Release Notes (or backporting 23.11 and 24.05 Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
  • Fits CONTRIBUTING.md.

Add a 👍 reaction to pull requests you find important.

@nixos-discourse
Copy link

This pull request has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/unable-to-locate-pckg-installation-in-configure-phase-during-nix-build/46920/2

@veprbl
Copy link
Member

veprbl commented Jun 12, 2024

Result of nixpkgs-review pr 319401 run on x86_64-darwin 1

1 package built:
  • munge

@markuskowa
Copy link
Member

@GrahamcOfBorg test slurm

pkgs/tools/security/munge/default.nix Show resolved Hide resolved
"--with-pkgconfigdir=${placeholder "out"}/lib/pkgconfig"
"--with-systemdunitdir=${placeholder "out"}/lib/systemd/system"

# Cross-compilation fixes
"--with-libgcrypt-prefix=${libgcrypt.dev}"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"--with-libgcrypt-prefix=${libgcrypt.dev}"
"--with-libgcrypt-prefix=${lib.getDev libgcrypt}"

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not even sure if this is still necessary. <rant>Cross people keep introducing junk like this without any mention how to reproduce the failure or attempts to resolve this upstream. I am half inclined to just revert faacc88 @NickCao</rant>

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have no opinion on the cross-compilation issue.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 to getDev, but I'm not sure I understand what issue the comment refers to (even though I suspect I've seen it before)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, done.

By the way, I managed to reproduce a cross failure with pkgsCross.aarch64-multiplatform.munge when I revert faacc88.

The libgcrypt.dev in nativeBuildInputs is needed for libgcrypt.m4 to be picked up for ACLOCAL_PATH (see also #311773 (comment)). And --with-libgcrypt-prefix is probably needed because the m4 file/libgcrypt-config cannot handle multiple outputs.

It appears possible to force it to use pkg-config but that is no less hacky:

Patch
diff --git a/pkgs/tools/security/munge/default.nix b/pkgs/tools/security/munge/default.nix
index f21a9e17add3..1a7ada38fa95 100644
--- a/pkgs/tools/security/munge/default.nix
+++ b/pkgs/tools/security/munge/default.nix
@@ -1,6 +1,7 @@
 {
   lib,
   stdenv,
+  pkg-config,
   fetchFromGitHub,
   autoreconfHook,
   libgcrypt,
@@ -21,7 +22,7 @@ stdenv.mkDerivation (finalAttrs: {
 
   nativeBuildInputs = [
     autoreconfHook
-    libgcrypt # provides libgcrypt.m4
+    pkg-config
   ];
 
   buildInputs = [
@@ -44,7 +45,7 @@ stdenv.mkDerivation (finalAttrs: {
     "--with-systemdunitdir=${placeholder "out"}/lib/systemd/system"
 
     # Cross-compilation hacks
-    "--with-libgcrypt-prefix=${lib.getDev libgcrypt}"
+    "GPGRT_CONFIG=${stdenv.cc.targetPrefix}pkg-config"
     # workaround for cross compilation: https://github.com/dun/munge/issues/103
     "ac_cv_file__dev_spx=no"
     "x_ac_cv_check_fifo_recvfd=no"
@@ -57,6 +58,11 @@ stdenv.mkDerivation (finalAttrs: {
     "sysconfigdir=${placeholder "out"}/etc/default"
   ];
 
+  preAutoreconf = ''
+    # For some reason, automake setup hook does not pick it up from buildInputs.
+    addAclocals "${lib.getDev libgcrypt}"
+  '';
+
   postInstall = ''
     # rmdir will notify us if anything new is installed to the directories.
     rmdir "$out"/{var{/{lib,log}{/munge,},},etc/munge}

Ideally, all of this would be resolved upstream but m4 is the opposite of exciting to work with.

- Format & re-order the expression.
- Use finalAttrs pattern.
- Fix license according to https://github.com/dun/munge/wiki/License-Info.
- Use `lib.getDev` instead of directly using `dev` output. This provides loose coupling in case `dev` output is merged back to `out`.
- Add comment to segregate cross-configuration hacks from rest of the configuration flags.
  They were introduced in faacc88
  and appear to be still necessary to build `pkgsCross.aarch64-multiplatform.munge`.
Removing `src/etc/Makefile` is overly intrusive, as the file is responsible
for installing pkg-config file.  The issue when it would try to write to
the specified out-of-store paths can be easily resolved by overriding them
to ones within `$out` during installation.

Also set `sysconfdir` path properly to allow configuring it with `environment.etc`.
There should be no problem with missing files, as nothing was installed
to `$out/etc` previously either, other than an empty `munge` directory.

`localstatedir` is used at runtime and installation creates empty directories in `$out`.
But since we do not merge those directories into running system, having them in `$out`
serves no purpose.  Creation of `StateDir` and logging is handled by systemd anyway.

`runstatedir` defaults to `$(localstatedir)/run` but that has long been
deprecated in favour of `/run`, so let’s fix that as well.

`pkgconfigdir` and `sysconfigdir` (not to be confused with the standard `sysconfdir`)
rely on FHS for proper detection and `systemdunitdir` tries to run `systemd --version`,
let’s just hardcode them.  `sysconfigdir` is mentioned in the newly installed
and currently unused `munge.service` – a file within is loaded as `EnvironmentFile`
when it exists so let’s override the path for installation.  This will again make it
so the file can serve as a template in `$out` but the service will load it from `/etc`.

The last two options are installation-only so we can directly set them to `$out` subdirectories.
@jtojnar jtojnar merged commit 69802c3 into NixOS:master Jun 21, 2024
24 checks passed
@jtojnar jtojnar deleted the munge branch June 21, 2024 21:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants