mirror of
https://github.com/nmattia/niv.git
synced 2024-09-18 19:07:19 +03:00
commit
aedf42ae0a
@ -41,8 +41,34 @@ jobs:
|
|||||||
name: Nix build
|
name: Nix build
|
||||||
command: ./script/test
|
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:
|
workflows:
|
||||||
version: 2
|
version: 2
|
||||||
build:
|
build:
|
||||||
jobs:
|
jobs:
|
||||||
- build-nix
|
- build-nix:
|
||||||
|
context: niv-netlify
|
||||||
|
@ -1,10 +1,15 @@
|
|||||||
# niv
|
# niv
|
||||||
|
|
||||||
[![CircleCI](https://circleci.com/gh/nmattia/niv.svg?style=svg)](https://circleci.com/gh/nmattia/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
|
Painless dependencies for [Nix] projects. Read more in the [use case
|
||||||
section](#use-cases) section below.
|
section](#use-cases) section below.
|
||||||
|
|
||||||
|
<p align="center">
|
||||||
|
<img src="https://niv.nmattia.com/niv.svg">
|
||||||
|
</p>
|
||||||
|
|
||||||
## Install
|
## Install
|
||||||
|
|
||||||
``` bash
|
``` bash
|
||||||
|
@ -1,10 +1,15 @@
|
|||||||
# niv
|
# niv
|
||||||
|
|
||||||
[![CircleCI](https://circleci.com/gh/nmattia/niv.svg?style=svg)](https://circleci.com/gh/nmattia/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
|
Painless dependencies for [Nix] projects. Read more in the [use case
|
||||||
section](#use-cases) section below.
|
section](#use-cases) section below.
|
||||||
|
|
||||||
|
<p align="center">
|
||||||
|
<img src="https://niv.nmattia.com/niv.svg">
|
||||||
|
</p>
|
||||||
|
|
||||||
## Install
|
## Install
|
||||||
|
|
||||||
``` bash
|
``` bash
|
||||||
|
10
app/Niv.hs
10
app/Niv.hs
@ -209,8 +209,8 @@ completePackageSpec = execStateT $ do
|
|||||||
(Just (Aeson.String owner), Just (Aeson.String repo)) -> do
|
(Just (Aeson.String owner), Just (Aeson.String repo)) -> do
|
||||||
liftIO (GH.executeRequest' $ GH.repositoryR (GH.N owner) (GH.N repo))
|
liftIO (GH.executeRequest' $ GH.repositoryR (GH.N owner) (GH.N repo))
|
||||||
>>= \case
|
>>= \case
|
||||||
Left {} ->
|
Left e ->
|
||||||
liftIO $ warnCouldNotFetchGitHubRepo (T.unpack owner, T.unpack repo)
|
liftIO $ warnCouldNotFetchGitHubRepo e (T.unpack owner, T.unpack repo)
|
||||||
Right ghRepo -> do
|
Right ghRepo -> do
|
||||||
|
|
||||||
-- Description
|
-- Description
|
||||||
@ -669,8 +669,9 @@ initNixSourcesJsonContent = "{}"
|
|||||||
-- Warn
|
-- Warn
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
|
|
||||||
warnCouldNotFetchGitHubRepo :: (String, String) -> IO ()
|
warnCouldNotFetchGitHubRepo :: GH.Error -> (String, String) -> IO ()
|
||||||
warnCouldNotFetchGitHubRepo (owner, repo) = putStrLn $ unlines [ line1, line2 ]
|
warnCouldNotFetchGitHubRepo e (owner, repo) =
|
||||||
|
putStrLn $ unlines [ line1, line2, line3 ]
|
||||||
where
|
where
|
||||||
line1 = "WARNING: Could not read from GitHub repo: " <> owner <> "/" <> repo
|
line1 = "WARNING: Could not read from GitHub repo: " <> owner <> "/" <> repo
|
||||||
line2 = [s|
|
line2 = [s|
|
||||||
@ -687,6 +688,7 @@ If not, try re-adding it:
|
|||||||
|
|
||||||
Make sure the repository exists.
|
Make sure the repository exists.
|
||||||
|]
|
|]
|
||||||
|
line3 = unwords [ "(Error was:", show e, ")" ]
|
||||||
|
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
-- Abort
|
-- Abort
|
||||||
|
53
default.nix
53
default.nix
@ -1,10 +1,10 @@
|
|||||||
{ pkgs ? import ./nix {} }:
|
{ pkgs ? import ./nix {} }:
|
||||||
with rec
|
with rec
|
||||||
{ niv-source = pkgs.lib.sourceByRegex ./.
|
{ files = pkgs.callPackage ./nix/files.nix {};
|
||||||
|
niv-source = files.sourceByRegex "niv" ./.
|
||||||
[ "^package.yaml$"
|
[ "^package.yaml$"
|
||||||
"^app.*$"
|
"^app.*$"
|
||||||
"^README.md$"
|
"^README.md$"
|
||||||
"^nix$"
|
|
||||||
"^nix.sources.nix$"
|
"^nix.sources.nix$"
|
||||||
];
|
];
|
||||||
haskellPackages = pkgs.haskellPackages.override
|
haskellPackages = pkgs.haskellPackages.override
|
||||||
@ -24,6 +24,7 @@ with rec
|
|||||||
echo " > repl"
|
echo " > repl"
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
};
|
};
|
||||||
rec
|
rec
|
||||||
{ inherit niv-source niv-devshell;
|
{ inherit niv-source niv-devshell;
|
||||||
@ -58,4 +59,52 @@ rec
|
|||||||
|
|
||||||
diff ${./README.md} ${readme} && echo dummy > $out || err ;
|
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
|
||||||
|
'';
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,8 @@
|
|||||||
{ sources ? import ./sources.nix }:
|
{ sources ? import ./sources.nix }:
|
||||||
import sources.nixpkgs
|
import sources.nixpkgs
|
||||||
{ overlays =
|
{ overlays =
|
||||||
[
|
[ (_: pkgs:
|
||||||
# Snack
|
{ termtosvg = pkgs.callPackage ./termtosvg.nix {}; }
|
||||||
(_: pkgs:
|
|
||||||
with
|
|
||||||
{ snack = pkgs.callPackage "${sources.snack}/nix/packages.nix" {}; };
|
|
||||||
{ inherit (snack) snack-exe snack-lib; }
|
|
||||||
)
|
)
|
||||||
];
|
];
|
||||||
config = {};
|
config = {};
|
||||||
|
60
nix/files.nix
Normal file
60
nix/files.nix
Normal file
@ -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
|
||||||
|
'';
|
||||||
|
}
|
22
nix/termtosvg.nix
Normal file
22
nix/termtosvg.nix
Normal file
@ -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 ];
|
||||||
|
};
|
||||||
|
}
|
@ -9,3 +9,4 @@ set -euo pipefail
|
|||||||
echo "Updating README"
|
echo "Updating README"
|
||||||
|
|
||||||
cat $(nix-build -A readme) > README.md
|
cat $(nix-build -A readme) > README.md
|
||||||
|
$(nix-build -A niv-svg-gen)
|
||||||
|
3
site/index.html
Normal file
3
site/index.html
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
<h1>Niv</h1>
|
||||||
|
<img src="./niv.svg">
|
||||||
|
<a href="https://www.github.com/nmattia/niv">niv</a>
|
48
site/niv.svg
Normal file
48
site/niv.svg
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" id="106e890de9b7df935e0f4355a28a86e7" baseProfile="full" viewBox="0 0 703 523" width="703" version="1.1">
|
||||||
|
<defs>
|
||||||
|
<termtosvg:template_settings xmlns:termtosvg="https://github.com/nbedos/termtosvg">
|
||||||
|
<termtosvg:screen_geometry columns="82" rows="26"/>
|
||||||
|
</termtosvg:template_settings>
|
||||||
|
<style type="text/css" id="generated-style"><![CDATA[:root {
|
||||||
|
--animation-duration: 5500ms;
|
||||||
|
}
|
||||||
|
|
||||||
|
#screen {
|
||||||
|
font-family: 'DejaVu Sans Mono', monospace;
|
||||||
|
font-style: normal;
|
||||||
|
font-size: 14px;
|
||||||
|
}
|
||||||
|
|
||||||
|
text {
|
||||||
|
dominant-baseline: text-before-edge;
|
||||||
|
white-space: pre;
|
||||||
|
}]]></style>
|
||||||
|
<style type="text/css" id="user-style">
|
||||||
|
/* gjm8 color theme (source: https://terminal.sexy/) */
|
||||||
|
.foreground {fill: #f8f8f2}
|
||||||
|
.background {fill: #272822}
|
||||||
|
.color0 {fill: #272822}
|
||||||
|
.color1 {fill: #f92672}
|
||||||
|
.color2 {fill: #a6e22e}
|
||||||
|
.color3 {fill: #f4bf75}
|
||||||
|
.color4 {fill: #66d9ef}
|
||||||
|
.color5 {fill: #ae81ff}
|
||||||
|
.color6 {fill: #a1efe4}
|
||||||
|
.color7 {fill: #f8f8f2}
|
||||||
|
.color8 {fill: #75715e}
|
||||||
|
.color9 {fill: #fd971f}
|
||||||
|
.color10 {fill: #383830}
|
||||||
|
.color11 {fill: #49483e}
|
||||||
|
.color12 {fill: #a59f85}
|
||||||
|
.color13 {fill: #f5f4f1}
|
||||||
|
.color14 {fill: #cc6633}
|
||||||
|
.color15 {fill: #f9f8f5}
|
||||||
|
</style>
|
||||||
|
</defs>
|
||||||
|
<rect id="terminalui" class="background" width="100%" height="100%" ry="4.5826941"/>
|
||||||
|
<circle cx="24" cy="23" r="7" class="color1"/>
|
||||||
|
<circle cx="44" cy="23" r="7" class="color3"/>
|
||||||
|
<circle cx="64" cy="23" r="7" class="color2"/>
|
||||||
|
<svg id="screen" width="656" x="23" y="50" viewBox="0 0 656 442" preserveAspectRatio="xMidYMin meet">
|
||||||
|
<rect class="background" height="100%" width="100%" x="0" y="0"/><g display="none"><rect class="foreground" height="17" width="8" x="0" y="85"/><use y="85" xlink:href="#g1"/><animate attributeName="display" begin="0ms; anim_last.end" dur="1500ms" from="inline" to="inline"/></g><g display="none"><rect class="foreground" height="17" width="8" x="0" y="187"/><use y="187" xlink:href="#g1"/><animate attributeName="display" begin="1500ms; anim_last.end+1500ms" dur="1500ms" from="inline" to="inline"/></g><g display="none"><rect class="foreground" height="17" width="8" x="0" y="289"/><use y="289" xlink:href="#g1"/><animate attributeName="display" begin="3000ms; anim_last.end+3000ms" dur="1500ms" from="inline" to="inline"/></g><g display="none"><use y="0" xlink:href="#g2"/><use y="17" xlink:href="#g3"/><use y="34" xlink:href="#g4"/><use y="51" xlink:href="#g5"/><use y="68" xlink:href="#g6"/><animate attributeName="display" begin="0ms; anim_last.end" dur="5500ms" from="inline" to="inline"/></g><g display="none"><use y="85" xlink:href="#g7"/><use y="102" xlink:href="#g8"/><use y="119" xlink:href="#g9"/><use y="136" xlink:href="#g10"/><use y="153" xlink:href="#g11"/><use y="170" xlink:href="#g6"/><animate attributeName="display" begin="1500ms; anim_last.end+1500ms" dur="4000ms" from="inline" to="inline"/></g><g display="none"><use y="272" xlink:href="#g6"/><use y="187" xlink:href="#g7"/><use y="204" xlink:href="#g12"/><use y="221" xlink:href="#g13"/><use y="238" xlink:href="#g10"/><use y="255" xlink:href="#g14"/><animate attributeName="display" begin="3000ms; anim_last.end+3000ms" dur="2500ms" from="inline" to="inline"/></g><g display="none"><use y="289" xlink:href="#g7"/><use y="306" xlink:href="#g15"/><use y="323" xlink:href="#g16"/><use y="340" xlink:href="#g10"/><rect class="foreground" height="17" width="8" x="0" y="357"/><use y="357" xlink:href="#g1"/><animate attributeName="display" begin="4500ms; anim_last.end+4500ms" dur="1000ms" from="inline" to="inline" id="anim_last"/></g><defs><g id="g1"><text class="background" textLength="8" x="0"> </text></g><g id="g2"><text class="foreground" textLength="80" x="0">$ niv init</text></g><g id="g3"><text class="foreground" textLength="192" x="0">Creating nix/sources.nix</text></g><g id="g4"><text class="foreground" textLength="200" x="0">Creating nix/sources.json</text></g><g id="g5"><text class="foreground" textLength="152" x="0">Importing 'niv' ...</text></g><g id="g6"><text class="foreground" textLength="160" x="0">Reading sources file</text></g><g id="g7"><text class="foreground" textLength="96" x="0">unpacking...</text></g><g id="g8"><text class="foreground" textLength="656" x="0">path is '/nix/store/0m9fmmxbmvdqwpmryqb0gz27b768h6hd-7aa070d8b3f5a1399286c685a457c</text></g><g id="g9"><text class="foreground" textLength="152" x="0">622df616c68.tar.gz'</text></g><g id="g10"><text class="foreground" textLength="192" x="0">Writing new sources file</text></g><g id="g11"><text class="foreground" textLength="184" x="0">Importing 'nixpkgs' ...</text></g><g id="g12"><text class="foreground" textLength="656" x="0">path is '/nix/store/wbq0p56kd31j6zznjlaxahm8815gqcwk-46d3867a08a9206685e2b6a8e19f5</text></g><g id="g13"><text class="foreground" textLength="152" x="0">ad9f6ab4b39.tar.gz'</text></g><g id="g14"><text class="foreground" textLength="168" x="0">$ niv add stedolan/jq</text></g><g id="g15"><text class="foreground" textLength="656" x="0">path is '/nix/store/yjz2v8kfk2jkzc0w7lh43hfmcafpqs33-ad9fc9f559e78a764aac20f669f23</text></g><g id="g16"><text class="foreground" textLength="152" x="0">cdd020cd943.tar.gz'</text></g></defs></svg>
|
||||||
|
</svg>
|
After Width: | Height: | Size: 5.5 KiB |
Loading…
Reference in New Issue
Block a user