Get more tests working; make Nix build work

This commit is contained in:
Andrew Dunham 2021-07-19 21:13:18 -04:00
parent 86fa81c411
commit 91d2808bfb
4 changed files with 134 additions and 71 deletions

105
flake.nix
View file

@ -6,8 +6,77 @@
outputs = { self, nixpkgs, flake-utils }:
flake-utils.lib.eachSystem [ "x86_64-linux" ] (system:
let pkgs = nixpkgs.legacyPackages.${system}; in
rec {
let
pkgs = nixpkgs.legacyPackages.${system};
inherit (pkgs) stdenv lib;
in rec {
defaultPackage = self.packages."${system}".apply;
packages.apply = stdenv.mkDerivation {
pname = "apply";
version = "2021-07-16";
src = ./.;
nativeBuildInputs = with pkgs; [ makeWrapper ];
# Overridden in tests
doCheck = false;
checkInputs = with pkgs; [
shellcheck
gnumake
bash
dash
ksh
# busybox as an input will break things
];
# Test with each shell
checkPhase = ''
cd "$src"
make test
(
export PATH="${lib.makeBinPath (with pkgs; [ busybox gnumake shellcheck ])}"
make test-ash
)
'';
# Don't patch shebangs on everything or it'll get the 'lib' and 'run'
# scripts, which we need to be able to copy elsewhere.
dontPatchShebangs = true;
installPhase = ''
mkdir -p $out/bin/
cp ./{apply,lib,push,run} $out/bin/
chmod +x $out/bin/*
'';
postFixup = ''
for f in $out/bin/{apply,push}; do
patchShebangs "$f"
wrapProgram "$f" \
--suffix PATH ":" "${lib.makeBinPath (with pkgs; [ coreutils parallel openssh ])}"
done
'';
meta = with lib; {
homepage = "https://github.com/andrew-d/apply";
description = "TODO";
maintainers = with maintainers; [ andrew-d ];
license = licenses.bsd3;
platforms = platforms.unix;
};
};
defaultApp = self.apps."${system}".apply;
apps.apply = {
type = "app";
program = "${self.defaultPackage."${system}"}/bin/apply";
};
devShell = pkgs.mkShell {
buildInputs = with pkgs; [
# Shells
@ -21,36 +90,8 @@
];
};
checks = let
commonDeps = with pkgs; [ gnumake shellcheck ];
in {
bash = pkgs.runCommand "lint" {
src = ./.;
nativeBuildInputs = commonDeps ++ (with pkgs; [ bash ]);
} ''
export SHELL="${pkgs.bash}/bin/bash"
make -C "$src" test-bash
touch "$out"
'';
dash = pkgs.runCommand "lint" {
src = ./.;
nativeBuildInputs = commonDeps ++ (with pkgs; [ dash ]);
} ''
export SHELL="${pkgs.dash}/bin/dash"
make -C "$src" test-dash
touch "$out"
'';
busybox = pkgs.runCommand "lint" {
src = ./.;
nativeBuildInputs = commonDeps ++ (with pkgs; [ busybox ]);
} ''
export SHELL="${pkgs.busybox}/bin/ash"
make -C "$src" test-ash
touch "$out"
'';
checks = {
apply = self.defaultPackage.${system}.overrideAttrs (super: { doCheck = true; });
};
}
);