Skip to content

Commit

Permalink
Create nix flake to ensure reproducibility
Browse files Browse the repository at this point in the history
  • Loading branch information
palas committed Jan 31, 2024
1 parent 6fd4305 commit 1e85862
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 21 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/nix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ jobs:
- uses: cachix/install-nix-action@daddc62a2e67d1decb56e028c9fa68344b9b7c2a
with:
nix_path: nixpkgs=channel:nixos-23.05
- run: nix-build shell.nix
- run: nix-shell --run "hlint src && fix-hie && git diff --exit-code hie.yaml"
- run: nix build
- run: nix develop --command bash -c "hlint src && fix-hie && git diff --exit-code hie.yaml"
20 changes: 13 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,37 @@ This version of MarloweScan requires a running instance of the Marlowe Runtime.

## Using Nix

This repo provides a `shell.nix` file that can be used for developing and building MarloweScan without having to worry about dependencies.
This repo provides a `flake.nix` file that can be used for developing and building MarloweScan without having to worry about dependencies.

### Building with Nix

To build MarloweScan with Nix, you can use the `nix-build` command with `shell.nix`:
To build MarloweScan with Nix, you can use the `nix` command:

```bash
nix-build shell.nix
nix build
```

The resulting executable will be made available in `result/bin/marlowe-scan-exe`

Alternatively, you can run MarloweScan directly by writing:

```bash
nix run
```

### Development shell

As usual, you can use the `nix-shell` command to enter the development environment from the root folder of the project:
As usual, you can use the `nix` command to enter the development environment from the root folder of the project:

```bash
nix-shell
nix develop
```

That will make the required Haskell libraries, tools like cabal, stack, the Haskell Language Server, and the `gen-hie` command available in the command line.
That will make the required Haskell libraries, tools like cabal, stack, the Haskell Language Server, and the `fix-hie` command available in the command line.

### Caching dependencies

In order to take advantage of caching, you can use the `https://nixos.org/channels/nixos-22.11` channel. If using a different channel like `unstable`, building may take a while.
In order to take advantage of caching, you can use the `https://nixos.org/channels/nixos-23.05` channel.

## Using Stack

Expand Down
27 changes: 27 additions & 0 deletions flake.lock

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

17 changes: 17 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
description = "MarloweScan - An explorer for Marlowe contracts";

inputs.nixpkgs.url = github:NixOS/nixpkgs/23.05;

outputs = { self, nixpkgs }: {
defaultPackage.x86_64-linux =
with import nixpkgs { system = "x86_64-linux"; };
with haskellPackages;
import ./shell.nix { nixpkgs = nixpkgs; haskellPackages = haskellPackages; };
devShells.x86_64-linux.default =
with import nixpkgs { system = "x86_64-linux"; };
with haskellPackages;
(import ./shell.nix { nixpkgs = nixpkgs; haskellPackages = haskellPackages; }).env;
};

}
15 changes: 3 additions & 12 deletions shell.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ nixpkgs ? import <nixpkgs> {}, compiler ? "ghc92", doBenchmark ? false }:
{ nixpkgs ? import <nixpkgs> {}, haskellPackages ? (import <nixpkgs> {}).haskellPackages }:

let
pkgs = nixpkgs;
Expand Down Expand Up @@ -29,14 +29,5 @@ let
}
'';
};
haskellPackages = if compiler == "default"
then pkgs.haskellPackages
else pkgs.haskell.packages.${compiler};

variant = if doBenchmark then pkgs.haskell.lib.doBenchmark else pkgs.lib.id;

drv = variant (haskellPackages.callPackage f {});

in

if pkgs.lib.inNixShell then drv.env else drv
d = haskellPackages.callPackage f {};
in d // { meta = d.meta // { mainProgram= "marlowe-scan-exe"; }; }

0 comments on commit 1e85862

Please sign in to comment.