···57575858### Building it yourself
59596060-For version numbers, see `.tool-versions` and `stack.yaml`.
6161-All of these, except the last one, can be install using [homebrew](https://brew.sh/).
6262-6363-- [Elm](https://elm-lang.org/) programming language
6464-- [Haskell](https://docs.haskellstack.org/en/stable/README/) programming language
6565-- [Node.js](https://nodejs.org/) programming language with the [Yarn](https://yarnpkg.com/) package manager
6666-- [Just](https://github.com/casey/just) command runner (improved `make`)
6767-- [Devd](https://github.com/cortesi/devd) web server for development (optional)
6868-- [Elm Format](https://github.com/avh4/elm-format) elm code formatter (optional)
6969-- [Watchexec](https://github.com/watchexec/watchexec) watching for file changes (optional)
7070-- [Elm Proofread](https://github.com/icidasset/elm-proofread) documentation tests (optional)
6060+This project uses [Nix](https://nixos.org/features.html) to manage the project's environment. If you'd like to build this project without Nix, check out the dependencies in the `shell.nix` file (most are available through Homebrew as well).
716172627363```shell
7464# 🍱
75657676-# 1. Install programming languages:
7777-# Elm 0.19.1 & Haskell (Stack), see links above
6666+# 1. Setup Nix environment
6767+# https://nixos.org/download.html
78687969# 2. Install dependencies
8070yarn install
···11+# This file has been generated by Niv.
22+33+let
44+55+ #
66+ # The fetchers. fetch_<type> fetches specs of type <type>.
77+ #
88+99+ fetch_file = pkgs: spec:
1010+ if spec.builtin or true then
1111+ builtins_fetchurl { inherit (spec) url sha256; }
1212+ else
1313+ pkgs.fetchurl { inherit (spec) url sha256; };
1414+1515+ fetch_tarball = pkgs: name: spec:
1616+ let
1717+ ok = str: ! builtins.isNull (builtins.match "[a-zA-Z0-9+-._?=]" str);
1818+ # sanitize the name, though nix will still fail if name starts with period
1919+ name' = stringAsChars (x: if ! ok x then "-" else x) "${name}-src";
2020+ in
2121+ if spec.builtin or true then
2222+ builtins_fetchTarball { name = name'; inherit (spec) url sha256; }
2323+ else
2424+ pkgs.fetchzip { name = name'; inherit (spec) url sha256; };
2525+2626+ fetch_git = spec:
2727+ builtins.fetchGit { url = spec.repo; inherit (spec) rev ref; };
2828+2929+ fetch_local = spec: spec.path;
3030+3131+ fetch_builtin-tarball = name: throw
3232+ ''[${name}] The niv type "builtin-tarball" is deprecated. You should instead use `builtin = true`.
3333+ $ niv modify ${name} -a type=tarball -a builtin=true'';
3434+3535+ fetch_builtin-url = name: throw
3636+ ''[${name}] The niv type "builtin-url" will soon be deprecated. You should instead use `builtin = true`.
3737+ $ niv modify ${name} -a type=file -a builtin=true'';
3838+3939+ #
4040+ # Various helpers
4141+ #
4242+4343+ # The set of packages used when specs are fetched using non-builtins.
4444+ mkPkgs = sources:
4545+ let
4646+ sourcesNixpkgs =
4747+ import (builtins_fetchTarball { inherit (sources.nixpkgs) url sha256; }) {};
4848+ hasNixpkgsPath = builtins.any (x: x.prefix == "nixpkgs") builtins.nixPath;
4949+ hasThisAsNixpkgsPath = <nixpkgs> == ./.;
5050+ in
5151+ if builtins.hasAttr "nixpkgs" sources
5252+ then sourcesNixpkgs
5353+ else if hasNixpkgsPath && ! hasThisAsNixpkgsPath then
5454+ import <nixpkgs> {}
5555+ else
5656+ abort
5757+ ''
5858+ Please specify either <nixpkgs> (through -I or NIX_PATH=nixpkgs=...) or
5959+ add a package called "nixpkgs" to your sources.json.
6060+ '';
6161+6262+ # The actual fetching function.
6363+ fetch = pkgs: name: spec:
6464+6565+ if ! builtins.hasAttr "type" spec then
6666+ abort "ERROR: niv spec ${name} does not have a 'type' attribute"
6767+ else if spec.type == "file" then fetch_file pkgs spec
6868+ else if spec.type == "tarball" then fetch_tarball pkgs name spec
6969+ else if spec.type == "git" then fetch_git spec
7070+ else if spec.type == "local" then fetch_local spec
7171+ else if spec.type == "builtin-tarball" then fetch_builtin-tarball name
7272+ else if spec.type == "builtin-url" then fetch_builtin-url name
7373+ else
7474+ abort "ERROR: niv spec ${name} has unknown type ${builtins.toJSON spec.type}";
7575+7676+ # Ports of functions for older nix versions
7777+7878+ # a Nix version of mapAttrs if the built-in doesn't exist
7979+ mapAttrs = builtins.mapAttrs or (
8080+ f: set: with builtins;
8181+ listToAttrs (map (attr: { name = attr; value = f attr set.${attr}; }) (attrNames set))
8282+ );
8383+8484+ # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/lists.nix#L295
8585+ range = first: last: if first > last then [] else builtins.genList (n: first + n) (last - first + 1);
8686+8787+ # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/strings.nix#L257
8888+ stringToCharacters = s: map (p: builtins.substring p 1 s) (range 0 (builtins.stringLength s - 1));
8989+9090+ # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/strings.nix#L269
9191+ stringAsChars = f: s: concatStrings (map f (stringToCharacters s));
9292+ concatStrings = builtins.concatStringsSep "";
9393+9494+ # fetchTarball version that is compatible between all the versions of Nix
9595+ builtins_fetchTarball = { url, name, sha256 }@attrs:
9696+ let
9797+ inherit (builtins) lessThan nixVersion fetchTarball;
9898+ in
9999+ if lessThan nixVersion "1.12" then
100100+ fetchTarball { inherit name url; }
101101+ else
102102+ fetchTarball attrs;
103103+104104+ # fetchurl version that is compatible between all the versions of Nix
105105+ builtins_fetchurl = { url, sha256 }@attrs:
106106+ let
107107+ inherit (builtins) lessThan nixVersion fetchurl;
108108+ in
109109+ if lessThan nixVersion "1.12" then
110110+ fetchurl { inherit url; }
111111+ else
112112+ fetchurl attrs;
113113+114114+ # Create the final "sources" from the config
115115+ mkSources = config:
116116+ mapAttrs (
117117+ name: spec:
118118+ if builtins.hasAttr "outPath" spec
119119+ then abort
120120+ "The values in sources.json should not have an 'outPath' attribute"
121121+ else
122122+ spec // { outPath = fetch config.pkgs name spec; }
123123+ ) config.sources;
124124+125125+ # The "config" used by the fetchers
126126+ mkConfig =
127127+ { sourcesFile ? ./sources.json
128128+ , sources ? builtins.fromJSON (builtins.readFile sourcesFile)
129129+ , pkgs ? mkPkgs sources
130130+ }: rec {
131131+ # The sources, i.e. the attribute set of spec name to spec
132132+ inherit sources;
133133+134134+ # The "pkgs" (evaluated nixpkgs) to use for e.g. non-builtin fetchers
135135+ inherit pkgs;
136136+ };
137137+in
138138+mkSources (mkConfig {}) // { __functor = _: settings: mkSources (mkConfig settings); }