Skip to content

Commit

Permalink
Rewrite flake
Browse files Browse the repository at this point in the history
This copies most of the derivation from nixpkgs.  The old override
technique was problematic when development diverged since the last
release and the derivation in nixpkgs was not up to date any longer.
  • Loading branch information
lucc committed May 14, 2024
1 parent f5fe564 commit 878517c
Showing 1 changed file with 38 additions and 15 deletions.
53 changes: 38 additions & 15 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,49 @@
version = head (match ".*version=([0-9.]*)\n.*" (readFile ./nvimpager))
+ "-dev-${toString self.sourceInfo.lastModifiedDate}";
withoutDarwin = filter (s: !nixpkgs.lib.strings.hasSuffix "-darwin" s);
nvimpager = {
stdenv, neovim, ncurses, procps, scdoc, lua51Packages, util-linux
}:
stdenv.mkDerivation {
pname = "nvimpager";
inherit version;

src = self;

buildInputs = [
ncurses # for tput
procps # for nvim_get_proc() which uses ps(1)
];
nativeBuildInputs = [ scdoc ];

makeFlags = [ "PREFIX=$(out)" "VERSION=${version}" ];
buildFlags = [ "nvimpager.configured" "nvimpager.1" ];
preBuild = ''
patchShebangs nvimpager
substituteInPlace nvimpager --replace ':-nvim' ':-${neovim}/bin/nvim'
'';

doCheck = true;
nativeCheckInputs = [ lua51Packages.busted util-linux neovim ];
# filter out one test that fails in the sandbox of nix
preCheck = let
exclude-tags = if stdenv.isDarwin then "nix,mac" else "nix";
in ''
checkFlagsArray+=('BUSTED=busted --output TAP --exclude-tags=${exclude-tags}')
'';
};
in ({
overlays.default = final: prev: {
nvimpager = prev.nvimpager.overrideAttrs (oa: {
inherit version;
src = ./.;
buildFlags = oa.buildFlags ++ [ "VERSION=${version}" ];
checkPhase = ''
runHook preCheck
make test BUSTED='busted --output TAP --exclude-tags=nix'
runHook postCheck
'';
});
nvimpager = final.callPackage nvimpager {};
};
} // (eachSystem (withoutDarwin defaultSystems) (system:
let
stable = import nixpkgs { overlays = [ self.overlays.default ]; inherit system; };
nightly = import nixpkgs { overlays = [ neovim.overlay self.overlays.default ]; inherit system; };
callPackage = (import nixpkgs { inherit system; }).callPackage nvimpager;
neovim-nightly = neovim.packages.${system}.default;
default = callPackage {};
nightly = callPackage { neovim = neovim-nightly; };
in {
apps.default = flake-utils.lib.mkApp { drv = stable.nvimpager; };
packages.default = stable.nvimpager;
packages.nightly = nightly.nvimpager;
apps.default = flake-utils.lib.mkApp { drv = default; };
packages = { inherit default nightly; };
})));
}

0 comments on commit 878517c

Please sign in to comment.