2016年3月6日日曜日

gentooでstackとyesodをやる

最近、yesod initが変わっちゃったみたい


最近、こうなる
cuomo@karky7 ~ $ yesod init
yesod: The init command has been removed. Please use 'stack new' instead
なんだよ、そうなっちゃってたの?

stackをいれる


stackってライブラリのバージョンセットを管理してくれるツール、便利だけど、gentoo-haskell使っている場合はあんまりうまくない。

Stackageはここ

karky7 ~ # emerge dev-haskell/stack

yesodのscaffoldを作成する


stackコマンドでそれぞれのテンプレートが作成出きるようになる
cuomo@karky7 ~ $ stack templates
chrisdone
franklinchen
ghcjs
ghcjs-old-base
hakyll-template
haskeleton
hspec
new-template
quickcheck-test-framework
rubik
scotty-hello-world
scotty-hspec-wai
servant
servant-docker
simple
simple-hpack
tasty-discover
tasty-travis
yesod-hello-world
yesod-minimal
yesod-mongo
yesod-mysql
yesod-postgres
yesod-postgres-fay
yesod-simple
yesod-sqlite
cuomo@karky7 ~ $ stack templates
ここからyesod-mysqlのテンプレートでalchuプロジェクトのscaffoldを作成する、ghcとかその他のyesodに関係するライブラリがはいっているので追加オプションでその辺を調整する。初回の実行はちょっと時間がかかるよ。
cuomo@karky7 ~/Code/yesod $ stack --system-ghc --no-install-ghc new alchu yesod-mysql
Downloading template "yesod-mysql" to create project "alchu" in alchu/ ...
Using cabal packages:
- alchu/alchu.cabal

Selecting the best among 3 snapshots...

Downloaded lts-5.5 build plan.
Caching build plan
Fetched package index.
Populated index cache.
* Selected lts-5.5

Initialising configuration using resolver: lts-5.5
Writing configuration to file: alchu/stack.yaml
All done.
cuomo@karky7 ~/Code/yesod $
mysqlを起動し、alchuを動かす
karky7 ~ # systemctl start mysqld
karky7 ~ # mysqladmin -u root create alchu
でdevelする
cuomo@karky7 ~ $ cd alchu/
cuomo@karky7 ~/alchu $ yesod devel
これで開発サーバーが起動する

stackとgentoo-haskell


gentoo-haskell使っているとstackを使ってインストールすることはあまりないと思いますが、gentoo-haskellにないライブラリ何かはstackで入れればいいとは思います。 hackportでebuild作っても簡単に入れられるので、どちらでもいいとは思いますが。
ちょっと機能的にかぶるので、ややこしい感は有りますが、バージョンセットを決めてくれたり、まえのcabalよりは統合されていて使いやすいですね。 ちなみに、~/.stackディレクトリに情報がはいっています。
.stack/
├── build-plan
│   └── lts-5.5.yaml
├── build-plan-cache
│   └── x86_64-linux
│       └── lts-5.5.cache
├── config.yaml
├── indices
│   └── Hackage
│       ├── 00-index.cache
│       ├── 00-index.tar
│       └── git-update
│           └── all-cabal-hashes
│               └── README.md
└── templates
    ├── yesod-mysql.hsfiles
        └── yesod-mysql.hsfiles.etag
stackでインストールした場合、この辺に実行プログラムとかがインストールされるようです。

でも、stackは非常に便利なので、みんなで使いましょう。

stackのオプション


こんなに覚えられるわけない...
cuomo@karky7 ~ $ stack --help
stack - The Haskell Tool Stack

Usage: stack [--help] [--version] [--numeric-version] [--docker*] [--nix*]
             ([--verbosity VERBOSITY] | [-v|--verbose]) [--work-dir WORK-DIR]
             [--[no-]system-ghc] [--[no-]install-ghc] [--arch ARCH] [--os OS]
             [--ghc-variant VARIANT] [-j|--jobs JOBS] [--extra-include-dirs DIR]
             [--extra-lib-dirs DIR] [--[no-]skip-ghc-check] [--[no-]skip-msys]
             [--local-bin-path DIR] [--[no-]modify-code-page]
             [--resolver RESOLVER] [--compiler COMPILER] [--[no-]terminal]
             [--stack-yaml STACK-YAML] COMMAND|FILE

Available options:
  --help                   Show this help text
  --version                Show version
  --numeric-version        Show only version number
  --docker*                Run 'stack --docker-help' for details
  --nix*                   Run 'stack --nix-help' for details
  --verbosity VERBOSITY    Verbosity: silent, error, warn, info, debug
  -v,--verbose             Enable verbose mode: verbosity level "debug"
  --work-dir WORK-DIR      Override work directory (default: .stack-work)
  --[no-]system-ghc        Enable/disable using the system installed GHC (on the
                           PATH) if available and a matching version
  --[no-]install-ghc       Enable/disable downloading and installing GHC if
                           necessary (can be done manually with stack setup)
  --arch ARCH              System architecture, e.g. i386, x86_64
  --os OS                  Operating system, e.g. linux, windows
  --ghc-variant VARIANT    Specialized GHC variant, e.g. integersimple (implies
                           --no-system-ghc)
  -j,--jobs JOBS           Number of concurrent jobs to run
  --extra-include-dirs DIR Extra directories to check for C header files
  --extra-lib-dirs DIR     Extra directories to check for libraries
  --[no-]skip-ghc-check    Enable/disable skipping the GHC version and
                           architecture check
  --[no-]skip-msys         Enable/disable skipping the local MSYS installation
                           (Windows only)
  --local-bin-path DIR     Install binaries to DIR
  --[no-]modify-code-page  Enable/disable setting the codepage to support UTF-8
                           (Windows only)
  --resolver RESOLVER      Override resolver in project file
  --compiler COMPILER      Use the specified compiler
  --[no-]terminal          Enable/disable overriding terminal detection in the
                           case of running in a false terminal
  --stack-yaml STACK-YAML  Override project stack.yaml file (overrides any
                           STACK_YAML environment variable)

Available commands:
  build                    Build the package(s) in this directory/configuration
  install                  Shortcut for 'build --copy-bins'
  uninstall                DEPRECATED: This command performs no actions, and is
                           present for documentation only
  test                     Shortcut for 'build --test'
  bench                    Shortcut for 'build --bench'
  haddock                  Shortcut for 'build --haddock'
  new                      Create a new project from a template. Run `stack
                           templates' to see available templates.
  templates                List the templates available for `stack new'.
  init                     Initialize a stack project based on one or more cabal
                           packages
  solver                   Use a dependency solver to try and determine missing
                           extra-deps
  setup                    Get the appropriate GHC for your project
  path                     Print out handy path information
  unpack                   Unpack one or more packages locally
  update                   Update the package index
  upgrade                  Upgrade to the latest stack (experimental)
  upload                   Upload a package to Hackage
  sdist                    Create source distribution tarballs
  dot                      Visualize your project's dependency graph using
                           Graphviz dot
  exec                     Execute a command
  ghc                      Run ghc
  ghci                     Run ghci in the context of package(s) (experimental)
  repl                     Run ghci in the context of package(s) (experimental)
                           (alias for 'ghci')
  runghc                   Run runghc
  runhaskell               Run runghc (alias for 'runghc')
  eval                     Evaluate some haskell code inline. Shortcut for
                           'stack exec ghc -- -e CODE'
  clean                    Clean the local packages
  list-dependencies        List the dependencies
  query                    Query general build information (experimental)
  ide                      IDE-specific commands
  docker                   Subcommands specific to Docker use
  config                   Subcommands specific to modifying stack.yaml files
  image                    Subcommands specific to imaging (EXPERIMENTAL)
  hpc                      Subcommands specific to Haskell Program Coverage
  sig                      Subcommands specific to package signatures
                           (EXPERIMENTAL)