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}"
Then I copied my haskell project.
ADD haskell-project /opt/haskell-project
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
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{})
Build the nix package
RUNnix-build
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}");}}
Top comments(0)
For further actions, you may consider blocking this person and/orreporting abuse