2019-02-03 16:07:42 +03:00
|
|
|
{ pkgs ? import ./nix {} }:
|
2019-04-05 12:43:57 +03:00
|
|
|
with rec
|
2019-04-14 15:49:13 +03:00
|
|
|
{ files = pkgs.callPackage ./nix/files.nix {};
|
2019-05-09 13:43:00 +03:00
|
|
|
sourceByRegex = name: src: regexes:
|
|
|
|
builtins.path
|
|
|
|
{ filter = (path: type:
|
|
|
|
let
|
|
|
|
relPath = pkgs.lib.removePrefix (toString src + "/") (toString path);
|
|
|
|
accept = pkgs.lib.any (re: builtins.match re relPath != null) regexes;
|
|
|
|
in accept);
|
|
|
|
inherit name;
|
|
|
|
path = src;
|
|
|
|
};
|
|
|
|
niv-source = sourceByRegex "niv" ./.
|
2019-04-05 12:43:57 +03:00
|
|
|
[ "^package.yaml$"
|
2019-06-13 12:30:13 +03:00
|
|
|
"^README.md$"
|
|
|
|
"^LICENSE$"
|
2019-05-09 13:43:00 +03:00
|
|
|
"^app$"
|
|
|
|
"^app.*.hs$"
|
2019-06-09 23:42:35 +03:00
|
|
|
"^src$"
|
|
|
|
"^src/Niv$"
|
|
|
|
"^src/Niv/GitHub$"
|
|
|
|
"^src/Niv/Update$"
|
|
|
|
"^src.*.hs$"
|
2019-04-05 12:43:57 +03:00
|
|
|
"^README.md$"
|
2019-05-09 13:43:00 +03:00
|
|
|
"^nix$"
|
2019-04-07 20:56:58 +03:00
|
|
|
"^nix.sources.nix$"
|
2019-04-05 12:43:57 +03:00
|
|
|
];
|
2019-06-13 12:30:13 +03:00
|
|
|
|
2019-04-05 12:43:57 +03:00
|
|
|
haskellPackages = pkgs.haskellPackages.override
|
|
|
|
{ overrides = _: haskellPackages:
|
|
|
|
{ niv = haskellPackages.callCabal2nix "niv" niv-source {}; };
|
|
|
|
};
|
|
|
|
|
2019-06-13 12:30:13 +03:00
|
|
|
niv = haskellPackages.niv;
|
|
|
|
|
|
|
|
niv-sdist = pkgs.haskell.lib.sdistTarball niv;
|
|
|
|
|
|
|
|
niv-cabal-upload =
|
|
|
|
with
|
|
|
|
{ niv-version = niv.version;
|
|
|
|
};
|
|
|
|
pkgs.writeScript "cabal-upload"
|
|
|
|
''
|
|
|
|
cabal upload "$@" "${niv-sdist}/niv-${niv-version}.tar.gz"
|
|
|
|
'';
|
|
|
|
|
2019-04-05 12:43:57 +03:00
|
|
|
niv-devshell = haskellPackages.shellFor
|
|
|
|
{ packages = (ps: [ ps.niv ]);
|
|
|
|
shellHook =
|
|
|
|
''
|
|
|
|
repl() {
|
2019-06-09 23:42:35 +03:00
|
|
|
shopt -s globstar
|
2019-06-12 16:58:10 +03:00
|
|
|
ghci -Wall app/NivTest.hs src/**/*.hs
|
2019-04-05 12:43:57 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
echo "To start a REPL session, run:"
|
|
|
|
echo " > repl"
|
|
|
|
'';
|
|
|
|
};
|
2019-04-14 15:49:13 +03:00
|
|
|
|
2019-04-05 12:43:57 +03:00
|
|
|
};
|
2019-04-05 12:29:26 +03:00
|
|
|
rec
|
2019-06-13 12:30:13 +03:00
|
|
|
{ inherit niv niv-sdist niv-source niv-devshell niv-cabal-upload;
|
2019-04-28 20:31:31 +03:00
|
|
|
|
|
|
|
tests = pkgs.callPackage ./tests { inherit niv; };
|
|
|
|
|
2019-06-12 15:57:21 +03:00
|
|
|
niv-test = pkgs.runCommand "niv-test" { buildInputs = [ niv ] ; }
|
|
|
|
"niv-test && touch $out";
|
|
|
|
|
2019-04-05 12:29:26 +03:00
|
|
|
readme = pkgs.writeText "README.md"
|
|
|
|
(with
|
|
|
|
{ template = builtins.readFile ./README.tpl.md;
|
|
|
|
niv_help = builtins.readFile
|
|
|
|
(pkgs.runCommand "niv_help" { buildInputs = [ niv ]; }
|
|
|
|
"niv --help > $out"
|
|
|
|
);
|
|
|
|
niv_cmd_help = cmd: builtins.readFile
|
|
|
|
(pkgs.runCommand "niv_${cmd}_help" { buildInputs = [ niv ]; }
|
|
|
|
"niv ${cmd} --help > $out"
|
|
|
|
);
|
|
|
|
cmds = [ "add" "update" "drop" "init" "show" ];
|
|
|
|
};
|
|
|
|
pkgs.lib.replaceStrings
|
|
|
|
([ "replace_niv_help" ] ++ (map (cmd: "replace_niv_${cmd}_help") cmds))
|
|
|
|
([ niv_help ] ++ (map niv_cmd_help cmds))
|
|
|
|
template
|
|
|
|
);
|
|
|
|
readme-test = pkgs.runCommand "README-test" {}
|
|
|
|
''
|
|
|
|
err() {
|
|
|
|
echo
|
|
|
|
echo -e "\e[31mERR\e[0m: README.md out of date"
|
|
|
|
echo -e "please run \e[1m./script/gen\e[0m"
|
|
|
|
echo
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
diff ${./README.md} ${readme} && echo dummy > $out || err ;
|
|
|
|
'';
|
2019-04-14 15:49:13 +03:00
|
|
|
|
|
|
|
niv-svg-test = pkgs.runCommand "niv-svg-test" {}
|
|
|
|
''
|
2019-06-12 17:27:59 +03:00
|
|
|
# XXX: This test means that the svg needs to be regenerated
|
|
|
|
# by hand on (virtually) every commit.
|
|
|
|
# TODO: figure out a nicer way
|
|
|
|
touch $out
|
|
|
|
exit 0
|
|
|
|
|
2019-04-14 15:49:13 +03:00
|
|
|
err() {
|
|
|
|
echo
|
|
|
|
echo -e "\e[31mERR\e[0m: niv.svg out of date"
|
|
|
|
echo -e "please run \e[1m./script/gen\e[0m"
|
|
|
|
echo
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
expected_hash=$(${pkgs.nix}/bin/nix-hash ${niv-svg-gen})
|
|
|
|
actual_hash=$(grep -oP 'id="\K[^"]+' ${./site/niv.svg} -m 1)
|
|
|
|
|
2019-05-09 13:43:00 +03:00
|
|
|
echo "expected $expected_hash"
|
|
|
|
echo "actual $actual_hash"
|
2019-04-14 15:49:13 +03:00
|
|
|
|
|
|
|
[ $expected_hash == $actual_hash ] && echo dymmy > $out || err
|
|
|
|
'';
|
|
|
|
|
2019-06-09 23:42:35 +03:00
|
|
|
|
|
|
|
# TODO: use nivForTest for this one
|
2019-04-14 15:49:13 +03:00
|
|
|
niv-svg-cmds = pkgs.writeScript "niv-svg-cmds"
|
|
|
|
''
|
|
|
|
#!${pkgs.stdenv.shell}
|
|
|
|
set -euo pipefail
|
|
|
|
echo '$ niv init'
|
|
|
|
niv init
|
2019-04-15 00:50:42 +03:00
|
|
|
echo
|
2019-04-14 15:49:13 +03:00
|
|
|
echo '$ niv add stedolan/jq'
|
|
|
|
niv add stedolan/jq
|
|
|
|
'';
|
|
|
|
|
|
|
|
niv-svg-gen = pkgs.writeScript "niv-svg-gen"
|
|
|
|
''
|
|
|
|
#!${pkgs.stdenv.shell}
|
|
|
|
set -euo pipefail
|
|
|
|
export PATH=${haskellPackages.niv}/bin:${pkgs.nix}/bin:$PATH
|
|
|
|
|
|
|
|
hash=$(${pkgs.nix}/bin/nix-hash ''${BASH_SOURCE[0]})
|
|
|
|
pushd $(mktemp -d)
|
|
|
|
(tail -f /dev/null || true) | ${pkgs.termtosvg}/bin/termtosvg \
|
|
|
|
-g 82x26 -M 1500 -m 1500 -t window_frame \
|
|
|
|
-c '${niv-svg-cmds}' niv.svg
|
|
|
|
${pkgs.gnused}/bin/sed -i "0,/terminal/{s/terminal/$hash/}" niv.svg
|
|
|
|
niv_svg=$(realpath niv.svg)
|
|
|
|
popd
|
|
|
|
|
|
|
|
cp $niv_svg site/niv.svg
|
|
|
|
'';
|
|
|
|
|
2019-04-05 12:29:26 +03:00
|
|
|
}
|