Skip to content

Add Nix flake for Cabal-based development environment - #123

Open
yjymosheng wants to merge 4 commits into
moocfi:masterfrom
yjymosheng:add-nix-flake-cabal-support
Open

Add Nix flake for Cabal-based development environment#123
yjymosheng wants to merge 4 commits into
moocfi:masterfrom
yjymosheng:add-nix-flake-cabal-support

Conversation

@yjymosheng

Copy link
Copy Markdown

Provide a Nix flake that sets up a GHC 9.2.8 development shell with cabal-install, HLS, and two convenience wrappers:

  • cabal-build: runs cabal v2-build in the exercises/ directory
  • cabal-test: runs cabal v2-exec runhaskell <file> in exercises/

This allows NixOS users to run exercises with Cabal without needing Stack. The existing Stack workflow is not affected.

Usage:
nix develop
cabal-build
cabal-test exercises/Set1Test.hs

Provide a Nix flake that sets up a GHC 9.2.8 development shell with
cabal-install, HLS, and two convenience wrappers:

- cabal-build: runs `cabal v2-build` in the exercises/ directory
- cabal-test: runs `cabal v2-exec runhaskell <file>` in exercises/

This allows NixOS users to run exercises with Cabal without needing
Stack. The existing Stack workflow is not affected.

Usage:
  nix develop
  cabal-build
  cabal-test exercises/Set1Test.hs
Provide a Nix flake that sets up a GHC 9.2.8 development shell with
cabal-install, HLS, and two convenience wrappers:

- cabal-build: runs `cabal v2-build` in the exercises/ directory
- cabal-test: runs `cabal v2-exec runhaskell <file>` in exercises/

This allows NixOS users to run exercises with Cabal without needing
Stack. The existing Stack workflow is not affected.

Usage:
  nix develop
  cabal-build
  cabal-test exercises/Set1Test.hs
@yjymosheng
yjymosheng force-pushed the add-nix-flake-cabal-support branch from 89a17bb to 9b60e01 Compare June 7, 2026 15:28
@yjymosheng

Copy link
Copy Markdown
Author

Some images are used to demonstrate that the intended use is normal and does not affect the normal use of non-NixOS stacks.

image image

…RARY_PATH

- Replace hardcoded nix store path with `git rev-parse --show-toplevel`
  to avoid read-only filesystem issue
- Use realpath in cabal-test to resolve file arguments before cd
- Add LD_LIBRARY_PATH for zlib to fix libz.so warning
@yjymosheng

yjymosheng commented Jun 8, 2026

Copy link
Copy Markdown
Author

While adjusting the PR, I saw some issues that already exist in the Issue ,so added a README to support the usage instructions for Cabal and Nix.

@yjymosheng
yjymosheng force-pushed the add-nix-flake-cabal-support branch 3 times, most recently from 13fd264 to 5217e0f Compare June 9, 2026 15:06
@yjymosheng
yjymosheng requested a review from abdivasiyev June 9, 2026 15:09
@yjymosheng

Copy link
Copy Markdown
Author

Sorry for the additional review request. I just rebased and cleaned up the commit history. The original history was a bit messy, so out of a desire for cleanliness, I cleaned it up.

@abdivasiyev abdivasiyev left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@opqdonut

Copy link
Copy Markdown
Collaborator

This looks ok. I'll try to merge this soon. Merging needs a bit of extra work since the private repository that this repository is generated from needs to be updated to match.

@yjymosheng

Copy link
Copy Markdown
Author

This looks ok. I'll try to merge this soon. Merging needs a bit of extra work since the private repository that this repository is generated from needs to be updated to match.看起来没问题。我会尽快合并。合并需要一些额外的工作,因为生成此仓库的私有仓库需要更新以与之匹配。

Got it.

@AfkaraLP

Copy link
Copy Markdown

You should maybe update the .gitignore to allow commiting the flake.lock file (!flake.lock) else direnv will keep trying to rewrite the flake lock file as it does not see it

@yjymosheng

Copy link
Copy Markdown
Author

You should maybe update the .gitignore to allow commiting the flake.lock file (!flake.lock) else direnv will keep trying to rewrite the flake lock file as it does not see it您应该更新 .gitignore 文件,允许提交 flake.lock 文件( !flake.lock ),否则 direnv 会一直尝试重写 flake lock 文件,因为它找不到该文件。

  1. I wasn't sure about the "not found" scenario - direnv allow automatically generates flake.lock on first run, so there shouldn't be any issue.

  2. Since nixos-24.05 is a stable branch with no updates for ~2 years, I didn't think reproducibility would be a practical concern.

  3. My initial preference was to keep changes to the original setup minimal. But you're right that including the lock file is the better practice, so I've added it . However, it depends on the onwer's idea.

@yjymosheng

yjymosheng commented Jun 23, 2026

Copy link
Copy Markdown
Author

Additional change : I also removed the shellHook that attempted to auto-run cabal update . It wasn't working reliably (likely due to my misunderstanding of cabal's behavior), so I replaced it with a note in the README instead. This also slightly improves shell startup time.


+ Once inside the Nix shell, you can use the Cabal commands described above. **If you encounter issues with missing packages, try running `cabal update` first to refresh the Hackage index.**

If you encounter issues with missing packages, try running cabal update first to refresh the Hackage index.

The above is the main content that has been added.

@yjymosheng
yjymosheng force-pushed the add-nix-flake-cabal-support branch from 5217e0f to 8c15429 Compare June 23, 2026 02:07
@yjymosheng
yjymosheng force-pushed the add-nix-flake-cabal-support branch from 8c15429 to b45c907 Compare June 23, 2026 02:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants