Skip to content

Format Nix code #602

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

Merged
merged 2 commits into from
Aug 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Manual nixfmt run
706478750fc8574ed816ef746d3ad3790b2ea66a
2 changes: 1 addition & 1 deletion default.nix
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
(import (fetchTarball https://github.com/edolstra/flake-compat/archive/master.tar.gz) {
(import (fetchTarball "https://github.com/edolstra/flake-compat/archive/master.tar.gz") {
src = ./.;
}).defaultNix
193 changes: 109 additions & 84 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,29 @@

inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";

outputs = { self, nixpkgs }:
outputs =
{ self, nixpkgs }:

let
supportedSystems = [ "x86_64-linux" "i686-linux" "aarch64-linux" ];
supportedSystems = [
"x86_64-linux"
"i686-linux"
"aarch64-linux"
];
forAllSystems = nixpkgs.lib.genAttrs supportedSystems;

version = nixpkgs.lib.removeSuffix "\n" (builtins.readFile ./version);
pkgs = nixpkgs.legacyPackages.x86_64-linux;


patchelfFor = pkgs: let
# this is only
in pkgs.callPackage ./patchelf.nix {
inherit version;
src = self;
};
patchelfFor =
pkgs:
let
# this is only
in
pkgs.callPackage ./patchelf.nix {
inherit version;
src = self;
};

in

Expand All @@ -29,101 +36,119 @@
};

hydraJobs = {
tarball =
pkgs.releaseTools.sourceTarball rec {
name = "patchelf-tarball";
inherit version;
versionSuffix = ""; # obsolete
src = self;
preAutoconf = "echo ${version} > version";

# portable configure shouldn't have a shebang pointing to the nix store
postConfigure = ''
sed -i '1s|^.*$|#!/bin/sh|' ./configure
'';
postDist = ''
cp README.md $out/
echo "doc readme $out/README.md" >> $out/nix-support/hydra-build-products
'';
};
tarball = pkgs.releaseTools.sourceTarball rec {
name = "patchelf-tarball";
inherit version;
versionSuffix = ""; # obsolete
src = self;
preAutoconf = "echo ${version} > version";

# portable configure shouldn't have a shebang pointing to the nix store
postConfigure = ''
sed -i '1s|^.*$|#!/bin/sh|' ./configure
'';
postDist = ''
cp README.md $out/
echo "doc readme $out/README.md" >> $out/nix-support/hydra-build-products
'';
};

coverage =
(pkgs.releaseTools.coverageAnalysis {
name = "patchelf-coverage";
src = self.hydraJobs.tarball;
lcovFilter = ["*/tests/*"];
}).overrideAttrs (old: {
preCheck = ''
# coverage cflag breaks this target
NIX_CFLAGS_COMPILE=''${NIX_CFLAGS_COMPILE//--coverage} make -C tests phdr-corruption.so
'';
});
lcovFilter = [ "*/tests/*" ];
}).overrideAttrs
(old: {
preCheck = ''
# coverage cflag breaks this target
NIX_CFLAGS_COMPILE=''${NIX_CFLAGS_COMPILE//--coverage} make -C tests phdr-corruption.so
'';
});

build = forAllSystems (system: self.packages.${system}.patchelf);
build-sanitized = forAllSystems (system: self.packages.${system}.patchelf.overrideAttrs (old: {
configureFlags = [ "--with-asan " "--with-ubsan" ];
# -Wno-unused-command-line-argument is for clang, which does not like
# our cc wrapper arguments
CFLAGS = "-Werror -Wno-unused-command-line-argument";
}));
build-sanitized = forAllSystems (
system:
self.packages.${system}.patchelf.overrideAttrs (old: {
configureFlags = [
"--with-asan "
"--with-ubsan"
];
# -Wno-unused-command-line-argument is for clang, which does not like
# our cc wrapper arguments
CFLAGS = "-Werror -Wno-unused-command-line-argument";
})
);

# x86_64-linux seems to be only working clangStdenv at the moment
build-sanitized-clang = nixpkgs.lib.genAttrs [ "x86_64-linux" ] (system: self.hydraJobs.build-sanitized.${system}.override {
stdenv = nixpkgs.legacyPackages.${system}.llvmPackages_latest.libcxxStdenv;
});
build-sanitized-clang = nixpkgs.lib.genAttrs [ "x86_64-linux" ] (
system:
self.hydraJobs.build-sanitized.${system}.override {
stdenv = nixpkgs.legacyPackages.${system}.llvmPackages_latest.libcxxStdenv;
}
);

# To get mingw compiler from hydra cache
inherit (self.packages.x86_64-linux) patchelf-win32 patchelf-win64;

release = pkgs.releaseTools.aggregate
{ name = "patchelf-${self.hydraJobs.tarball.version}";
constituents =
[ self.hydraJobs.tarball
self.hydraJobs.build.x86_64-linux
self.hydraJobs.build.i686-linux
# FIXME: add aarch64 emulation to our github action...
#self.hydraJobs.build.aarch64-linux
self.hydraJobs.build-sanitized.x86_64-linux
#self.hydraJobs.build-sanitized.aarch64-linux
self.hydraJobs.build-sanitized.i686-linux
self.hydraJobs.build-sanitized-clang.x86_64-linux
];
meta.description = "Release-critical builds";
};
release = pkgs.releaseTools.aggregate {
name = "patchelf-${self.hydraJobs.tarball.version}";
constituents = [
self.hydraJobs.tarball
self.hydraJobs.build.x86_64-linux
self.hydraJobs.build.i686-linux
# FIXME: add aarch64 emulation to our github action...
#self.hydraJobs.build.aarch64-linux
self.hydraJobs.build-sanitized.x86_64-linux
#self.hydraJobs.build-sanitized.aarch64-linux
self.hydraJobs.build-sanitized.i686-linux
self.hydraJobs.build-sanitized-clang.x86_64-linux
];
meta.description = "Release-critical builds";
};

};

checks = forAllSystems (system: {
build = self.hydraJobs.build.${system};
});

devShells = forAllSystems (system: {
glibc = self.packages.${system}.patchelf;
default = self.devShells.${system}.glibc;
} // nixpkgs.lib.optionalAttrs (system != "i686-linux") {
musl = self.packages.${system}.patchelf-musl;
});

packages = forAllSystems (system: let
pkgs = nixpkgs.legacyPackages.${system};
in {
patchelf = patchelfFor pkgs;
default = self.packages.${system}.patchelf;

# This is a good test to see if packages can be cross-compiled. It also
# tests if our testsuite uses target-prefixed executable names.
patchelf-musl-cross = patchelfFor pkgs.pkgsCross.musl64;
patchelf-netbsd-cross = patchelfFor pkgs.pkgsCross.x86_64-netbsd;

patchelf-win32 = (patchelfFor pkgs.pkgsCross.mingw32).overrideAttrs (old: {
NIX_CFLAGS_COMPILE = "-static";
});
patchelf-win64 = (patchelfFor pkgs.pkgsCross.mingwW64).overrideAttrs (old: {
NIX_CFLAGS_COMPILE = "-static";
});
} // nixpkgs.lib.optionalAttrs (system != "i686-linux") {
patchelf-musl = patchelfFor nixpkgs.legacyPackages.${system}.pkgsMusl;
});
devShells = forAllSystems (
system:
{
glibc = self.packages.${system}.patchelf;
default = self.devShells.${system}.glibc;
}
// nixpkgs.lib.optionalAttrs (system != "i686-linux") {
musl = self.packages.${system}.patchelf-musl;
}
);

packages = forAllSystems (
system:
let
pkgs = nixpkgs.legacyPackages.${system};
in
{
patchelf = patchelfFor pkgs;
default = self.packages.${system}.patchelf;

# This is a good test to see if packages can be cross-compiled. It also
# tests if our testsuite uses target-prefixed executable names.
patchelf-musl-cross = patchelfFor pkgs.pkgsCross.musl64;
patchelf-netbsd-cross = patchelfFor pkgs.pkgsCross.x86_64-netbsd;

patchelf-win32 = (patchelfFor pkgs.pkgsCross.mingw32).overrideAttrs (old: {
NIX_CFLAGS_COMPILE = "-static";
});
patchelf-win64 = (patchelfFor pkgs.pkgsCross.mingwW64).overrideAttrs (old: {
NIX_CFLAGS_COMPILE = "-static";
});
}
// nixpkgs.lib.optionalAttrs (system != "i686-linux") {
patchelf-musl = patchelfFor nixpkgs.legacyPackages.${system}.pkgsMusl;
}
);

};
}
29 changes: 18 additions & 11 deletions patchelf.nix
Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@
{ stdenv, buildPackages, autoreconfHook, version, src, overrideCC }:
{
stdenv,
buildPackages,
autoreconfHook,
version,
src,
overrideCC,
}:
let
# on windows we use win32 threads to get a fully static binary
gcc = buildPackages.wrapCC (buildPackages.gcc-unwrapped.override ({
threadsCross = {
model = "win32";
package = null;
};
}));
gcc = buildPackages.wrapCC (
buildPackages.gcc-unwrapped.override ({
threadsCross = {
model = "win32";
package = null;
};
})
);

stdenv' = if (stdenv.cc.isGNU && stdenv.targetPlatform.isWindows) then
overrideCC stdenv gcc
else
stdenv;
stdenv' =
if (stdenv.cc.isGNU && stdenv.targetPlatform.isWindows) then overrideCC stdenv gcc else stdenv;
in
stdenv'.mkDerivation {
pname = "patchelf";
Expand Down
Loading