Skip to content

Commit

Permalink
Merge pull request #10855 from NixOS/meson-libutil
Browse files Browse the repository at this point in the history
Build `nix-util` with Meson
  • Loading branch information
Ericson2314 authored Jun 12, 2024
2 parents 0e22559 + 28d2af4 commit 96cf6b0
Show file tree
Hide file tree
Showing 12 changed files with 553 additions and 33 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ perl/Makefile.config
/svn-revision
/libtool
/config/config.*
# Default meson build dir
/build

# /doc/manual/
/doc/manual/*.1
Expand Down
75 changes: 48 additions & 27 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -160,21 +160,23 @@
};
});

nix-util = final.callPackage ./src/libutil/package.nix {
inherit
fileset
stdenv
officialRelease
versionSuffix
;
};

nix =
let
officialRelease = false;
versionSuffix =
if officialRelease
then ""
else "pre${builtins.substring 0 8 (self.lastModifiedDate or self.lastModified or "19700101")}_${self.shortRev or "dirty"}";

in final.callPackage ./package.nix {
final.callPackage ./package.nix {
inherit
fileset
stdenv
officialRelease
versionSuffix
;
officialRelease = false;
boehmgc = final.boehmgc-nix;
libgit2 = final.libgit2-nix;
libseccomp = final.libseccomp-nix;
Expand Down Expand Up @@ -203,7 +205,7 @@
# 'nix.perl-bindings' packages.
overlays.default = overlayFor (p: p.stdenv);

hydraJobs = import ./build/hydra.nix {
hydraJobs = import ./maintainers/hydra.nix {
inherit
inputs
binaryTarball
Expand Down Expand Up @@ -236,11 +238,29 @@
} // devFlake.checks.${system} or {}
);

packages = forAllSystems (system: rec {
inherit (nixpkgsFor.${system}.native) nix changelog-d;
default = nix;
} // (lib.optionalAttrs (builtins.elem system linux64BitSystems) {
nix-static = nixpkgsFor.${system}.static.nix;
packages = forAllSystems (system: {
inherit (nixpkgsFor.${system}.native)
changelog-d;
default = self.packages.${system}.nix;
} // lib.concatMapAttrs
(pkgName: {}: {
"${pkgName}" = nixpkgsFor.${system}.native.${pkgName};
"${pkgName}-static" = nixpkgsFor.${system}.static.${pkgName};
} // lib.concatMapAttrs
(crossSystem: {}: {
"${pkgName}-${crossSystem}" = nixpkgsFor.${system}.cross.${crossSystem}.${pkgName};
})
(lib.genAttrs crossSystems (_: { }))
// lib.concatMapAttrs
(stdenvName: {}: {
"${pkgName}-${stdenvName}" = nixpkgsFor.${system}.stdenvs."${stdenvName}Packages".${pkgName};
})
(lib.genAttrs stdenvs (_: { })))
{
"nix" = { };
"nix-util" = { };
}
// lib.optionalAttrs (builtins.elem system linux64BitSystems) {
dockerImage =
let
pkgs = nixpkgsFor.${system}.native;
Expand All @@ -255,25 +275,19 @@
ln -s ${image} $image
echo "file binary-dist $image" >> $out/nix-support/hydra-build-products
'';
} // builtins.listToAttrs (map
(crossSystem: {
name = "nix-${crossSystem}";
value = nixpkgsFor.${system}.cross.${crossSystem}.nix;
})
crossSystems)
// builtins.listToAttrs (map
(stdenvName: {
name = "nix-${stdenvName}";
value = nixpkgsFor.${system}.stdenvs."${stdenvName}Packages".nix;
})
stdenvs)));
});

devShells = let
makeShell = pkgs: stdenv: (pkgs.nix.override { inherit stdenv; forDevShell = true; }).overrideAttrs (attrs:
let
modular = devFlake.getSystem stdenv.buildPlatform.system;
in {
pname = "shell-for-" + attrs.pname;

# Remove the version suffix to avoid unnecessary attempts to substitute in nix develop
version = lib.fileContents ./.version;
name = attrs.pname;

installFlags = "sysconfdir=$(out)/etc";
shellHook = ''
PATH=$prefix/bin:$PATH
Expand All @@ -288,12 +302,19 @@
src = null;

env = {
# Needed for Meson to find Boost.
# https://github.com/NixOS/nixpkgs/issues/86131.
BOOST_INCLUDEDIR = "${lib.getDev pkgs.boost}/include";
BOOST_LIBRARYDIR = "${lib.getLib pkgs.boost}/lib";
# For `make format`, to work without installing pre-commit
_NIX_PRE_COMMIT_HOOKS_CONFIG =
"${(pkgs.formats.yaml { }).generate "pre-commit-config.yaml" modular.pre-commit.settings.rawConfig}";
};

inherit (pkgs.nix-util) mesonFlags;

nativeBuildInputs = attrs.nativeBuildInputs or []
++ pkgs.nix-util.nativeBuildInputs
++ [
modular.pre-commit.settings.package
(pkgs.writeScriptBin "pre-commit-hooks-install"
Expand Down
12 changes: 8 additions & 4 deletions build/hydra.nix → maintainers/hydra.nix
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,21 @@ let

doBuild = false;
};

forAllPackages = lib.genAttrs [ "nix" "nix-util" ];
in
{
# Binary package for various platforms.
build = forAllSystems (system: self.packages.${system}.nix);

shellInputs = forAllSystems (system: self.devShells.${system}.default.inputDerivation);

buildStatic = lib.genAttrs linux64BitSystems (system: self.packages.${system}.nix-static);
buildStatic = forAllPackages (pkgName:
lib.genAttrs linux64BitSystems (system: nixpkgsFor.${system}.static.${pkgName}));

buildCross = forAllCrossSystems (crossSystem:
lib.genAttrs [ "x86_64-linux" ] (system: self.packages.${system}."nix-${crossSystem}"));
buildCross = forAllPackages (pkgName:
forAllCrossSystems (crossSystem:
lib.genAttrs [ "x86_64-linux" ] (system: nixpkgsFor.${system}.cross.${crossSystem}.${pkgName})));

buildNoGc = forAllSystems (system:
self.packages.${system}.nix.override { enableGC = false; }
Expand Down Expand Up @@ -76,7 +80,7 @@ in
binaryTarballCross = lib.genAttrs [ "x86_64-linux" ] (system:
forAllCrossSystems (crossSystem:
binaryTarball
self.packages.${system}."nix-${crossSystem}"
nixpkgsFor.${system}.cross.${crossSystem}.nix
nixpkgsFor.${system}.cross.${crossSystem}));

# The first half of the installation script. This is uploaded
Expand Down
9 changes: 9 additions & 0 deletions meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# This is just a stub project to include all the others as subprojects
# for development shell purposes

project('nix-dev-shell', 'cpp',
version : files('.version'),
subproject_dir : 'src',
)

subproject('libutil')
3 changes: 1 addition & 2 deletions package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -385,8 +385,7 @@ in {

separateDebugInfo = !stdenv.hostPlatform.isStatic;

# TODO `releaseTools.coverageAnalysis` in Nixpkgs needs to be updated
# to work with `strictDeps`.
# TODO Always true after https://github.com/NixOS/nixpkgs/issues/318564
strictDeps = !withCoverageChecks;

hardeningDisable = lib.optional stdenv.hostPlatform.isStatic "pie";
Expand Down
1 change: 1 addition & 0 deletions src/libutil/.version
11 changes: 11 additions & 0 deletions src/libutil/linux/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
sources += files(
'cgroup.cc',
'namespaces.cc',
)

include_dirs += include_directories('.')

headers += files(
'cgroup.hh',
'namespaces.hh',
)
Loading

0 comments on commit 96cf6b0

Please sign in to comment.