Using the zero-to-nix flake template for Haskell, I packaged a simple Haskell program. I can run the flake just fine.
❯ nix run "git+https://codeberg.org/mhwombat/hello-flake-haskell"
Hello from Haskell!
Now I want to make the program available in a shell:
❯ cat shell.nix
with (import <nixpkgs> {});
let
hello-flake-haskell = (builtins.getFlake git+https://codeberg.org/mhwombat/hello-flake-haskell).packages.${builtins.currentSystem}.default;
in
mkShell {
buildInputs = [
hello-flake-haskell
];
}
But when I try to enter the shell, I get an error:
❯ nix-shell
bash: /nix/store/ffbpbxg9cyj8nvj84d1si7k0g9ddyl0i-ghc-9.0.2-with-packages: Is a directory
bash: pop_var_context: head of shell_variables not a function context
bash: pop_var_context: head of shell_variables not a function context
I suspected that this might be an IFD problem, so I also tried nix-shell --allow-import-from-derivation
, but I got the same error. How do I fix the problem?
In case it helps, here’s the flake.nix
.
{
description = "a flake for a simple Haskell program";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-22.11";
};
outputs = { self, nixpkgs }:
let
nameValuePair = name: value: { inherit name value; };
genAttrs = names: f: builtins.listToAttrs (map (n: nameValuePair n (f n)) names);
allSystems = [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin" ];
forAllSystems = f: genAttrs allSystems (system: f {
pkgs = import nixpkgs { inherit system; };
});
in
{
packages = forAllSystems ({ pkgs }: {
default = pkgs.haskellPackages.developPackage {
name = "hello-flake-haskell";
root = ./.;
};
});
};
}