I have two repos with a basic “hello world” programs, one written in C, one written in Haskell. Both build and execute just fine. I can add the C version to my NixOS configuration, and it is installed and available as a command. I run into problems when I try to add the Haskell version to my NixOS configuration.
Running nix flake show
on the C version, I see that the module name is hello-nix-flake.nixosModules.hello
.
$ nix flake show github:mhwombat/hello-nix-flake
github:mhwombat/hello-nix-flake/089373e73f6a0401a4ed16f323a48b15cfde17e0
├───checks
. . .
├───nixosModules
│ └───hello: NixOS module
. . .
I add that to my NixOS configuration, rebuild, and my custom hello
is now available as a command. I feel victorious. I am the flake master! Mwah ha ha! Alas, pride goeth before a fall.
Next I try running nix flake show
on the Haskell version. (The flake.nix
file is based on templates#haskell-hello
.)
$ nix flake show github:mhwombat/hello-haskell-flake
github:mhwombat/hello-haskell-flake/dab155b5b631eb7f301b1e88821b3a4f9c2c23a4
├───checks
│ └───x86_64-linux
error: cannot build '/nix/store/kl94d5zyndm1vv8am6swjrn5dsm2msp7-cabal2nix-hello-haskell-flake.drv' during evaluation because the option 'allow-import-from-derivation' is disabled
(use '--show-trace' to show detailed location information)
I don’t know why the extra flag --allow-import-from-derivation is needed, but I take the hint:
$ nix flake show github:mhwombat/hello-haskell-flake --allow-import-from-derivation
github:mhwombat/hello-haskell-flake/dab155b5b631eb7f301b1e88821b3a4f9c2c23a4
├───checks
│ └───x86_64-linux
│ └───hello-haskell-flake: derivation 'l6z88yi6vdyxp5hxy7xppi4j2xkdwwiw-source-0.0.0'
├───defaultPackage
│ └───x86_64-linux: package 'l6z88yi6vdyxp5hxy7xppi4j2xkdwwiw-source-0.0.0'
├───devShell
│ └───x86_64-linux: development environment 'ghc-shell-for-l6z88yi6vdyxp5hxy7xppi4j2xkdwwiw-source-0.0.0-0'
├───overlay: Nixpkgs overlay
└───packages
└───x86_64-linux
└───hello-haskell-flake: package 'l6z88yi6vdyxp5hxy7xppi4j2xkdwwiw-source-0.0.0'
There’s no nixosModules
section, so I can’t tell what to add to my NixOS configuration (also a flake) to install this on my system.
Note that I can build the flake at the command line, and run it just fine. For reference, here’s the flake:
{
# inspired by: https://serokell.io/blog/practical-nix-flakes#packaging-existing-applications
description = "A Hello World in Haskell with a dependency and a devShell";
inputs.nixpkgs.url = "nixpkgs";
outputs = { self, nixpkgs }:
let
supportedSystems = [ "x86_64-linux" ];
forAllSystems = f: nixpkgs.lib.genAttrs supportedSystems (system: f system);
nixpkgsFor = forAllSystems (system: import nixpkgs {
inherit system;
overlays = [ self.overlay ];
});
in
{
overlay = (final: prev: {
hello-haskell-flake = final.haskellPackages.callCabal2nix "hello-haskell-flake" ./. {};
});
packages = forAllSystems (system: {
hello-haskell-flake = nixpkgsFor.${system}.hello-haskell-flake;
});
defaultPackage = forAllSystems (system: self.packages.${system}.hello-haskell-flake);
checks = self.packages;
devShell = forAllSystems (system: let haskellPackages = nixpkgsFor.${system}.haskellPackages;
in haskellPackages.shellFor {
packages = p: [self.packages.${system}.hello-haskell-flake];
withHoogle = true;
buildInputs = with haskellPackages; [
haskell-language-server
ghcid
cabal-install
];
# Change the prompt to show that you are in a devShell
shellHook = "export PS1='\\e[1;34mdev > \\e[0m'";
});
};
}