Skip to content

Commit

Permalink
Merge pull request #43 from Liqwid-Labs/t4/offchain-shell-hook
Browse files Browse the repository at this point in the history
Add `shell.shellHook` and `pkgs` options to offchain module
  • Loading branch information
emiflake authored Jan 25, 2023
2 parents 6ece419 + 2df395d commit 72d18a5
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 12 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ This format is based on [Keep A Changelog](https://keepachangelog.com/en/1.0.0).

## 2.3.0 - 2023-01-25

- Added `shell.shellHook`, `pkgs`, and `runtime.exposeConfig` options in offchain module

- Fix inclusion of checks when no related project exists.

## 2.2.2 - 2023-01-16
Expand Down
59 changes: 47 additions & 12 deletions nix/offchain.nix
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@ in
'';
default = [ ];
};
shellHook = lib.mkOption {
type = types.lines;
description = ''
Shell code to run when the shell is started.
Added in: 2.3.0.
'';
default = "";
};
};
};

Expand Down Expand Up @@ -166,6 +175,18 @@ in
type = types.attrsOf types.anything;
default = { };
};

exposeConfig = lib.mkOption {
description = ''
Whether to expose the runtime config as an attribute set in
`packages`. Config is not a package so you may want to set it
to false.
Added in: 2.3.0.
'';
type = types.bool;
default = true;
};
};
};

Expand All @@ -181,6 +202,17 @@ in
type = types.path;
};

pkgs = lib.mkOption {
description = ''
Package set to use. If specified, you must also manually apply
CTL overlays.
Added in: 2.3.0.
'';
default = null;
type = types.nullOr (types.raw or types.unspecified);
};

ignoredWarningCodes = lib.mkOption {
description = ''
Warnings from `purs` to silence during compilation.
Expand Down Expand Up @@ -294,7 +326,7 @@ in
});
};
config = {
perSystem = { config, self', inputs', lib, system, ... }:
perSystem = { config, self', inputs', pkgs, lib, system, ... }:
let
liqwid-nix = self.inputs.liqwid-nix.inputs;

Expand Down Expand Up @@ -325,11 +357,6 @@ in
[liqwid-nix] liqwid-nix offchain module is being used. Please provide a 'nixpkgs-ctl' input, as taken from 'cardano-transaction-lib'.
''); self.inputs.nixpkgs-ctl;

pkgs = import nixpkgs-ctl {
inherit system;
overlays = defaultCtlOverlays ++ additionalOverlays;
};

# NOTE(Emily, 13 Jan 2023): This is currently semi-vendored from CTL. This shouldn't be necessary
# once we are on a more recent version that supports including the spago result in the bundle.
#
Expand Down Expand Up @@ -362,6 +389,7 @@ in
, includeBundledModule ? false
# The project object
, project
, pkgs
, ...
}:
pkgs.runCommand "${name}"
Expand Down Expand Up @@ -397,6 +425,11 @@ in

makeProject = projectName: projectConfig:
let
pkgs = projectConfig.pkgs or (import nixpkgs-ctl {
inherit system;
overlays = defaultCtlOverlays ++ additionalOverlays;
});

nodejsPackage = projectConfig.nodejsPackage;

defaultCommandLineTools = with pkgs; [
Expand All @@ -419,7 +452,7 @@ in
pkgSet = pkgs.purescriptProject {
inherit (projectConfig) src;

inherit projectName;
inherit projectName pkgs;

nodejs = nodejsPackage;

Expand All @@ -434,7 +467,8 @@ in
packages = commandLineTools;
shellHook = ''
liqwid(){ c=$1; shift; nix run .#$c -- $@; }
'';
''
+ projectConfig.shell.shellHook;
};
};
in
Expand All @@ -447,7 +481,7 @@ in
webpackConfig
includeBundledModule
browserRuntime;
inherit name project;
inherit name project pkgs;

main = bundle.mainModule;
entrypoint = bundle.entrypointJs;
Expand Down Expand Up @@ -540,9 +574,10 @@ in
};
in
{
packages = {
ctl-runtime = pkgs.buildCtlRuntime ctlRuntimeConfig { };
} // bundles;
packages = bundles //
(if projectConfig.runtime.exposeConfig
then { ctl-runtime = pkgs.buildCtlRuntime ctlRuntimeConfig { }; }
else { });

run.nixFormat =
{
Expand Down

0 comments on commit 72d18a5

Please sign in to comment.