From e084316130a255313eb026db8bc64a653f5ffb0c Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Sat, 29 Jun 2024 19:28:09 +0200 Subject: [PATCH 1/3] Add mkMesonPackage for local meson packages This helper makes it easy to use filesets that include files from parent directories, which we'll need more of in https://github.com/NixOS/nix/pull/10973 --- packaging/dependencies.nix | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/packaging/dependencies.nix b/packaging/dependencies.nix index 88273df22..484385128 100644 --- a/packaging/dependencies.nix +++ b/packaging/dependencies.nix @@ -10,6 +10,33 @@ stdenv, versionSuffix, }: +let + inherit (pkgs) lib; + + localSourceLayer = finalAttrs: prevAttrs: + let + root = ../.; + workDirPath = + # Ideally we'd pick finalAttrs.workDir, but for now `mkDerivation` has + # the requirement that everything except passthru and meta must be + # serialized by mkDerivation, which doesn't work for this. + prevAttrs.workDir; + + workDirSubpath = lib.path.removePrefix root workDirPath; + sources = assert prevAttrs.fileset._type == "fileset"; prevAttrs.fileset; + src = lib.fileset.toSource { fileset = sources; inherit root; }; + + in + { + sourceRoot = "${src.name}/" + workDirSubpath; + inherit src; + + # Clear what `derivation` can't/shouldn't serialize; see prevAttrs.workDir. + fileset = null; + workDir = null; + }; + +in scope: { inherit stdenv versionSuffix; @@ -55,4 +82,6 @@ scope: { CONFIG_ASH_TEST y ''; }); + + mkMesonDerivation = f: stdenv.mkDerivation (lib.extends localSourceLayer f); } From 7dd938b228c0dc5c5e42eb0efcbbe9929bde9f90 Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Sun, 30 Jun 2024 19:42:05 +0200 Subject: [PATCH 2/3] libutil/package.nix: Remove .version symlink replacement solution --- src/libutil/package.nix | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/src/libutil/package.nix b/src/libutil/package.nix index 892951cdf..1996a6c4d 100644 --- a/src/libutil/package.nix +++ b/src/libutil/package.nix @@ -1,5 +1,6 @@ { lib , stdenv +, mkMesonDerivation , releaseTools , meson @@ -38,22 +39,22 @@ let else stdenv.mkDerivation; in -mkDerivation (finalAttrs: { +mkMesonDerivation (finalAttrs: { pname = "nix-util"; inherit version; - src = fileset.toSource { - root = ./.; - fileset = fileset.unions [ - ./meson.build - ./meson.options - ./linux/meson.build - ./unix/meson.build - ./windows/meson.build - (fileset.fileFilter (file: file.hasExt "cc") ./.) - (fileset.fileFilter (file: file.hasExt "hh") ./.) - ]; - }; + workDir = ./.; + fileset = fileset.unions [ + ../../.version + ./.version + ./meson.build + ./meson.options + ./linux/meson.build + ./unix/meson.build + ./windows/meson.build + (fileset.fileFilter (file: file.hasExt "cc") ./.) + (fileset.fileFilter (file: file.hasExt "hh") ./.) + ]; outputs = [ "out" "dev" ]; @@ -80,13 +81,9 @@ mkDerivation (finalAttrs: { disallowedReferences = [ boost ]; preConfigure = - # "Inline" .version so it's not a symlink, and includes the suffix - '' - echo ${version} > .version - '' # Copy some boost libraries so we don't get all of Boost in our # closure. https://github.com/NixOS/nixpkgs/issues/45462 - + lib.optionalString (!stdenv.hostPlatform.isStatic) ('' + lib.optionalString (!stdenv.hostPlatform.isStatic) ('' mkdir -p $out/lib cp -pd ${boost}/lib/{libboost_context*,libboost_thread*,libboost_system*} $out/lib rm -f $out/lib/*.a From 93b50857edbee33c7c6522d4d5971b5081c5b7c1 Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Sun, 30 Jun 2024 17:25:32 +0200 Subject: [PATCH 3/3] packaging: Restore .version value altering behavior --- src/libutil/package.nix | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/libutil/package.nix b/src/libutil/package.nix index 1996a6c4d..8ba6daa2a 100644 --- a/src/libutil/package.nix +++ b/src/libutil/package.nix @@ -81,9 +81,14 @@ mkMesonDerivation (finalAttrs: { disallowedReferences = [ boost ]; preConfigure = + # TODO: change release process to add `pre` in `.version`, remove it before tagging, and restore after. + '' + chmod u+w ./.version + echo ${version} > ../../.version + '' # Copy some boost libraries so we don't get all of Boost in our # closure. https://github.com/NixOS/nixpkgs/issues/45462 - lib.optionalString (!stdenv.hostPlatform.isStatic) ('' + + lib.optionalString (!stdenv.hostPlatform.isStatic) ('' mkdir -p $out/lib cp -pd ${boost}/lib/{libboost_context*,libboost_thread*,libboost_system*} $out/lib rm -f $out/lib/*.a