mirror of
https://github.com/nmattia/niv.git
synced 2024-11-09 12:38:31 +03:00
180 lines
4.8 KiB
Nix
180 lines
4.8 KiB
Nix
{ sources ? import ./nix/sources.nix
|
|
, pkgs ? import ./nix { inherit sources; }
|
|
}:
|
|
|
|
with rec
|
|
{ files = pkgs.callPackage ./nix/files.nix {};
|
|
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" ./.
|
|
[ "^package.yaml$"
|
|
"^README.md$"
|
|
"^LICENSE$"
|
|
"^app$"
|
|
"^app.*.hs$"
|
|
"^src$"
|
|
"^src/Niv$"
|
|
"^src/Niv/GitHub$"
|
|
"^src/Niv/Update$"
|
|
"^src.*.hs$"
|
|
"^README.md$"
|
|
"^nix$"
|
|
"^nix.sources.nix$"
|
|
];
|
|
|
|
haskellPackages = pkgs.haskellPackages.override
|
|
{ overrides = _: haskellPackages:
|
|
{ niv =
|
|
pkgs.haskell.lib.failOnAllWarnings (
|
|
pkgs.haskell.lib.disableExecutableProfiling (
|
|
pkgs.haskell.lib.disableLibraryProfiling (
|
|
pkgs.haskell.lib.generateOptparseApplicativeCompletion "niv" (
|
|
haskellPackages.callCabal2nix "niv" niv-source {}))));
|
|
};
|
|
};
|
|
|
|
niv = haskellPackages.niv;
|
|
|
|
niv-sdist = pkgs.haskell.lib.sdistTarball niv;
|
|
|
|
niv-cabal-upload =
|
|
with
|
|
{ niv-version = niv.version;
|
|
};
|
|
pkgs.writeScript "cabal-upload"
|
|
''
|
|
#!${pkgs.stdenv.shell}
|
|
cabal upload "$@" "${niv-sdist}/niv-${niv-version}.tar.gz"
|
|
'';
|
|
|
|
niv-devshell = haskellPackages.shellFor
|
|
{ packages = (ps: [ ps.niv ]);
|
|
shellHook =
|
|
''
|
|
repl() {
|
|
shopt -s globstar
|
|
ghci -clear-package-db -global-package-db -Wall app/NivTest.hs src/**/*.hs
|
|
}
|
|
|
|
repl_niv() {
|
|
shopt -s globstar
|
|
ghci -clear-package-db -global-package-db -Wall app/Niv.hs src/**/*.hs
|
|
}
|
|
|
|
echo "To start a REPL session for the test suite, run:"
|
|
echo " > repl"
|
|
echo " > :main"
|
|
echo " (tests run)"
|
|
echo
|
|
echo "To start a REPL session emulating the niv executable, run:"
|
|
echo " > repl_niv"
|
|
echo " > :main --help ..."
|
|
echo " NIV - Version manager for Nix projects"
|
|
echo " ..."
|
|
'';
|
|
};
|
|
|
|
};
|
|
rec
|
|
{ inherit niv niv-sdist niv-source niv-devshell niv-cabal-upload;
|
|
|
|
tests = pkgs.callPackage ./tests { inherit niv; };
|
|
|
|
niv-test = pkgs.runCommand "niv-test" { buildInputs = [ niv ] ; }
|
|
"niv-test && touch $out";
|
|
|
|
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 ;
|
|
'';
|
|
|
|
niv-svg-test = pkgs.runCommand "niv-svg-test" {}
|
|
''
|
|
# 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
|
|
|
|
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)
|
|
|
|
echo "expected $expected_hash"
|
|
echo "actual $actual_hash"
|
|
|
|
[ $expected_hash == $actual_hash ] && echo dymmy > $out || err
|
|
'';
|
|
|
|
|
|
# TODO: use nivForTest for this one
|
|
niv-svg-cmds = pkgs.writeScript "niv-svg-cmds"
|
|
''
|
|
#!${pkgs.stdenv.shell}
|
|
set -euo pipefail
|
|
echo '$ niv init'
|
|
niv init
|
|
echo
|
|
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
|
|
site=$PWD/site
|
|
|
|
pushd $(mktemp -d)
|
|
${pkgs.termtosvg}/bin/termtosvg \
|
|
-g 82x26 -M 500 -m 500 -t window_frame_js \
|
|
-c '${niv-svg-cmds}' $site/niv.svg
|
|
|
|
echo done rendering
|
|
popd
|
|
'';
|
|
|
|
}
|