first try at docker

This commit is contained in:
Yann Esposito (Yogsototh) 2021-04-23 10:38:46 +02:00
parent 247c276788
commit b522d357d3
Signed by untrusted user who does not match committer: yogsototh
GPG Key ID: 7B19A4C650D59646
10 changed files with 95 additions and 51 deletions

11
Dockerfile Normal file
View File

@ -0,0 +1,11 @@
FROM nixos/nix
RUN nix-channel --add https://nixos.org/channels/nixos-20.09 nixpkgs
RUN nix-channel --update
RUN nix-env -i git
RUN nix-env -i niv
RUN mkdir -p /home/her.esy.fun
COPY . /home/her.esy.fun
RUN cd /home/her.esy.fun && nix-shell

View File

@ -371,6 +371,7 @@ genPdfAction _getPost out = do
["--pdf-engine=xelatex"
, "--resource-path=" <> takeDirectory srcFile
, srcFile
, "--resource-path=."
, "-H", "engine" </> "deeplist.tex"
, "-V", "mainfont:CMU Serif"
, "-V", "mainfontoptions:Renderer=OpenType, Mapping=tex-text, ItalicFeatures={Alternate = 0}, Ligatures={Common,Rare,Historic,Contextual},Contextuals=Inner,Alternate=1"

4
engine/docker-build.sh Executable file
View File

@ -0,0 +1,4 @@
#!/usr/bin/env zsh
# Should build the docker image
docker build -t her.esy.fun .

8
engine/docker-run.sh Executable file
View File

@ -0,0 +1,8 @@
#!/usr/bin/env bash
cd "$(git rev-parse --show-toplevel)" || exit 1
if (($#>0)); then
docker run --rm -v $PWD:/home/her.esy.fun --name her.esy.fun -it her.esy.fun /bin/sh -c "cd /home/her.esy.fun && nix-shell --run $@"
else
docker run --rm -v $PWD:/home/her.esy.fun --name her.esy.fun -it her.esy.fun
fi

View File

@ -5,7 +5,7 @@ cd "$(git rev-parse --show-toplevel)" || exit 1
src="$1"
dst="$2"
./engine/org2gemini_step1.sh "$src" | \
awk -f ./engine/org2gemini_step1.sh "$src" | \
perl -pe 's#^email:\s+yann\@esposito.host\s*#$&=> /files/publickey.txt gpg\n#g;' | \
perl -pe 's#\[\[([^]]*)\]\[([^]]*)\]\]#\n=> $1 $2#g;' | \
perl -pe 's#=> file:([^ ]*)\.org#=> $1.gmi#g;' | \

View File

@ -10,4 +10,4 @@ fi
cd $webdir && \
echo "Serving: $webdir" && \
sws -d --port 3000 .
http-server -a dev.local -p 3000

View File

@ -29,7 +29,7 @@ executable her-esy-fun
-- LANGUAGE extensions used by modules in this package.
-- other-extensions:
build-depends: base ^>=4.14.1.0
build-depends: base
, aeson
, pandoc
, pandoc-types

View File

@ -1,38 +1,26 @@
{
"ghc.nix": {
"branch": "master",
"description": "Nix (shell) expression for working on GHC",
"homepage": "https://haskell.org/ghc/",
"owner": "alpmestan",
"repo": "ghc.nix",
"rev": "9adaf8abe53fa0618c1561919ddfbc4342fe144b",
"sha256": "0qmkkildzl21y88czgnschvi8mdkqrj9hgvpban58zzjnxw5s4nd",
"type": "tarball",
"url": "https://github.com/alpmestan/ghc.nix/archive/9adaf8abe53fa0618c1561919ddfbc4342fe144b.tar.gz",
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
},
"niv": {
"branch": "master",
"description": "Easy dependency management for Nix projects",
"homepage": "https://github.com/nmattia/niv",
"owner": "nmattia",
"repo": "niv",
"rev": "f73bf8d584148677b01859677a63191c31911eae",
"sha256": "0jlmrx633jvqrqlyhlzpvdrnim128gc81q5psz2lpp2af8p8q9qs",
"rev": "af958e8057f345ee1aca714c1247ef3ba1c15f5e",
"sha256": "1qjavxabbrsh73yck5dcq8jggvh3r2jkbr6b5nlz5d9yrqm9255n",
"type": "tarball",
"url": "https://github.com/nmattia/niv/archive/f73bf8d584148677b01859677a63191c31911eae.tar.gz",
"url": "https://github.com/nmattia/niv/archive/af958e8057f345ee1aca714c1247ef3ba1c15f5e.tar.gz",
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
},
"nixpkgs": {
"branch": "nixpkgs-20.09-darwin",
"description": "A read-only mirror of NixOS/nixpkgs tracking the released channels. Send issues and PRs to",
"branch": "nixos-20.09",
"description": "NixOS/nixpkgs repository instead.",
"homepage": "https://github.com/NixOS/nixpkgs",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "e716ddfac4be879ffbae75c3914a538dd5d4d12e",
"sha256": "0c2090sz4nvd1bqa9bfz3b6mj0q8b7v4jzgsykn2hf291l3h94d6",
"rev": "4263ba5e133cc3fc699c1152ab5ee46ef668e675",
"sha256": "1nzqrdw0lhbldbs9r651zmgqpwhjhh9sssykhcl2155kgsfsrk7i",
"type": "tarball",
"url": "https://github.com/NixOS/nixpkgs/archive/e716ddfac4be879ffbae75c3914a538dd5d4d12e.tar.gz",
"url": "https://github.com/NixOS/nixpkgs/archive/4263ba5e133cc3fc699c1152ab5ee46ef668e675.tar.gz",
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
},
"shake": {
@ -41,10 +29,10 @@
"homepage": "http://shakebuild.com",
"owner": "ndmitchell",
"repo": "shake",
"rev": "4536d9ce5cef0e56395fd61ccef9816c9b420fd1",
"sha256": "1s7hjhcc09l026jaca3ndbb103s9d7qlx4vqzx2s6j4rr751nd70",
"rev": "79a098c55f62de9efd851546435945b7f7f9b9df",
"sha256": "15p7szja7ngvmw1jdfik4n6yli3cwzy9irb9wqkrkkdx7cg9vvk4",
"type": "tarball",
"url": "https://github.com/ndmitchell/shake/archive/4536d9ce5cef0e56395fd61ccef9816c9b420fd1.tar.gz",
"url": "https://github.com/ndmitchell/shake/archive/79a098c55f62de9efd851546435945b7f7f9b9df.tar.gz",
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
}
}

View File

@ -6,25 +6,33 @@ let
# The fetchers. fetch_<type> fetches specs of type <type>.
#
fetch_file = pkgs: spec:
fetch_file = pkgs: name: spec:
let
name' = sanitizeName name + "-src";
in
if spec.builtin or true then
builtins_fetchurl { inherit (spec) url sha256; }
builtins_fetchurl { inherit (spec) url sha256; name = name'; }
else
pkgs.fetchurl { inherit (spec) url sha256; };
pkgs.fetchurl { inherit (spec) url sha256; name = name'; };
fetch_tarball = pkgs: name: spec:
let
ok = str: ! builtins.isNull (builtins.match "[a-zA-Z0-9+-._?=]" str);
# sanitize the name, though nix will still fail if name starts with period
name' = stringAsChars (x: if ! ok x then "-" else x) "${name}-src";
name' = sanitizeName name + "-src";
in
if spec.builtin or true then
builtins_fetchTarball { name = name'; inherit (spec) url sha256; }
else
pkgs.fetchzip { name = name'; inherit (spec) url sha256; };
fetch_git = spec:
builtins.fetchGit { url = spec.repo; inherit (spec) rev ref; };
fetch_git = name: spec:
let
ref =
if spec ? ref then spec.ref else
if spec ? branch then "refs/heads/${spec.branch}" else
if spec ? tag then "refs/tags/${spec.tag}" else
abort "In git source '${name}': Please specify `ref`, `tag` or `branch`!";
in
builtins.fetchGit { url = spec.repo; inherit (spec) rev; inherit ref; };
fetch_local = spec: spec.path;
@ -40,11 +48,21 @@ let
# Various helpers
#
# https://github.com/NixOS/nixpkgs/pull/83241/files#diff-c6f540a4f3bfa4b0e8b6bafd4cd54e8bR695
sanitizeName = name:
(
concatMapStrings (s: if builtins.isList s then "-" else s)
(
builtins.split "[^[:alnum:]+._?=-]+"
((x: builtins.elemAt (builtins.match "\\.*(.*)" x) 0) name)
)
);
# The set of packages used when specs are fetched using non-builtins.
mkPkgs = sources:
mkPkgs = sources: system:
let
sourcesNixpkgs =
import (builtins_fetchTarball { inherit (sources.nixpkgs) url sha256; }) {};
import (builtins_fetchTarball { inherit (sources.nixpkgs) url sha256; }) { inherit system; };
hasNixpkgsPath = builtins.any (x: x.prefix == "nixpkgs") builtins.nixPath;
hasThisAsNixpkgsPath = <nixpkgs> == ./.;
in
@ -64,9 +82,9 @@ let
if ! builtins.hasAttr "type" spec then
abort "ERROR: niv spec ${name} does not have a 'type' attribute"
else if spec.type == "file" then fetch_file pkgs spec
else if spec.type == "file" then fetch_file pkgs name spec
else if spec.type == "tarball" then fetch_tarball pkgs name spec
else if spec.type == "git" then fetch_git spec
else if spec.type == "git" then fetch_git name spec
else if spec.type == "local" then fetch_local spec
else if spec.type == "builtin-tarball" then fetch_builtin-tarball name
else if spec.type == "builtin-url" then fetch_builtin-url name
@ -80,7 +98,10 @@ let
saneName = stringAsChars (c: if isNull (builtins.match "[a-zA-Z0-9]" c) then "_" else c) name;
ersatz = builtins.getEnv "NIV_OVERRIDE_${saneName}";
in
if ersatz == "" then drv else ersatz;
if ersatz == "" then drv else
# this turns the string into an actual Nix path (for both absolute and
# relative paths)
if builtins.substring 0 1 ersatz == "/" then /. + ersatz else /. + builtins.getEnv "PWD" + "/${ersatz}";
# Ports of functions for older nix versions
@ -98,25 +119,29 @@ let
# https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/strings.nix#L269
stringAsChars = f: s: concatStrings (map f (stringToCharacters s));
concatMapStrings = f: list: concatStrings (map f list);
concatStrings = builtins.concatStringsSep "";
# https://github.com/NixOS/nixpkgs/blob/8a9f58a375c401b96da862d969f66429def1d118/lib/attrsets.nix#L331
optionalAttrs = cond: as: if cond then as else {};
# fetchTarball version that is compatible between all the versions of Nix
builtins_fetchTarball = { url, name, sha256 }@attrs:
builtins_fetchTarball = { url, name ? null, sha256 }@attrs:
let
inherit (builtins) lessThan nixVersion fetchTarball;
in
if lessThan nixVersion "1.12" then
fetchTarball { inherit name url; }
fetchTarball ({ inherit url; } // (optionalAttrs (!isNull name) { inherit name; }))
else
fetchTarball attrs;
# fetchurl version that is compatible between all the versions of Nix
builtins_fetchurl = { url, sha256 }@attrs:
builtins_fetchurl = { url, name ? null, sha256 }@attrs:
let
inherit (builtins) lessThan nixVersion fetchurl;
in
if lessThan nixVersion "1.12" then
fetchurl { inherit url; }
fetchurl ({ inherit url; } // (optionalAttrs (!isNull name) { inherit name; }))
else
fetchurl attrs;
@ -135,7 +160,8 @@ let
mkConfig =
{ sourcesFile ? if builtins.pathExists ./sources.json then ./sources.json else null
, sources ? if isNull sourcesFile then {} else builtins.fromJSON (builtins.readFile sourcesFile)
, pkgs ? mkPkgs sources
, system ? builtins.currentSystem
, pkgs ? mkPkgs sources system
}: rec {
# The sources, i.e. the attribute set of spec name to spec
inherit sources;

View File

@ -1,16 +1,15 @@
let
sources = import ./nix/sources.nix;
pkgs = import sources.nixpkgs {};
pkgs1909 = import (fetchTarball https://github.com/NixOS/nixpkgs/archive/19.09.tar.gz) {};
haskellDeps = ps : with ps; [
shake
pandoc
data-default
protolude
pkgs1909.haskellPackages.sws
stache
turtle
ansi-terminal
time
];
ghc = pkgs.haskellPackages.ghcWithPackages haskellDeps;
in
@ -18,19 +17,26 @@ pkgs.mkShell {
buildInputs = with pkgs;
[ cacert
coreutils
# build
ghc
haskellPackages.shake
wget # for cabal-install
haskellPackages.cabal-install
entr
html-xml-utils
zsh
perl
perlPackages.URI
minify
niv
imagemagick
texlive.combined.scheme-medium # https://nixos.wiki/wiki/TexLive
# dev env
# niv
git
direnv
ghc
haskellPackages.shake
tmux
# for emacs dev
ripgrep
nodePackages.http-server
];
}