improve release setup

- use a build flag to turn on static system libraries
- generate shell completion scripts
- externalise the generate cabal2nix function
master
Michele Guerini Rocco 2021-09-07 11:22:43 +02:00
parent 2fcb4eae1e
commit e16a6e42d6
Signed by: rnhmjoj
GPG Key ID: BFBAF4C975F76450
2 changed files with 25 additions and 27 deletions

View File

@ -29,6 +29,10 @@ source-repository head
type: git
location: https://maxwell.ydns.eu/git/rnhmjoj/bisc
flag static
default: False
description: Create a statically-linked binary
executable bisc
main-is: Main.hs
build-depends: base ==4.* , selda ==0.*,
@ -40,4 +44,5 @@ executable bisc
optparse-applicative
default-language: Haskell2010
ghc-options: -Wall
extra-libraries: snappy stdc++
if flag(static)
extra-libraries: snappy stdc++

View File

@ -10,38 +10,31 @@ let
basepkgs = import nixpkgs { inherit system; };
pkgs = if static then basepkgs.pkgsStatic else basepkgs.pkgs;
f = { mkDerivation, base, bytestring, configurator, data-default
, directory, exceptions, filepath, leveldb-haskell, mtl, selda
, selda-sqlite, lib, text, optparse-applicative
}:
mkDerivation {
pname = "bisc";
version = "0.3.0.0";
src = ./.;
isLibrary = false;
isExecutable = true;
executableHaskellDepends = [
base bytestring configurator data-default directory exceptions
filepath leveldb-haskell mtl selda selda-sqlite text
optparse-applicative
];
executableSystemDepends = [ pkgs.snappy ];
buildFlags = lib.optionals static [
"--ld-option=-lstdc++"
"--ld-option=-lsnappy"
];
homepage = "https://maxwell.ydns.eu/git/rnhmjoj/bisc";
description = "A small tool that clears cookies (and more)";
license = lib.licenses.gpl3;
};
ghc = if static then pkgs.haskell.packages.integer-simple.ghc8104
else if compiler == "default" then pkgs.haskellPackages
else pkgs.haskell.packages.${compiler};
variant = if doBenchmark then pkgs.haskell.lib.doBenchmark else pkgs.lib.id;
drv = variant (ghc.callPackage f {});
drv = variant (override (ghc.callPackage ./bisc.nix {}));
override = drv: pkgs.haskell.lib.overrideCabal drv (old: with pkgs.lib; {
buildTools = [ pkgs.installShellFiles ];
configureFlags = optional static "-f static";
buildFlags = optionals static [
"--ld-option=-lstdc++"
"--ld-option=-lsnappy"
];
postInstall = ''
# generate completion
$out/bin/bisc --bash-completion-script "$out/bin/bisc" > bisc.bash
$out/bin/bisc --fish-completion-script "$out/bin/bisc" > bisc.fish
$out/bin/bisc --zsh-completion-script "$out/bin/bisc" > bisc.zsh
installShellCompletion bisc.{bash,fish,zsh}
'';
postFixup = optionalString static "rm -r $out/nix-support";
});
in