Skip to content

Commit

Permalink
run nixfmt-rfc-style on all nix files
Browse files Browse the repository at this point in the history
  • Loading branch information
fidgetingbits committed May 13, 2024
1 parent 92640c7 commit 387092f
Show file tree
Hide file tree
Showing 5 changed files with 236 additions and 197 deletions.
68 changes: 43 additions & 25 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,38 +7,56 @@
inputs.nixpkgs.follows = "nixpkgs";
};

outputs = { self, nixpkgs, poetry2nix }:
outputs =
{
self,
nixpkgs,
poetry2nix,
}:
let
# Self contained packages for: Debian, RHEL-like (yum, rpm), Alpine, Arch packages
forAllSystems = nixpkgs.lib.genAttrs nixpkgs.lib.systems.flakeExposed;
forPortables = nixpkgs.lib.genAttrs [ "deb" "rpm" "apk" "archlinux" ];
forPortables = nixpkgs.lib.genAttrs [
"deb"
"rpm"
"apk"
"archlinux"
];

pkgsBySystem = forAllSystems (system: import nixpkgs {
inherit system;
overlays = [ poetry2nix.overlays.default ];
});
pkgUtil = forAllSystems (system: import ./nix/bundle/pkg.nix {
pkgs = pkgsBySystem.${system};
});
pkgsBySystem = forAllSystems (
system:
import nixpkgs {
inherit system;
overlays = [ poetry2nix.overlays.default ];
}
);
pkgUtil = forAllSystems (system: import ./nix/bundle/pkg.nix { pkgs = pkgsBySystem.${system}; });

portableDrv = system: import ./nix/portable.nix {
pkgs = pkgsBySystem.${system};
pwndbg = self.packages.${system}.pwndbg;
};
portableDrvs = system: forPortables (packager: pkgUtil.${system}.buildPackagePFPM {
inherit packager;
drv = portableDrv system;
config = ./nix/bundle/nfpm.yaml;
preremove = ./nix/bundle/preremove.sh;
});
tarballDrv = system: {
tarball = pkgUtil.${system}.buildPackageTarball {
drv = portableDrv system;
portableDrv =
system:
import ./nix/portable.nix {
pkgs = pkgsBySystem.${system};
pwndbg = self.packages.${system}.pwndbg;
};
portableDrvs =
system:
forPortables (
packager:
pkgUtil.${system}.buildPackagePFPM {
inherit packager;
drv = portableDrv system;
config = ./nix/bundle/nfpm.yaml;
preremove = ./nix/bundle/preremove.sh;
}
);
tarballDrv = system: {
tarball = pkgUtil.${system}.buildPackageTarball { drv = portableDrv system; };
};
in
{
packages = forAllSystems (system: {
{
packages = forAllSystems (
system:
{
pwndbg = import ./nix/pwndbg.nix {
pkgs = pkgsBySystem.${system};
python3 = pkgsBySystem.${system}.python3;
Expand All @@ -50,5 +68,5 @@
// (portableDrvs system)
// (tarballDrv system)
);
};
};
}
59 changes: 32 additions & 27 deletions nix/bundle/default.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{ pkgs
, bin_dir ? "bin"
, exe_dir ? "exe"
, lib_dir ? if pkgs.stdenv.isDarwin then "Frameworks/Library.dylib" else "lib"
{
pkgs,
bin_dir ? "bin",
exe_dir ? "exe",
lib_dir ? if pkgs.stdenv.isDarwin then "Frameworks/Library.dylib" else "lib",
}:
path:
# Original file copied from https://github.com/3noch/nix-bundle-exe
Expand All @@ -11,23 +12,26 @@ path:
# 2) a path to a directory containing bin/, or
# 3) a path to an executable.
let
print-needed-elf = pkgs.writeScriptBin
"print-needed-elf"
'''${pkgs.python3}'/bin/python ${./print_needed_elf.py} "$@"'';
print-needed-elf = pkgs.writeScriptBin "print-needed-elf" '''${pkgs.python3}'/bin/python ${./print_needed_elf.py} "$@"'';
relative-path = pkgs.writeScriptBin
"relative-path"
'''${pkgs.python3}'/bin/python ${./relative-path.py} "$@"'';
relative-path = pkgs.writeScriptBin "relative-path" '''${pkgs.python3}'/bin/python ${./relative-path.py} "$@"'';

cfg =
if pkgs.stdenv.isDarwin then
{
deps = with pkgs; [ darwin.binutils darwin.sigtool ];
deps = with pkgs; [
darwin.binutils
darwin.sigtool
];
script = "bash ${./bundle-macos.sh}";
}
else if pkgs.stdenv.isLinux then
{
deps = [ pkgs.glibc print-needed-elf relative-path ];
deps = [
pkgs.glibc
print-needed-elf
relative-path
];
script = "bash ${./bundle-linux.sh}";
}
else
Expand All @@ -36,19 +40,20 @@ let
name = if pkgs.lib.isDerivation path then path.name else builtins.baseNameOf path;
overrideEnv = name: value: if value == null then "" else "export ${name}='${value}'";
in
pkgs.runCommand "bundle-${name}"
{
nativeBuildInputs = cfg.deps ++ [ pkgs.nukeReferences ];
pkgs.runCommand "bundle-${name}" { nativeBuildInputs = cfg.deps ++ [ pkgs.nukeReferences ]; } ''
set -euo pipefail
export bin_dir='${bin_dir}'
export exe_dir='${exe_dir}'
export lib_dir='${lib_dir}'
${
if builtins.pathExists "${path}/bin" then
''
find '${path}/bin' -type f -executable -print0 | xargs -0 --max-args 1 ${cfg.script} "$out"
''
else
''
${cfg.script} "$out" ${pkgs.lib.escapeShellArg path}
''
}
''
set -euo pipefail
export bin_dir='${bin_dir}'
export exe_dir='${exe_dir}'
export lib_dir='${lib_dir}'
${if builtins.pathExists "${path}/bin" then ''
find '${path}/bin' -type f -executable -print0 | xargs -0 --max-args 1 ${cfg.script} "$out"
'' else ''
${cfg.script} "$out" ${pkgs.lib.escapeShellArg path}
''}
find $out -empty -type d -delete
''
find $out -empty -type d -delete
''
113 changes: 61 additions & 52 deletions nix/bundle/pkg.nix
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
pkgs ? import <nixpkgs> {}
pkgs ? import <nixpkgs> { },
}:
let
pfpmArchs = {
Expand All @@ -12,64 +12,73 @@ let
"riscv64-linux" = "riscv64";
};

buildPackagePFPM = {
drv ? null
, config ? "nfpm.yaml"
, packager ? null # apk|deb|rpm|archlinux
, preremove ? null
, ...
}@attrs: pkgs.stdenv.mkDerivation {
name = "nfpm-${packager}-${drv.name}";
buildInputs = [ pkgs.nfpm ];
buildPackagePFPM =
{
drv ? null,
config ? "nfpm.yaml",
packager ? null, # apk|deb|rpm|archlinux
preremove ? null,
...
}@attrs:
pkgs.stdenv.mkDerivation {
name = "nfpm-${packager}-${drv.name}";
buildInputs = [ pkgs.nfpm ];

unpackPhase = "true";
unpackPhase = "true";

buildPhase = (pkgs.lib.optionalString (preremove != null) ''
cp ${preremove} preremove.sh
'') + ''
mkdir -p ./dist
ln -s ${drv} ./result
export VERSION=${drv.meta.version}
export ARCH=${pfpmArchs.${drv.meta.architecture}}
nfpm pkg --config ${config} --packager ${packager} --target ./dist
'';
buildPhase =
(pkgs.lib.optionalString (preremove != null) ''
cp ${preremove} preremove.sh
'')
+ ''
mkdir -p ./dist
ln -s ${drv} ./result
export VERSION=${drv.meta.version}
export ARCH=${pfpmArchs.${drv.meta.architecture}}
nfpm pkg --config ${config} --packager ${packager} --target ./dist
'';

installPhase = ''
mkdir -p $out
cp -r ./dist/* $out
'';
};
installPhase = ''
mkdir -p $out
cp -r ./dist/* $out
'';
};

buildPackageTarball = {
drv ? null
, ...
}@attrs: pkgs.stdenv.mkDerivation {
name = "tarball-${drv.name}";
buildInputs = [ pkgs.gnutar ];
buildPackageTarball =
{
drv ? null,
...
}@attrs:
pkgs.stdenv.mkDerivation {
name = "tarball-${drv.name}";
buildInputs = [ pkgs.gnutar ];

unpackPhase = "true";
unpackPhase = "true";

buildPhase = ''
mkdir -p ./dist
ln -s ${drv} ./result
export DIST_TAR=$PWD/dist/${drv.meta.name}_${drv.meta.version}_${pfpmArchs.${drv.meta.architecture}}.tar.gz
buildPhase = ''
mkdir -p ./dist
ln -s ${drv} ./result
export DIST_TAR=$PWD/dist/${drv.meta.name}_${drv.meta.version}_${
pfpmArchs.${drv.meta.architecture}
}.tar.gz
pushd ./result
chmod +x bin/* || true
chmod +x lib/ld-* || true
tar cvfJ $DIST_TAR \
--owner=0 --group=0 --mode=u+rw,uga+r \
--mtime='1970-01-01' \
.
popd
'';
pushd ./result
chmod +x bin/* || true
chmod +x lib/ld-* || true
tar cvfJ $DIST_TAR \
--owner=0 --group=0 --mode=u+rw,uga+r \
--mtime='1970-01-01' \
.
popd
'';

installPhase = ''
mkdir -p $out
cp -r ./dist/* $out
'';
};
in {
installPhase = ''
mkdir -p $out
cp -r ./dist/* $out
'';
};
in
{
buildPackagePFPM = buildPackagePFPM;
buildPackageTarball = buildPackageTarball;
}
}
Loading

0 comments on commit 387092f

Please sign in to comment.