Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Ingun 전인건
Ingun 전인건

Posted on

     

Azure Function app that runs Haskell Nix package

I built a containerized Azure Function App that internlly runs a haskell program packaged with Nix.

I followedCreate your first containerized functions on Azure Container Apps to make a scaffold. Runtime could be anything than can run sub process, which is everything. So I choose dotnet.

And at the end of the generated Dockerfile, I added some nix layers.

# Basic runtime to install nixRUNaptinstall-y xz-utils curlRUNbash-c"sh <(curl -L https://nixos.org/nix/install) --daemon --yes"# Update PATH to include nix toolsENV PATH="/home/.nix-profile/bin:/nix/var/nix/profiles/default/bin:${PATH}"
Enter fullscreen modeExit fullscreen mode

Then I copied my haskell project.

ADD haskell-project /opt/haskell-project
Enter fullscreen modeExit fullscreen mode

Create haskell package usingcabal2nix. I callnix-collect-garbage to reduce the size of docker layer.

RUNnix-shell-p cabal2nix--run'cabal2nix --no-check /opt/haskell-project > /opt/haskell-project/foo.nix'&& nix-collect-garbage
Enter fullscreen modeExit fullscreen mode

Thedefault.nix would look like this. It calls the haskell package and wrap it withjustStaticExecutables to leave only runtime dependencies.

letp=(import<nixpkgs>{}).pkgs;inp.haskell.lib.compose.justStaticExecutables(p.haskellPackages.callPackage./foo.nix{})
Enter fullscreen modeExit fullscreen mode

Build the nix package

RUNnix-build
Enter fullscreen modeExit fullscreen mode

In the Function implementation, run the hasell executable as a subprocess

usingSystem.Diagnostics;using(Processhs=newProcess()){hs.StartInfo.UseShellExecute=true;hs.StartInfo.FileName="/opt/haskell-project/result/bin/exe";hs.Start();awaiths.WaitForExitAsync();if(hs.ExitCode!=0){thrownewException($"haskell subprocess failed{hs.ExitCode}");}}
Enter fullscreen modeExit fullscreen mode

Top comments(0)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

🇰🇷Developer/Mathematics Enthusiast/Painter
  • Location
    Seoul, South Korea
  • Joined

More fromIngun 전인건

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp