2017-04-17 6 views
5

私はしばらくの間、Nixに興味がありました。そして、私はついにそれを新しいhaskellプロジェクトの開始に使用しようと考えました。nixを使ってシンプルなhaskellライブラリを構築する

name: project 
version: 0.1.0.0 
build-type: Simple 
license: MIT 
cabal-version: >= 1.18 

library 
    exposed-modules: Lib 
    build-depends: base < 5 
    hs-source-dirs: src 
    default-language: Haskell2010 

とあなたが見ることができるようにLib.hsが

module Lib where 

hello :: Int -> IO() 
hello x = putStrLn (show x) 

を持って、私はディレクトリ構造徒党ファイルには、次のような内容を持っている

project.cabal 
src/Lib.hs 

で始まった

それは非常に簡単です。私がcabal buildを実行すると、それは満足しているようです。私は何の意味もありませんので、初心者の間違いをしているかもしれません。

これをNixで構築するために、私はhttps://github.com/Gabriel439/haskell-nixを読んで私の情報を得ました。私はcabal2nix . > default.nixを実行して、私のカバールファイルのNix版を入手しました。私は実際にそれを構築するためにrelease.nixファイルを作成しました。次のように2つのファイルの内容は以下のとおりです。

これを実行した後、私はnix-build release.nixを実行し、バック

these derivations will be built: 
    /nix/store/p481alkpm89712n3hnwai0nxhmjrm8b2-project-0.1.0.0.drv 
building path(s) ‘/nix/store/yszy2a6wd88pf6zlw0nw99l5wzvc0s9x-project-0.1.0.0’ 
setupCompilerEnvironmentPhase 
Build with /nix/store/d5w12a8bprd2518xnqp1cwh3rbjiagyx-ghc-8.0.1. 
unpacking sources 
unpacking source archive /nix/store/fsn4b9w54h2jdpv546nwvy82vnkszl1w-project 
source root is project 
patching sources 
compileBuildDriverPhase 
setupCompileFlags: -package-db=/tmp/nix-build-project-0.1.0.0.drv-0/package.conf.d -j4 -threaded 
[1 of 1] Compiling Main    (/nix/store/4mdp8nhyfddh7bllbi7xszz7k9955n79-Setup.hs, /tmp/nix-build-project-0.1.0.0.drv-0/Main.o) 
Linking Setup ... 
... 
... 
Building project-0.1.0.0... 
Preprocessing library project-0.1.0.0... 
dist/build/Lib_o_split: getDirectoryContents: does not exist (No such file or 
directory) 
builder for ‘/nix/store/p481alkpm89712n3hnwai0nxhmjrm8b2-project-0.1.0.0.drv’ failed with exit code 1 
error: build of ‘/nix/store/p481alkpm89712n3hnwai0nxhmjrm8b2-project-0.1.0.0.drv’ failed 
を得たrelease.nix

let 
    pkgs = import <nixpkgs> { }; 
in 
    pkgs.haskellPackages.callPackage ./default.nix { } 

default.nix

{ mkDerivation, base, stdenv }: 
mkDerivation { 
    pname = "project"; 
    version = "0.1.0.0"; 
    src = ./.; 
    libraryHaskellDepends = [ base ]; 
    license = stdenv.lib.licenses.mit; 
} 

どちらがいいですか。私はここで何の間違いをしていますか?私はライブラリの代わりに実行可能ファイルを作成していたのと同じような試みで成功しているので、それはそれと関係があると思われます。私が従っていたgithubリポジトリも実行可能ファイルを使用していました。

+0

暗いところで撮影したビットですが、default.nixファイルに 'enableSplitObjs = false;'を追加しても何も役に立ちませんか? 'error:assertion failed at..'でエラーが出たら、代わりに' enableDeadCodeElimination = false; 'を試してみることができますか? – ppb

+0

@ppb 'enableSplitObjs = false;'正しくビルドされました。なぜそれは物事を修正するのですか?すべてのhaskell nixオプションが文書化されている場所はありますか?また、これを答えさせたら、私はそれを受け入れるでしょう。 – phil

答えて

0

私はper cabal's manual、デフォルトNIXによって、無地の秘密結社とは異なり、分割オブジェクトを使用して、任意のHaskellのプロジェクトをビルドしようとしています信じて:

--enable-split-objs

Use the GHC -split-objs feature when building the library. This reduces the final size of the executables that use the library by allowing them to link with only the bits that they use rather than the entire library. The downside is that building the library takes longer and uses considerably more memory.

私はそれがあなたの上に失敗することができる理由として、あまりにもわからないんだけど

enableSplitObjs = false;

enableDeadCodeElimination = false;

:システムが、あなたのnixpkgsのバージョンに依存しての1を追加することによって無効にすることができます

を派生します。

その他の属性/オプションのリストについては、https://github.com/NixOS/nixpkgs/blob/master/pkgs/development/haskell-modules/generic-builder.nixを参照してください。残念ながら、私は残念なことに、それらを詳細に説明する公式の文書は認識していません。

関連する問題