From 9703f53e8153489b913fecb804d18d2b1a76e920 Mon Sep 17 00:00:00 2001 From: Nicolas Mattia Date: Sun, 14 Apr 2019 14:49:13 +0200 Subject: [PATCH] Add SVG to README --- .circleci/config.yml | 28 ++++++++++++++++++++- README.md | 5 ++++ README.tpl.md | 5 ++++ app/Niv.hs | 10 +++++--- default.nix | 53 ++++++++++++++++++++++++++++++++++++-- nix/default.nix | 8 ++---- nix/files.nix | 60 ++++++++++++++++++++++++++++++++++++++++++++ nix/termtosvg.nix | 22 ++++++++++++++++ script/gen | 1 + site/index.html | 3 +++ site/niv.svg | 48 +++++++++++++++++++++++++++++++++++ 11 files changed, 230 insertions(+), 13 deletions(-) create mode 100644 nix/files.nix create mode 100644 nix/termtosvg.nix create mode 100644 site/index.html create mode 100644 site/niv.svg diff --git a/.circleci/config.yml b/.circleci/config.yml index a0508b1..3b562bb 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -41,8 +41,34 @@ jobs: name: Nix build command: ./script/test + - run: + name: "Update Node.js and npm (master only)" + command: | + if [ "$CIRCLE_BRANCH" == "master" ]; then + nix-env -f ./nix -iA nodejs-10_x + fi + - run: + name: "Install netlify-cli (master only)" + command: | + if [ "$CIRCLE_BRANCH" == "master" ]; then + npm install netlify-cli + fi + + - run: + name: "Netlify deploy (master only)" + command: | + if [ "$CIRCLE_BRANCH" == "master" ]; then + echo "Deploying to production" + ./node_modules/netlify-cli/bin/run deploy \ + --dir=./site \ + --message="$CIRCLE_SHA1" --prod + else + echo "Not deploying" + fi + workflows: version: 2 build: jobs: - - build-nix + - build-nix: + context: niv-netlify diff --git a/README.md b/README.md index f090ce3..f1324e7 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,15 @@ # niv [![CircleCI](https://circleci.com/gh/nmattia/niv.svg?style=svg)](https://circleci.com/gh/nmattia/niv) +[![Netlify Status](https://api.netlify.com/api/v1/badges/48532eaa-259f-4ca2-aadf-67f7c6b957fd/deploy-status)](https://app.netlify.com/sites/brave-meninsky-83f073/deploys) Painless dependencies for [Nix] projects. Read more in the [use case section](#use-cases) section below. +

+ +

+ ## Install ``` bash diff --git a/README.tpl.md b/README.tpl.md index 25d64d9..eeae14a 100644 --- a/README.tpl.md +++ b/README.tpl.md @@ -1,10 +1,15 @@ # niv [![CircleCI](https://circleci.com/gh/nmattia/niv.svg?style=svg)](https://circleci.com/gh/nmattia/niv) +[![Netlify Status](https://api.netlify.com/api/v1/badges/48532eaa-259f-4ca2-aadf-67f7c6b957fd/deploy-status)](https://app.netlify.com/sites/brave-meninsky-83f073/deploys) Painless dependencies for [Nix] projects. Read more in the [use case section](#use-cases) section below. +

+ +

+ ## Install ``` bash diff --git a/app/Niv.hs b/app/Niv.hs index 413fde4..42955b7 100644 --- a/app/Niv.hs +++ b/app/Niv.hs @@ -209,8 +209,8 @@ completePackageSpec = execStateT $ do (Just (Aeson.String owner), Just (Aeson.String repo)) -> do liftIO (GH.executeRequest' $ GH.repositoryR (GH.N owner) (GH.N repo)) >>= \case - Left {} -> - liftIO $ warnCouldNotFetchGitHubRepo (T.unpack owner, T.unpack repo) + Left e -> + liftIO $ warnCouldNotFetchGitHubRepo e (T.unpack owner, T.unpack repo) Right ghRepo -> do -- Description @@ -669,8 +669,9 @@ initNixSourcesJsonContent = "{}" -- Warn ------------------------------------------------------------------------------- -warnCouldNotFetchGitHubRepo :: (String, String) -> IO () -warnCouldNotFetchGitHubRepo (owner, repo) = putStrLn $ unlines [ line1, line2 ] +warnCouldNotFetchGitHubRepo :: GH.Error -> (String, String) -> IO () +warnCouldNotFetchGitHubRepo e (owner, repo) = + putStrLn $ unlines [ line1, line2, line3 ] where line1 = "WARNING: Could not read from GitHub repo: " <> owner <> "/" <> repo line2 = [s| @@ -687,6 +688,7 @@ If not, try re-adding it: Make sure the repository exists. |] + line3 = unwords [ "(Error was:", show e, ")" ] ------------------------------------------------------------------------------- -- Abort diff --git a/default.nix b/default.nix index 2c46a64..802fd72 100644 --- a/default.nix +++ b/default.nix @@ -1,10 +1,10 @@ { pkgs ? import ./nix {} }: with rec -{ niv-source = pkgs.lib.sourceByRegex ./. +{ files = pkgs.callPackage ./nix/files.nix {}; + niv-source = files.sourceByRegex "niv" ./. [ "^package.yaml$" "^app.*$" "^README.md$" - "^nix$" "^nix.sources.nix$" ]; haskellPackages = pkgs.haskellPackages.override @@ -24,6 +24,7 @@ with rec echo " > repl" ''; }; + }; rec { inherit niv-source niv-devshell; @@ -58,4 +59,52 @@ rec diff ${./README.md} ${readme} && echo dummy > $out || err ; ''; + + niv-svg-test = pkgs.runCommand "niv-svg-test" {} + '' + 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 actuall $actual_hash + + [ $expected_hash == $actual_hash ] && echo dymmy > $out || err + ''; + + niv-svg-cmds = pkgs.writeScript "niv-svg-cmds" + '' + #!${pkgs.stdenv.shell} + set -euo pipefail + echo '$ niv init' + niv init + 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 + ''; + } diff --git a/nix/default.nix b/nix/default.nix index 091b0b3..ec122e2 100644 --- a/nix/default.nix +++ b/nix/default.nix @@ -1,12 +1,8 @@ { sources ? import ./sources.nix }: import sources.nixpkgs { overlays = - [ - # Snack - (_: pkgs: - with - { snack = pkgs.callPackage "${sources.snack}/nix/packages.nix" {}; }; - { inherit (snack) snack-exe snack-lib; } + [ (_: pkgs: + { termtosvg = pkgs.callPackage ./termtosvg.nix {}; } ) ]; config = {}; diff --git a/nix/files.nix b/nix/files.nix new file mode 100644 index 0000000..5717a5e --- /dev/null +++ b/nix/files.nix @@ -0,0 +1,60 @@ +{ lib +, writeText +, runCommand +}: +rec +{ + + # Lists all the (relative paths to the) files in the directory. + listFilesInDir = dir: + let + go = dir: dirName: + lib.lists.concatLists + ( + lib.attrsets.mapAttrsToList + (path: ty: + if ty == "directory" + then + go "${dir}/${path}" "${dirName}${path}/" + else + [ "${dirName}${path}" ] + ) + (builtins.readDir dir) + ); + in go dir ""; + + # Like nixpkgs' sourceByRegex but doesn't depend on the directory name when + # computing the hash. Also doesn't require matching on the dir name to + # actually enter the dir. + sourceByRegex = name: src: regexes: + let + files = builtins.filter (x: x.keep) (map mk (listFilesInDir src)); + mk = path: + let relPath = lib.removePrefix (toString src + "/") (toString path); + in + { inherit relPath; + path = src + ("/" + path); + keep = lib.any (re: builtins.match re relPath != null) regexes; + }; + + files' = map (x: x.path) files; + paths' = map (x: x.relPath) files; + + filesAbs = writeText "foo" (lib.concatStringsSep "\n" files'); + filesRel = writeText "bar" (lib.concatStringsSep "\n" paths'); + in + runCommand "source-${name}" {} + '' + mkdir -p $out + + paste ${filesAbs} ${filesRel} | while IFS="$(printf '\t')" read -r f1 f2 + do + f="$out/$f2" + mkdir -p $(dirname $f) + echo $f1 + echo $f2 + echo $f + cp $f1 $f + done + ''; +} diff --git a/nix/termtosvg.nix b/nix/termtosvg.nix new file mode 100644 index 0000000..14618e5 --- /dev/null +++ b/nix/termtosvg.nix @@ -0,0 +1,22 @@ +{ lib, python3Packages }: + +python3Packages.buildPythonApplication rec { + pname = "termtosvg"; + version = "0.8.0"; + + src = python3Packages.fetchPypi { + inherit pname version; + sha256 = "e3a0a7bd511028c96d242525df807a23e6f22e55b111a7ee861f294a86224b0c"; + }; + + doCheck = false; + + propagatedBuildInputs = with python3Packages; [ lxml pyte ]; + + meta = with lib; { + homepage = https://nbedos.github.io/termtosvg/; + description = "Record terminal sessions as SVG animations"; + license = licenses.bsd3; + maintainers = with maintainers; [ ma27 ]; + }; +} diff --git a/script/gen b/script/gen index 3090548..2239be6 100755 --- a/script/gen +++ b/script/gen @@ -9,3 +9,4 @@ set -euo pipefail echo "Updating README" cat $(nix-build -A readme) > README.md +$(nix-build -A niv-svg-gen) diff --git a/site/index.html b/site/index.html new file mode 100644 index 0000000..bf551c8 --- /dev/null +++ b/site/index.html @@ -0,0 +1,3 @@ +

Niv

+ +niv diff --git a/site/niv.svg b/site/niv.svg new file mode 100644 index 0000000..aac905f --- /dev/null +++ b/site/niv.svg @@ -0,0 +1,48 @@ + + + + + + + + + + + + + + $ niv initCreating nix/sources.nixCreating nix/sources.jsonImporting 'niv' ...Reading sources fileunpacking...path is '/nix/store/0m9fmmxbmvdqwpmryqb0gz27b768h6hd-7aa070d8b3f5a1399286c685a457c622df616c68.tar.gz'Writing new sources fileImporting 'nixpkgs' ...path is '/nix/store/wbq0p56kd31j6zznjlaxahm8815gqcwk-46d3867a08a9206685e2b6a8e19f5ad9f6ab4b39.tar.gz'$ niv add stedolan/jqpath is '/nix/store/yjz2v8kfk2jkzc0w7lh43hfmcafpqs33-ad9fc9f559e78a764aac20f669f23cdd020cd943.tar.gz' + \ No newline at end of file