Skip to content

Commit

Permalink
Merge branch 'master' into gabriella/fix_build
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabriella439 committed Feb 22, 2023
2 parents 80f2ab3 + c686098 commit a9d9ac2
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 36 deletions.
13 changes: 8 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,19 @@ jobs:
run: nix-shell --pure ghc.nix/shell.nix --command "hadrian/build -j --flavour=quickest test --test-root-dirs=testsuite/tests/programs"

- name: Run nix develop - Boot and Configure
run: nix develop -Lv ghc.nix# -c bash -c "./boot && configure_ghc"
run: nix develop -Lv --fallback ghc.nix# -c bash -c "./boot && configure_ghc"

- name: Run nix develop - Build Hadrian
run: nix develop -Lv ghc.nix# -c bash -c "pushd hadrian; cabal new-update; cabal new-build -j all; popd"
run: nix develop -Lv --fallback ghc.nix# -c bash -c "pushd hadrian; cabal new-update; cabal new-build -j all; popd"

- name: Run nix develop - hadrian/ghci
run: nix develop -Lv ghc.nix# -c bash -c "echo :q | hadrian/ghci | tail -n2 | grep 'Ok,'"
run: nix develop -Lv --fallback ghc.nix# -c bash -c "echo :q | hadrian/ghci | tail -n2 | grep 'Ok,'"

- name: Run nix develop - Build GHC
run: nix develop -Lv ghc.nix# -c bash -c "hadrian/build -j --flavour=quickest"
run: nix develop -Lv --fallback ghc.nix# -c bash -c "hadrian/build -j --flavour=quickest"

- name: Run nix develop - Test GHC (by running a testsuite subset)
run: nix develop -Lv ghc.nix# -c bash -c "hadrian/build -j --flavour=quickest test --test-root-dirs=testsuite/tests/programs"
run: nix develop -Lv --fallback ghc.nix# -c bash -c "hadrian/build -j --flavour=quickest test --test-root-dirs=testsuite/tests/programs"

- name: check formatting
run: nix build -Lv --fallback ghc.nix#formatter.x86_64-linux
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
\#*
.\#*
.~*
result*
103 changes: 83 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,35 @@ an excellent place to start.

To enter an environment without cloning this repository you can run:

```sh
nix-shell https://github.com/alpmestan/ghc.nix/archive/master.tar.gz --attr devShells.<your-system>.default
```
nix-shell https://github.com/alpmestan/ghc.nix/archive/master.tar.gz
```
or, with flakes enabled:
where `<your-system>` would be the nix name of your system, in the typical case this is one of
- `x86_64-linux` (for `x86_64` Linux systems)
- `aarch64-linux` (for ARM Linux systems)
- `x86_64-darwin` (for old macs that do not have apple silicon)
- `aarch64-darwin` (for macs with apple silicon)

Hence, an invocation on an `x86_64` Linux system would look like this:
```sh
nix-shell https://github.com/alpmestan/ghc.nix/archive/master.tar.gz --attr devShells.x86_64-linux.default
```

This repository is flakes enabled, which means, that you can more easily get a `devShell` using:

```sh
nix develop github:alpmestan/ghc.nix
```

## Building GHC

These commands assume you have cloned this repository
to `~/ghc.nix`. `default.nix` has many parameters, all
to `~/ghc.nix`. `shell.nix` has many parameters, all
of them optional. You should take a look at `ghc.nix`
for more details.


``` sh
```sh
$ echo "BuildFlavour = quick" > mk/build.mk
$ cat mk/build.mk.sample >> mk/build.mk
$ nix-shell ~/ghc.nix/shell.nix --run './boot && ./configure $CONFIGURE_ARGS && make -j4'
Expand All @@ -46,7 +58,7 @@ argument. See also https://unix.stackexchange.com/a/19533/61132.

You can alternatively use Hadrian to build GHC:

``` sh
```sh
$ nix-shell ~/ghc.nix/shell.nix
# from the nix shell:
$ ./boot && ./configure $CONFIGURE_ARGS # In zsh, use ${=CONFIGURE_ARGS}
Expand All @@ -72,13 +84,13 @@ You can also use `ghc.nix` to provide the right version of `ghcide` if you
want to use `ghcide` whilst developing on GHC. In order to do so, pass the `withIde`
argument to your `nix-shell` invocation.

```
```sh
nix-shell ~/.ghc.nix/shell.nix --arg withIde true
```

## Running `./validate`

``` sh
```sh
$ nix-shell ~/ghc.nix/shell.nix --pure --run 'THREADS=4 ./validate'
```

Expand All @@ -88,7 +100,7 @@ See other flags of `validate` by invoking `./validate --help` or just by reading

It's trivial!

``` sh
```sh
$ nix-shell ~/ghc.nix/shell.nix --arg nixpkgs '(import <nixpkgs> {}).pkgsi686Linux'
```

Expand All @@ -114,26 +126,77 @@ The cache contains Linux x64 binaries of all packages that are used during a def
- *to use a certain commit for any of the inputs*: use flag `--override-input`, e.g.
```sh
nix develop --override-input all-cabal-hashes "github:commercialhaskell/all-cabal-hashes/f4b3c68d6b5b128503bc1139cfc66e0537bccedd"
```
- if you plan to upstream your modifications to `ghc.nix`, don't forget to run the formatter (`nix fmt`)
```
this is not yet support in `flake-compat` mode, you will have to manually set the version in the `flake.nix` by appending
`/your-commit-hash` to the input you want to change, then running `nix flake lock --update-input input-you-want-to-update`.
Of course you can also just manually pass your own `nixpkgs` version to the `shell.nix`, this will override the one
provided by the flake.
- if you plan to upstream your modifications to `ghc.nix`, don't forget to run the formatter using `nix fmt`

## Flake support

`ghc.nix` now also has basic flake support, `nixpkgs` and `nixpkgs-unstable` are pinned in the flake inputs
and the cabal hashes are pinned in the toplevel flake (not via the flake inputs because that is currently not
possible in an idiomatic way)
`ghc.nix` now also has basic flake support, `nixpkgs`, `nixpkgs-unstable` and the `cabal-hashes` are pinned in the flake inputs.

To format all nix code in this repo, run `nix fmt`, to enter a development shell, run `nix develop`.
To format all nix code in this repository, run `nix fmt`, to enter a development shell, run `nix develop`.
- To change the settings of the `devShell` to your liking, just adjust the `userSettings` attribute-set in the top-level flake.
- To format all nix code in this repo, run `nix fmt`, to enter a development shell, run `nix develop`.

## direnv
## Legacy nix-commands support

With nix-direnv support, it is possible to make [`direnv`](https://github.com/direnv/direnv/) load `ghc.nix`
We use `flake-compat` to ensure compatibility of the old nix commands with the new flake commands and to use the flake inputs pinned by
`nix` itself. Unfortunately there is a shortcoming of the current implementation of the flake nix commands that makes it so that you
cannot pass arguments to the `devShell`s. To ensure backwards compatibility, we call a function that we keep as flake output from the
`./shell.nix` file. Most importantly, this means that **the `shell.nix` in this repo doesn't behave like a normal `flake-compat` shell
but rather like a legacy `shell.nix` that can indeed be passed arguments**.
The `default.nix` behaves just like you would expect it to behave with the use of `flake-compat`.

The following table shows what `./ghc.nix` can be configured with; the first column is the name of the attribute to be configured, the second
argument the description of that argument, the third the default value for that argument and the third one, whether or not the `flake.nix`
takes over orchestration of this attribute, this is the case if they're either pinned by the lock-file (e.g. `nixpkgs`) or can introduce impurity
(e.g. `system`)

If you do not want to pass your arguments with `--arg`, but rather capture your passed arguments in a `.nix` file, you can locally create a
file, say `shell.nix` with the following contents:

```nix
import ./path/to/ghc.nix/shell.nix {
withHadrianDeps = true;
withIde = true;
# ... and so on
}
```
be careful to specify the path to the `shell.nix`, not to the `default.nix`.

| attribute-name | description | default | orchestrated `flake.nix` |
| -- | -- | -- | -- |
| `system` | the system this is run on | `builtins.currentSystem` or flake system ||
| `nixpkgs` | the stable `nixpkgs` set used | `nixpkgs` as pinned in the lock-file ||
| `nixpkgs-unstable` | the unstable `nixpkgs` set used | `nixpkgs-unstable` as pinned in the lock-file ||
| `all-cabal-hashes` | the `all-cabal-hashes` version used | `all-cabal-hashes` as pinned in the lock-file ||
| `bootghc` | the bootstrap `ghc` version | `"ghc924"` ||
| `version` | the version of `ghc` to be bootstrapped | `"9.3"` ||
| `hadrianCabal` | where `hadrian` is to be found | `(builtins.getEnv "PWD") + "/hadrian/hadrian.cabal"` ||
| `useClang` | whether Clang is to be used for C compilation | `false` ||
| `withLlvm` | whether `llvm` should be included in the `librarySystemDepends` | `false` ||
| `withDocs` | whether to include dependencies to compile docs | `true` ||
| `withGhcid` | whether to include `ghci` | `false` ||
| `withIde` | whether to include `hls` | `false` ||
| `withHadrianDeps` | whether to include dependencies for `hadrian` | `false` ||
| `withDwarf` | whether to enable `libdw` unwinding support | `nixpkgs.stdenv.isLinux` ||
| `withNuma` | whether to enable `numa` support | `nixpkgs.stdenv.isLinux` ||
| `withDtrace` | whether to include `linuxPackage.systemtap` | `nixpkgs.stdenv.isLinux` ||
| `withGrind` | whether to include `valgrind` | `true` ||
| `withEMSDK` | whether to include `emscripten` for the js-backend | `false` ||

## `direnv`

With `nix-direnv` support, it is possible to make [`direnv`](https://github.com/direnv/direnv/) load `ghc.nix`
upon entering your local `ghc` directory. Just put a `.envrc` containing `use flake /home/theUser/path/to/ghc.nix#`
in the ghc directory. This works for all flake urls, so you can also put `use flake github:alpmestan/ghc.nix#` in
in the `ghc` directory. This works for all flake URLs, so you can also put `use flake github:alpmestan/ghc.nix#` in
there and it should work.

(*Note*: at the time of writing `.direnv` is not part of the `.gitignore` in ghc, so be careful to not accidentally
commit it, it's the local cache of your development shell which makes loading it upon entering the directory instant)
(*Note*: at the time of writing `.direnv` is not part of the `.gitignore` in `ghc`, so be careful to not accidentally
check it out, it's the local cache of your development shell which makes loading it upon entering the directory instant)

## TODO

Expand Down
27 changes: 18 additions & 9 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,30 @@
};
};

outputs = inputs@{ self, nixpkgs, nixpkgs-unstable, all-cabal-hashes, ... }: with nixpkgs.lib; let
supportedSystems = nixpkgs.lib.systems.flakeExposed;
outputs = { self, nixpkgs, nixpkgs-unstable, all-cabal-hashes, ... }: with nixpkgs.lib; let
supportedSystems = systems.flakeExposed;
perSystem = genAttrs supportedSystems;

defaultSettings = system: {
inherit nixpkgs nixpkgs-unstable system;
all-cabal-hashes = all-cabal-hashes.outPath;
};

# NOTE: change this according to the settings allowed in the ./ghc.nix file and described
# in the `README.md`
userSettings = {
withHadrianDeps = true;
withIde = true;
};
in
{
devShells = perSystem (system: rec {
ghc-nix = import ./ghc.nix {
inherit nixpkgs nixpkgs-unstable system;
all-cabal-hashes = all-cabal-hashes.outPath;
withHadrianDeps = true;
withIde = true;
};

ghc-nix = import ./ghc.nix (defaultSettings system // userSettings);
default = ghc-nix;
});
formatter = perSystem (system: (import nixpkgs { inherit system; }).nixpkgs-fmt);

# NOTE: this attribute is used by the flake-compat code to allow passing arguments to ./ghc.nix
legacy = args: import ./ghc.nix (defaultSettings args.system // args);
};
}
7 changes: 5 additions & 2 deletions shell.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
(import
args@
{ system ? builtins.currentSystem or "unknown-system"
, ...
}: (import
(
let lock = builtins.fromJSON (builtins.readFile ./flake.lock); in
fetchTarball {
Expand All @@ -7,4 +10,4 @@
}
)
{ src = ./.; }
).shellNix
).defaultNix.outputs.legacy (args // { inherit system; })

0 comments on commit a9d9ac2

Please sign in to comment.