From e16a6e42d69ebc18fd308b8ae9a7cab02064d6a4 Mon Sep 17 00:00:00 2001 From: rnhmjoj Date: Tue, 7 Sep 2021 11:22:43 +0200 Subject: [PATCH] improve release setup - use a build flag to turn on static system libraries - generate shell completion scripts - externalise the generate cabal2nix function --- bisc.cabal | 7 ++++++- default.nix | 45 +++++++++++++++++++-------------------------- 2 files changed, 25 insertions(+), 27 deletions(-) diff --git a/bisc.cabal b/bisc.cabal index 0f36b7f..b43e0d6 100644 --- a/bisc.cabal +++ b/bisc.cabal @@ -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++ diff --git a/default.nix b/default.nix index d965b7b..90b6bde 100644 --- a/default.nix +++ b/default.nix @@ -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