Skip to content

Commit

Permalink
Modern nix setup with flakes (#2474)
Browse files Browse the repository at this point in the history
Modern nix setup with flakes
  • Loading branch information
alex-mckenna authored Jun 6, 2023
1 parent 4296578 commit b80511b
Show file tree
Hide file tree
Showing 24 changed files with 857 additions and 437 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,6 @@ docs/env

# build_clash_dev.sh output
clash-dev.result

# direnv
.envrc
38 changes: 37 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,43 @@ stack run -- clash
Or [use Nix](https://nixos.org/nix/download.html) to get a shell with the `clash` and `clashi` binaries on your PATH:

```bash
nix-shell
# Start the default dev shell
nix develop .

# Start a dev shell with a specific GHC version
nix develop .#ghc961
```

You will need a modern version of nix with support for the new-style `nix`
command and flakes (2.4 or newer). Support for these must still be manually
enabled, this can be done by setting

```
experimental-features = nix-command flakes
```

in your `nix.conf`.

To automatically enter and exit the `nix` environment on directory change, you
can install [`direnv`](https://direnv.net/) and
[`nix-direnv`](https://github.com/nix-community/nix-direnv) and write the
following to a `.envrc` file in the root of this repository:

```
use flake
watch_file nix/*
```

Upon adding or changing this file you must `direnv allow` in order for the file
to be automatically loaded / reloaded on project changes.

Individual packages / applications can also be built or run using the `nix
build` and `nix run` commands, i.e.

```
nix build .#clash-ghc
nix run .#clashi
```

# Related libraries and initiatives
Expand Down
22 changes: 22 additions & 0 deletions clash-cores/clash-cores.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ flag haddock
default: False
manual: True

flag nix
description:
Are we building this package from nix
default: False
manual: True

common basic-config
default-language: Haskell2010

Expand Down Expand Up @@ -63,6 +69,22 @@ common basic-config
if flag(haddock)
ghc-options:
-fdefer-type-errors
elif flag(nix)
-- It's absolutely grimy, but if we don't specify the `-package` flags here
-- then when nix eventually calls `./Setup register` on the package it will
-- still pass the `-fplugin` options to GHC and fail to create the package
-- registation file needed to finish the `installPhase`.
--
-- These flags are something we NEVER want to manually specify in a normal
-- build, since correctly configuring this kind of thing should be solely
-- left to cabal as a build tool.
ghc-options:
-package ghc-typelits-extra
-fplugin GHC.TypeLits.Extra.Solver
-package ghc-typelits-knownnat
-fplugin GHC.TypeLits.Normalise
-package ghc-typelits-natnormalise
-fplugin GHC.TypeLits.KnownNat.Solver
else
ghc-options:
-fplugin GHC.TypeLits.Extra.Solver
Expand Down
6 changes: 0 additions & 6 deletions clash-cores/default.nix

This file was deleted.

7 changes: 0 additions & 7 deletions clash-ghc/default.nix

This file was deleted.

1 change: 0 additions & 1 deletion clash-ghc/shell.nix

This file was deleted.

6 changes: 0 additions & 6 deletions clash-lib-hedgehog/default.nix

This file was deleted.

6 changes: 0 additions & 6 deletions clash-lib/default.nix

This file was deleted.

1 change: 0 additions & 1 deletion clash-lib/shell.nix

This file was deleted.

6 changes: 0 additions & 6 deletions clash-prelude-hedgehog/default.nix

This file was deleted.

6 changes: 0 additions & 6 deletions clash-prelude/default.nix

This file was deleted.

1 change: 0 additions & 1 deletion clash-prelude/shell.nix

This file was deleted.

16 changes: 11 additions & 5 deletions default.nix
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
{ nixpkgs ? import ./nix/nixpkgs.nix {} }:

with nixpkgs.pkgs.haskellPackages;

{ inherit clash-ghc clash-lib clash-prelude clash-cores; }
(import
(
let lock = builtins.fromJSON (builtins.readFile ./flake.lock);
in
fetchTarball {
url = "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz";
sha256 = lock.nodes.flake-compat.locked.narHash;
}
)
{ src = ./.; }
).defaultNix
146 changes: 146 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit b80511b

Please sign in to comment.