本文介绍了从堆栈项目生成Nix包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个软件应用程序,可以用 stack 来构建和安装。我想为Linux和Mac提供一个二进制包。为此,我正在考虑 nix ,因为它可以在Linux和Mac中使用。这将节省我不得不维护两种包装类型的麻烦。

I have a software application that can be built and installed with stack. I would like to offer a binary package as well for Linux and Mac. For this purpose I'm considering nix, since, among other things, it can be used in Linux and Mac. This will save me the trouble of having to maintain two package types.

在阅读了如何定义 nix 包裹之后,我希望基于项目的 stack 可以使用如下配置来构建:

After reading about how nix packages are defined, I would expect that a stack based project could be built with a configuration that would look like:

{ stdenv, fetchurl, stack }: # we need to depend on stack

stdenv.mkDerivation { 
  name = "some-haskell-package-0.1"; 
  builder = ./builder.sh; # here we would call `stack install` 
  src = fetchurl {  # ...
  };
}

查看网上可用的资源,我找不到任何可能的解释做完了。我不知道这是否意味着 stack 和 nix 不能用于这种方式。

Looking at the resources available online, I cannot find any description of how this could be done. I don't know if this means that stack and nix are not intended to be used in this way.

手册中唯一能找到的是,以及,我可以使用以下步骤构建和安装一个简单的堆栈项目:

With this recent merge, I am able to build and installed a simple stack project using following steps:


  1. 创建新的 hello > > stack new hello

  2. 将以下行添加到堆栈.yaml

nix:
  enable: true
  shell-file: default.nix


  • 创建 default.nix

    with (import <nixpkgs> { });
    
    haskell.lib.buildStackProject {
      name = "hello";
      src = ./.;
    }
    


  • 此时,我可以运行 nix-build 来构建项目,结果将在 ./ result / bin / hello-exe

    At this point, I am able to run nix-build to build the project and result will be at ./result/bin/hello-exe

    如果我想安装,我会运行 nix-env -i -f default.nix

    If I want to install, I would run nix-env -i -f default.nix

    注意: nix-build 会每次下载堆栈的构建计划它会运行。

    Side note: nix-build will download stack's build plan every time it run.

    我想在进行更改时增量构建项目,因此我主要放在shell中并调用 stack build 那里。

    I want to incrementally build my project while making changes so I mainly just drop in the shell and call stack build there.

    这篇关于从堆栈项目生成Nix包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

    09-24 21:08