hnix: Haskell implementation of the Nix language

[ bsd3, data, library, nix, system ] [ Propose Tags ]

Haskell implementation of the Nix language.


[Skip to Readme]

Flags

Manual Flags

NameDescriptionDefault
optimize

Enable all optimization flags

Disabled
profiling

Enable profiling

Disabled

Use -f <flag> to enable a flag, or -f -<flag> to disable that flag. More info

Downloads

Note: This package has metadata revisions in the cabal description newer than included in the tarball. To unpack the package including the revisions, use 'cabal get'.

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 0.2.0, 0.2.1, 0.3.2, 0.3.3, 0.3.4, 0.4.0, 0.5.0, 0.5.1, 0.5.2, 0.6.0, 0.6.1, 0.7.0, 0.7.1, 0.8.0, 0.9.0, 0.9.1, 0.10.0, 0.10.1, 0.11.0, 0.11.1, 0.12.0, 0.12.0.1, 0.13.0, 0.13.0.1, 0.13.1, 0.14.0, 0.14.0.1, 0.14.0.2, 0.14.0.3, 0.14.0.4, 0.14.0.5, 0.14.0.6, 0.14.0.7, 0.14.0.8, 0.15.0, 0.16.0, 0.17.0 (info)
Change log CHANGELOG.md
Dependencies aeson (>=1.4.2 && <1.6), array (>=0.4 && <0.6), base (>=4.11 && <5), base16-bytestring, binary (>=0.8.5 && <0.9), bytestring (>=0.10.8 && <0.11), comonad (>=5.0.4 && <5.1), containers (>=0.5.11.0 && <0.7), data-fix (>=0.3.0 && <0.4), deepseq (>=1.4.3 && <1.5), deriving-compat (>=0.3 && <0.6), directory (>=1.3.1 && <1.4), exceptions (>=0.10.0 && <0.11), filepath (>=1.4.2 && <1.5), free (>=5.1 && <5.2), gitrev (>=1.1.0 && <1.4), hashable (>=1.2.5 && <1.3.1), hashing (>=0.1.0 && <0.2), haskeline (>=0.8.0.0 && <0.9), hnix, hnix-store-core (>=0.1.0 && <0.3), http-client (>=0.5.14 && <0.6 || >=0.6.4 && <0.8), http-client-tls (>=0.3.5 && <0.4), http-types (>=0.12.2 && <0.13), lens-family (>=1.2.2 && <2.2), lens-family-core (>=1.2.2 && <2.2), lens-family-th (>=0.5.0 && <0.6), logict (>=0.6.0 && <0.7 || >=0.7.0.2 && <0.8), megaparsec (>=7.0 && <9.1), monad-control (>=1.0.2 && <1.1), monadlist (>=0.0.2 && <0.1), mtl (>=2.2.2 && <2.3), neat-interpolation (>=0.4 && <0.6), optparse-applicative (>=0.14.3 && <0.17), parser-combinators (>=1.0.1 && <1.3), pretty-show, prettyprinter (>=1.7.0 && <1.8), process (>=1.6.3 && <1.7), ref-tf (>=0.4.0 && <0.5), regex-tdfa (>=1.2.3 && <1.4), repline (>=0.4.0.0 && <0.5), scientific (>=0.3.6 && <0.4), semialign (>=1 && <1.2), semialign-indexed (>=1 && <1.2), serialise, some (>=1.0.1 && <1.1), split (>=0.2.3 && <0.3), syb (>=0.7 && <0.8), template-haskell (>=2.13 && <2.17), text (>=1.2.3 && <1.3), these (>=1.0.1 && <1.2), time (>=1.8.0 && <1.9 || >=1.9.3 && <1.10), transformers (>=0.5.5 && <0.6), transformers-base (>=0.4.5 && <0.5), unix (>=2.7.2 && <2.8), unordered-containers (>=0.2.9 && <0.3), vector (>=0.12.0 && <0.13), xml (>=1.3.14 && <1.4) [details]
License BSD-3-Clause
Author John Wiegley
Maintainer johnw@newartisans.com
Revised Revision 1 made by AntonLatukha at 2021-02-20T16:53:21Z
Category System, Data, Nix
Home page https://github.com/haskell-nix/hnix#readme
Bug tracker https://github.com/haskell-nix/hnix/issues
Source repo head: git clone https://github.com/haskell-nix/hnix
Uploaded by AntonLatukha at 2020-12-09T17:23:17Z
Distributions NixOS:0.17.0
Reverse Dependencies 9 direct, 1 indirect [details]
Executables hnix
Downloads 16299 total (105 in the last 30 days)
Rating 2.25 (votes: 4) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs uploaded by user
Build status unknown [no reports yet]

Readme for hnix-0.11.1

[back to package description]

Chatroom Gitter Hackage Hackage Matrix Builder Bounds Hydra CI Repology page

hnix

Parser, evaluator and type checker for the Nix language written in Haskell.

Contents

Prerequisites

Tooling is WIP, nix-shell and nix-store are still used for their purpose, so, to access them Nix is required to be installed.

Getting Started

# Note: --recursive
git clone --recursive https://github.com/haskell-nix/hnix.git
cd hnix

Cachix prebuild binary caches

If you opt in to use of Nix environment, please enable the official HNix Cachix binary cache:

  1. Go through https://cachix.org/ and set it up.

  2. Run: cachix use hnix

Development using Cabal

Cabal Quickstart.

  1. (Optional), to enter the projects reproducible Nix environment:
nix-shell
  1. Building:
cabal v2-configure
cabal v2-build
  1. Loading the project into ghci REPL:
cabal v2-repl
  1. Testing:
  • Default suite:
cabal v2-test
  • All available tests:
env ALL_TESTS=yes cabal v2-test
  • Selected (list of tests is in tests/Main.hs):
env NIXPKGS_TESTS=yes PRETTY_TESTS=1 cabal v2-test

Building the project

With benchmarks

To run benchmarks:

cabal v2-bench
With profiling

To build hnix with profiling enabled:

cabal v2-configure --enable-tests --enable-profiling --flags=profiling
cabal v2-run hnix -- <args> +RTS -p
With full debug info

To build hnix for debugging, with full tracing output and stack traces:

cabal v2-configure --enable-tests --enable-profiling --flags=profiling --flags=tracing
cabal v2-run hnix -- -v5 --trace <args> +RTS -xc

Note that this going to run quite slowly, but would give the most information as to what happens during parsing & evaluation.

Run HNix

cabal v2-run hnix -- --help

(-- is for separation between cabal & hnix args)

Use of the Nix-build

There is a number of build options to use with nix-build, documentation of them is in: ./default.nix, keys essentially pass-through the Nixpkgs Haskell Lib API.

Options can be used as:

nix-build \
  --arg <option1> <argument1> \
  --arg <option2> <argument2> \
  --argstr <option3> "<strinTypeArg>"

Run benchmarks

nix-build \
  --arg disableOptimization false \
  --arg enableDeadCodeElimination true \
  --arg doStrip true \
  --arg doBenchmark true

With profiling

nix-build \
  --arg disableOptimization false \
  --arg enableDeadCodeElimination true \
  --arg enableLibraryProfiling true \
  --arg enableExecutableProfiling true

With full debug info

nix-build \
  --arg disableOptimization false \
  --arg enableDeadCodeElimination true \
  --arg doBenchmark true \
  --arg doStrip false \
  --arg enableLibraryProfiling true \
  --arg enableExecutableProfiling true
  --arg doTracing true \
  --arg enableDWARFDebugging true

Run the result

./result/bin/hnix

Development status loop with amazing ghcid

ghcid --command="cabal v2-repl --repl-options=-fno-code --repl-options=-fno-break-on-exception --repl-options=-fno-break-on-error --repl-options=-v1 --repl-options=-ferror-spans --repl-options=-j"

(optional) To use projects reproducible environment, wrap ghcid ... command into a nix-shell --command ' '.

For simplicity alias the command in your shell.

Using the HNix REPL

Enter in:

hnix --repl

Evaluate an expression:

hnix --eval -E '(import <nixpkgs> {}).pkgs.hello' --repl

This also binds the evaluated expression result to the input variable, so that variable can be inspected.

Use the :help command for a list of all available REPL commands.

Nix laziness

Nix is a lazy language with the ability of recursion, so by default REPL and eval prints are lazy:

hnix \
  --eval \
  --expr '{ x = true; }'
  
{ x = "<CYCLE>"; }

To disable laziness add the --strict to commands or :set strict in the REPL.

hnix \
  --eval \
  # Strictly \
  --strict \
  --expr '{ x = true; }'
  
{ x = true; }

Contributing

  1. If something in the quests looks interesting, look through the thread and leave a comment taking it, to let others know you're working on it.

  2. You are free to chat with everyone on Gitter.

  3. When the pull request is ready to be submitted, to save time - please, test it with:

git submodule update --init --recursive
nix-shell --run "LANGUAGE_TESTS=yes cabal v2-test"

Please, check that all tests that were passing prior (most probably all tests mentioned in the command) are still passing for the PR, it is faster to check that locally than through CI. It's OK if no new tests are passing.

Evaluating Nixpkgs with HNix

Currently, the main high-level goal is to be able to evaluate all of Nixpkgs:

hnix --eval -E "import <nixpkgs> {}" --find