Skip to content

Commit

Permalink
Prepare 1.0.0 release
Browse files Browse the repository at this point in the history
- Add ‘custom-sdist’ script in nix-shell configuration that prepares ‘README.md’
  file for being published on Hackage, calls ‘hpack’ to make sure Cabal config
  is up-to-date and then calls ‘cabal sdist’
- Update version to 1.0.0 in project Cabal config file
- Add more metadata to Cabal config file
- Remove -O2 flag from GHC options as recommended by Hackage’s RC uploader
- Wrap ‘hpack’, ‘cabal’ and ‘stack’ Haskell packages to ‘justStaticExecutables’
  in ‘shell.nix’ configuration
  • Loading branch information
unclechu committed Mar 20, 2021
1 parent be365c6 commit b636cb9
Show file tree
Hide file tree
Showing 4 changed files with 175 additions and 13 deletions.
135 changes: 135 additions & 0 deletions nix/custom-sdist-script.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
let sources = import nix/sources.nix; in
# This module is intended to be called with ‘nixpkgs.callPackage’
{ callPackage
, haskellPackages
, haskell
, coreutils
, utillinux

# Overridable dependencies
, __nix-utils ? callPackage sources.nix-utils {}
}:
let
inherit (__nix-utils) esc writeCheckedExecutable shellCheckers;
inherit (haskell.lib) justStaticExecutables;
hp = haskellPackages;

# Shortcuts for executables that are already escaped for Bash
c = builtins.mapAttrs (n: v: esc v) executables;

assetsCommit = "be365c601ad94a108967701c70042b994d7dd3f3";

staticAssetUrl = filePath:
"https://raw.githubusercontent.com/unclechu/place-cursor-at/" +
"${assetsCommit}/${filePath}";

gitHubUrl = filePath:
"https://github.com/unclechu/place-cursor-at/blob/" +
"${assetsCommit}/${filePath}";

executables =
builtins.foldl'
(acc: x: acc // { ${x} = "${coreutils}/bin/${x}"; })
{
hpack = "${justStaticExecutables hp.hpack}/bin/hpack";
cabal = "${justStaticExecutables hp.cabal-install}/bin/cabal";
column = "${utillinux}/bin/column";
}
[ "cp" "mv" "mktemp" "basename" ];
in

# Script that prepares ‘README.md’ file for being published on Hackage.
# It replaces relative links to some files in the repo to links to GitHub static
# content links relative to specific commit (so that content stays the same).
writeCheckedExecutable "custom-sdist" ''
${
builtins.concatStringsSep "\n"
(builtins.map shellCheckers.fileIsExecutable
(builtins.attrValues executables))
}
'' ''
set -Eeuxo pipefail || exit
# Generate fresh ‘*.cabal’ file from ‘package.yaml’
${c.hpack}
TMP_FILE_PATH=$(${c.mktemp} -ut 'README.md.bakXXXXXX')
README_BAK_FILE_NAME=$(${c.basename} -- "$TMP_FILE_PATH")
# Make a backup of ‘README.md’ before patching it
${c.cp} README.md -- "$README_BAK_FILE_NAME"
readarray -t LINES < README.md
# Restore original ‘README.md’ from backup file
restore-readme-backup() {
set -Eeuxo pipefail || exit
${c.mv} -f -- "$README_BAK_FILE_NAME" README.md
}
# Encapsulate ‘trap’
(
trap restore-readme-backup EXIT
> README.md # Empty the file first
table=
# Encapsulate stdout redirect and ‘set’
(
exec >> README.md # Redirect stdout to the README file
set +x # Too much noise
for line in "''${LINES[@]}"; do
# End of table, fix the table for Hackage and print it
if [[ -n $table ]] && ! [[ $line =~ ^\| ]]; then
echo '```'
table=''${table//'`'/}
table=''${table//'*'/}
table=$(${c.column} -t -o ' ' <<< "$table")
printf '%s\n' "$table"
echo '```'
table=
continue
# Save table into a variable
elif [[ $line =~ ^\| ]]; then
table="$table$line"$'\n'
continue
fi
line=''${line//'(artwork/screenshot.png)'/(${
esc (staticAssetUrl "artwork/screenshot.png")
})}
line=''${line//'(artwork/logo/horizontal.svg)'/(${
esc (staticAssetUrl "artwork/logo/horizontal.svg")
})}
line=''${line//'(artwork/logo/horizontal.png)'/(${
esc (staticAssetUrl "artwork/logo/horizontal.png")
})}
line=''${line//'(artwork/logo/vertical.svg)'/(${
esc (staticAssetUrl "artwork/logo/vertical.svg")
})}
line=''${line//'(artwork/logo/vertical.png)'/(${
esc (staticAssetUrl "artwork/logo/vertical.png")
})}
line=''${line//'(artwork/logo/icon.svg)'/(${
esc (staticAssetUrl "artwork/logo/icon.svg")
})}
line=''${line//'(artwork/logo/icon.png)'/(${
esc (staticAssetUrl "artwork/logo/icon.png")
})}
line=''${line//'(LICENSE)'/(${esc (staticAssetUrl "LICENSE")})}
line=''${line//': shell.nix'/: ${esc (gitHubUrl "shell.nix")}}
line=''${line//': artwork/logo'/: ${esc (gitHubUrl "artwork/logo")}}
printf '%s\n' "$line"
done
)
${c.cabal} sdist
)
''
13 changes: 10 additions & 3 deletions package.yaml
Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@
name: place-cursor-at
synopsis: A utility for X11 that moves the mouse cursor using the keyboard
version: 1.0.0
license: GPL-3
license-file: LICENSE
author: Viacheslav Lotsmanov
maintainer: <[email protected]>
category: System
copyright: Copyright © 2017–2021 Viacheslav Lotsmanov
maintainer: Viacheslav Lotsmanov <[email protected]>
category: Utility, GUI, Desktop, Desktop Environment, X11
github: unclechu/place-cursor-at

extra-source-files: README.md

tested-with: GHC ==8.10.4 || ==8.8.4 || ==8.6.4

dependencies:
- base >= 4.12 && < 5
- base-unicode-symbols ^>= 0.2
- X11 >= 1.9 && < 2

ghc-options:
- -O2
- -threaded

extra-libraries:
Expand Down
23 changes: 17 additions & 6 deletions place-cursor-at.cabal
Original file line number Diff line number Diff line change
@@ -1,25 +1,36 @@
cabal-version: 1.12

-- This file has been generated from package.yaml by hpack version 0.33.0.
-- This file has been generated from package.yaml by hpack version 0.34.2.
--
-- see: https://github.com/sol/hpack
--
-- hash: c1b0beb883ff043c4ac58f466cef84ebb5ce6669706a4a0a44334c7bca6acab4
-- hash: 66d39f7b6b91273a09289c622d5c81b8bb6f010ee69d032997ed77412a1f96f5

name: place-cursor-at
version: 0.0.0
category: System
version: 1.0.0
synopsis: A utility for X11 that moves the mouse cursor using the keyboard
category: Utility, GUI, Desktop, Desktop Environment, X11
homepage: https://github.com/unclechu/place-cursor-at#readme
bug-reports: https://github.com/unclechu/place-cursor-at/issues
author: Viacheslav Lotsmanov
maintainer: <[email protected]>
maintainer: Viacheslav Lotsmanov <[email protected]>
copyright: Copyright © 2017–2021 Viacheslav Lotsmanov
license: GPL-3
license-file: LICENSE
tested-with: GHC ==8.10.4 || ==8.8.4 || ==8.6.4
build-type: Simple
extra-source-files:
README.md

source-repository head
type: git
location: https://github.com/unclechu/place-cursor-at

executable place-cursor-at
main-is: place-cursor-at.hs
hs-source-dirs:
src
ghc-options: -O2 -threaded
ghc-options: -threaded
extra-libraries:
Xinerama
build-depends:
Expand Down
17 changes: 13 additions & 4 deletions shell.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Author: Viacheslav Lotsmanov
# License: GNU/GPLv3 https://raw.githubusercontent.com/unclechu/place-cursor-at/master/LICENSE

# In order to generate ‘cabal sdist’ bundle for Hackage just run:
# nix-shell --arg withCustomSdistScript true --run custom-sdist

let sources = import nix/sources.nix; in
args@
{ pkgs ?
Expand All @@ -20,6 +23,8 @@ args@

# Overridable local dependencies
, nix-utils ? pkgs.callPackage sources.nix-utils {}
, custom-sdist-script ?
pkgs.callPackage nix/custom-sdist-script.nix { __nix-utils = nix-utils; }

# Local arguments
, withCabal ? false
Expand All @@ -28,6 +33,7 @@ args@
, withStackNixDependencies ? false
, withPackageRepl ? false # Adds package library modules into GHCi REPL
, withHoogle ? true
, withCustomSdistScript ? false
, buildExecutable ? true
}:
let
Expand Down Expand Up @@ -83,6 +89,8 @@ let
map attrPathToDerivation attrPaths;

hpack = pkgs.haskell.lib.justStaticExecutables hp.hpack;
cabal = pkgs.haskell.lib.justStaticExecutables hp.cabal-install;
stack = pkgs.haskell.lib.justStaticExecutables hp.stack;
in
hp.shellFor {
packages = p: [
Expand All @@ -92,10 +100,11 @@ hp.shellFor {
inherit withHoogle;

buildInputs =
(if withCabal then [ hp.cabal-install ] else []) ++
(if withCabal then [ cabal ] else []) ++
(if withHpack then [ hpack ] else []) ++
(if withStack then [ hp.stack ] else []) ++
(if withStack then [ stack ] else []) ++
(if withStackNixDependencies then stackNixDependencies else []) ++
(if buildExecutable then [ hp.${name} ] else []) ++
(if withPackageRepl then pkgRepl else []);
(if withPackageRepl then pkgRepl else []) ++
(if withCustomSdistScript then [ custom-sdist-script ] else []) ++
(if buildExecutable then [ hp.${name} ] else []);
}

0 comments on commit b636cb9

Please sign in to comment.