Skip to content

Commit

Permalink
add console helpers for colors and printing to util
Browse files Browse the repository at this point in the history
  • Loading branch information
tek committed Oct 16, 2023
1 parent 4136d65 commit 7acaf2b
Show file tree
Hide file tree
Showing 23 changed files with 78 additions and 51 deletions.
3 changes: 3 additions & 0 deletions lib/console.nix
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,7 @@ in {
colorExt = n: color "48;5;${n}";

chevrons = bold (color colors.magenta ">>>");

chevronY = bold (color colors.yellow ">");
chevronM = bold (color colors.magenta ">");
}
37 changes: 36 additions & 1 deletion lib/default.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ lib }:
{lib}:
with lib;
let

Expand Down Expand Up @@ -125,8 +125,42 @@ let

app = program: { type = "app"; program = "${program}"; };

loadConsole = let
console = import ./console.nix { inherit lib; };
inherit (console) colors color bold chevrons chevronY chevronM;
colorFun = name: ''
${name}()
{
echo -e "${color colors.${name} "\${1}"}"
}
'';
in ''
message()
{
echo -e "${chevrons} $*"
}
error_message()
{
echo -e "${chevrons} ${color colors.red "\${*}"}"
}
${unlines (map colorFun (attrNames colors))}
bold()
{
echo -e "${bold "$1"}"
}
chevrons='${chevrons}'
chevronY='${chevronY}'
chevronM='${chevronM}'
die()
{
error_message $*
exit 1
}
'';

in {
inherit
lib
flake-utils
packageSubpath
relativePackages
Expand Down Expand Up @@ -157,6 +191,7 @@ in {
overridesVia
cabalDepPackage
app
loadConsole
;

ghcOverlay = import ./ghc-overlay.nix;
Expand Down
17 changes: 7 additions & 10 deletions lib/release.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{config, lib, util}: let
{config, util}: let

inherit (config.internal) pkgs;

Expand All @@ -7,22 +7,21 @@
preamble = ''
#!${pkgs.zsh}/bin/zsh
setopt err_exit no_unset pipefail
${util.loadConsole}
if [[ $# == 0 ]]
then
echo 'Error: Please specify version'
exit 1
die 'Please specify version'
fi
version="$1"
if ! ${git} diff --quiet
then
echo 'Error: Worktree is dirty'
exit 1
die 'Worktree is dirty'
fi
ask() {
echo -n ">>> $1 [Yn] "
echo -n "$chevrons $1 [Yn] "
read -q decision || true
echo ""
[[ $decision != 'n' ]]
Expand All @@ -43,8 +42,7 @@
if ! ask 'Versions updated. Continue?'
then
${git} reset --hard
echo ">>> Aborting."
exit 1
die "Aborting."
fi
${git} add .
'';
Expand All @@ -67,8 +65,7 @@
nix run .#release -- -v $version
if ! ask 'Update CLI version in overrides. Continue?'
then
echo ">>> Aborting."
exit 1
die "Aborting."
fi
${git} add modules/cli.nix
${commitAndTag}
Expand Down
7 changes: 2 additions & 5 deletions lib/show-overrides.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,8 @@ let
spec = import ./deps/spec.nix { inherit lib; };
deps = import ./deps/default.nix { inherit pkgs; };
console = import ./console.nix { inherit lib; };
inherit (console) color bold indent chevrons;
inherit (console.colors) magenta blue yellow green;

chevronY = bold (color yellow ">");
chevronM = bold (color magenta ">");
inherit (console) color bold indent chevrons chevronY chevronM;
inherit (console.colors) blue green;

renderSource = concatStringsSep (bold (color green " -> "));

Expand Down
1 change: 1 addition & 0 deletions lib/with-config.nix
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ let

in basic // {
inherit
config
paramApp
types
packageRel
Expand Down
13 changes: 5 additions & 8 deletions local.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

hix.pro [({config, lib, ...}: let
pkgs = config.pkgs;
util = import ./lib/with-config.nix { inherit config lib util; };
release = import ./lib/release.nix { inherit config util; };
in {
compiler = "ghc94";

Expand Down Expand Up @@ -95,8 +97,7 @@ in {
};

apps = let
tests = import ./test/default.nix { inherit (config) pkgs; };
util = import ./lib/with-config.nix { inherit config lib util; };
tests = import ./test/default.nix { inherit util; };
in {

test = {
Expand Down Expand Up @@ -145,16 +146,12 @@ in {
program = "${prog}";
};

release-nix = let
release = import ./lib/release.nix { inherit config lib util; };
in {
release-nix = {
type = "app";
program = "${release.nix}";
};

release-all = let
release = import ./lib/release.nix { inherit config lib util; };
in {
release-all = {
type = "app";
program = "${release.all}";
};
Expand Down
2 changes: 1 addition & 1 deletion test/basic/test.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ pkgs }:
{...}:
{
test = builtins.toFile "basic-test" ''
cd ./root
Expand Down
2 changes: 1 addition & 1 deletion test/bootstrap/test.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{pkgs}:
{pkgs, ...}:
{
test = pkgs.writeText "bootstrap-test" ''
cd ./root
Expand Down
2 changes: 1 addition & 1 deletion test/cross/test.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ pkgs }:
{...}:
{
test = builtins.toFile "cross-test" ''
cd ./root
Expand Down
19 changes: 8 additions & 11 deletions test/default.nix
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{ pkgs, keep ? false, ... }:
with builtins;
with pkgs.lib;
{ util, keep ? false, ... }:
let
test = name: (import (./. + "/${name}/test.nix") { inherit pkgs; }).test;
inherit (util) config lib;
inherit (config) pkgs;

test = name: (import (./. + "/${name}/test.nix") { inherit config util pkgs; }).test;

tests = {
basic = test "basic";
Expand All @@ -27,7 +28,7 @@ let

testA = n: t: "${n} ${t}";

testsA = concatStringsSep " " (mapAttrsToList testA tests);
testsA = lib.concatStringsSep " " (lib.mapAttrsToList testA tests);

ciSkipTests = "ghci-vm service postgres hackage";

Expand All @@ -49,19 +50,15 @@ in {
tmpdir=/tmp/hix-test-temp
if (( $# == 0 ))
then
targets="${toString (attrNames tests)}"
targets="${toString (lib.attrNames tests)}"
else
targets="$@"
fi
typeset -A tests
set -A tests ${testsA}
typeset -a vm_tests
ci_skip_tests=(${ciSkipTests})
message()
{
echo -e ">>> $*"
}
${util.loadConsole}
fail()
{
Expand Down
2 changes: 1 addition & 1 deletion test/deps/test.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ pkgs }:
{pkgs, ...}:
{
test = builtins.toFile "deps-test" ''
cd ./root
Expand Down
2 changes: 1 addition & 1 deletion test/ghci-vm/test.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ pkgs }:
{...}:
{
test = builtins.toFile "ghci-vm-test" ''
cd ./root
Expand Down
2 changes: 1 addition & 1 deletion test/ghci/test.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ pkgs }:
{...}:
{
test = builtins.toFile "ghci-test" ''
cd ./root
Expand Down
2 changes: 1 addition & 1 deletion test/hackage/test.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ pkgs }:
{...}:
let

regular = ''
Expand Down
2 changes: 1 addition & 1 deletion test/local-prelude/test.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ pkgs }:
{...}:
{
test = builtins.toFile "local-prelude-test" ''
cd ./root
Expand Down
2 changes: 1 addition & 1 deletion test/new-static-github/test.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ pkgs }:
{...}:
{
test = builtins.toFile "new-static-github-test" ''
mkdir root
Expand Down
2 changes: 1 addition & 1 deletion test/new-static/test.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ pkgs }:
{...}:
{
test = builtins.toFile "new-static-test" ''
mkdir root
Expand Down
2 changes: 1 addition & 1 deletion test/new/test.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ pkgs }:
{...}:
{
test = builtins.toFile "new-test" ''
mkdir root
Expand Down
2 changes: 1 addition & 1 deletion test/overrides/test.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ pkgs }:
{pkgs, ...}:
with pkgs.lib;
let
inherit (pkgs) lib;
Expand Down
2 changes: 1 addition & 1 deletion test/packages/test.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ pkgs }:
{...}:
let

targetDep = builtins.toFile "cabal-target-dep" ''
Expand Down
2 changes: 1 addition & 1 deletion test/postgres/test.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ pkgs }:
{...}:
{
test = builtins.toFile "postgres-test" ''
cd ./root
Expand Down
2 changes: 1 addition & 1 deletion test/service/test.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ pkgs }:
{...}:
{
test = builtins.toFile "service-test" ''
cd ./root
Expand Down
2 changes: 1 addition & 1 deletion test/subdir/test.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ pkgs }:
{...}:
{
test = builtins.toFile "subdir-test" ''
cd ./root
Expand Down

0 comments on commit 7acaf2b

Please sign in to comment.