Skip to content

Commit

Permalink
Fixed many runtime errors
Browse files Browse the repository at this point in the history
  • Loading branch information
mpscholten committed Aug 5, 2023
1 parent de4d557 commit d4a77c6
Show file tree
Hide file tree
Showing 12 changed files with 411 additions and 43 deletions.
3 changes: 2 additions & 1 deletion NixSupport/mkGhcCompiler.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
, dontHaddockPackages ? []
, manualOverrides ? _: _: { }
, haskellPackagesDir ? ./haskell-packages
, filter
, ... }:

let
Expand All @@ -20,7 +21,7 @@ let
};
makePackageSet = dir: pkgs.lib.mapAttrs' (toPackage dir) (builtins.readDir dir);
in {
"ihp" = ((haskellPackagesNew.callPackage "${toString ihp}/ihp.nix") { });
"ihp" = ((haskellPackagesNew.callPackage "${toString ihp}/ihp.nix") { inherit filter; });
} // (makePackageSet haskellPackagesDir) // (makePackageSet "${ihp}/NixSupport/haskell-packages/.");

makeOverrides =
Expand Down
2 changes: 1 addition & 1 deletion NixSupport/nixosModules/app.nix
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Running an IHP web server + Worker
{ config, pkgs, modulesPath, lib, ihp, ihpApp, ... }:
{ config, pkgs, modulesPath, lib, ihp, ... }:
let cfg = config.services.ihp;
in
{
Expand Down
4 changes: 3 additions & 1 deletion NixSupport/nixosModules/appWithPostgres.nix
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Running IHP app + a local Postgres connected to it
{ config, pkgs, modulesPath, lib, ihp, ihpApp, ... }:
{ config, pkgs, modulesPath, lib, ihp, ... }:
let cfg = config.services.ihp;
in
{
Expand Down Expand Up @@ -80,5 +80,7 @@ in
\i ${cfg.fixtures}
'';
};

services.ihp.databaseUrl = ""; # TODO: Set this to some real value
}

16 changes: 13 additions & 3 deletions NixSupport/nixosModules/options.nix
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
# Running IHP app + a local Postgres connected to it
{ config, pkgs, modulesPath, lib, ihpApp, ... }:
{ config, pkgs, modulesPath, lib, ... }:
with lib;
{
options.services.ihp = {
enable = mkEnableOption "IHP";
domain = mkOption {
type = types.str;
default = "localhost";
};

baseUrl = mkOption {
type = types.str;
default = "https://${config.services.ihp.domain}";
};

migrations = mkOption {
type = types.path;
Expand All @@ -21,7 +27,7 @@
};

httpsEnabled = mkOption {
type = types.boolean;
type = types.bool;
default = true;
};

Expand All @@ -35,6 +41,10 @@
default = "ihp";
};

databaseUrl = mkOption {
type = types.str;
};

# https://ihp.digitallyinduced.com/Guide/database-migrations.html#skipping-old-migrations
minimumRevision = mkOption {
type = types.int;
Expand All @@ -60,7 +70,7 @@
type = types.str;
};

addionalEnvVars = mkOption {
additionalEnvVars = mkOption {
type = types.attrs;
default = {};
};
Expand Down
7 changes: 4 additions & 3 deletions NixSupport/nixosModules/services/app.nix
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{ config, pkgs, modulesPath, lib, ihpApp, migrate, migrations, ... }:
let cfg = config.services.ihp;
{ config, pkgs, modulesPath, lib, ihpApp, ... }:
let
cfg = config.services.ihp;
in
{
systemd.services.app = {
Expand All @@ -16,7 +17,7 @@ in
environment =
let
defaultEnv = {
PORT = cfg.appPort;
PORT = "${toString cfg.appPort}";
IHP_ENV = cfg.ihpEnv;
IHP_BASEURL = cfg.baseUrl;
IHP_REQUEST_LOGGER_IP_ADDR_SOURCE = cfg.requestLoggerIPAddrSource;
Expand Down
24 changes: 12 additions & 12 deletions NixSupport/nixosModules/services/migrate.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ config, pkgs, ... }:
{ config, pkgs, ihp, ... }:
let cfg = config.services.ihp;
in
{
Expand All @@ -12,16 +12,16 @@ in
'';
};
in {
serviceConfig = {
Type = "oneshot";
};
script = ''
cd ${migrateApp}
${self.packages.x86_64-linux.migrate}/bin/migrate
'';
environment = {
DATABASE_URL = cfg.databaseUrl;
MINIMUM_REVISION = "${cfg.minimumRevision}";
};
serviceConfig = {
Type = "oneshot";
};
script = ''
cd ${migrateApp}
${ihp.apps.x86_64-linux.migrate.program}
'';
environment = {
DATABASE_URL = cfg.databaseUrl;
MINIMUM_REVISION = "${toString cfg.minimumRevision}";
};
};
}
7 changes: 4 additions & 3 deletions NixSupport/nixosModules/services/worker.nix
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{ config, pkgs, modulesPath, lib, ihpApp, migrate, migrations, ... }:
let cfg = config.services.ihp;
{ config, pkgs, ihpApp, lib, ... }:
let
cfg = config.services.ihp;
in
{
systemd.services.worker = {
Expand All @@ -15,7 +16,7 @@ in
environment =
let
defaultEnv = {
PORT = cfg.port;
PORT = "${toString cfg.appPort}";
IHP_ENV = cfg.ihpEnv;
IHP_BASEURL = cfg.baseUrl;
IHP_REQUEST_LOGGER_IP_ADDR_SOURCE = cfg.requestLoggerIPAddrSource;
Expand Down
24 changes: 15 additions & 9 deletions devenv-module.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,28 @@ flake-parts module for setting the local IHP devenv shell
this is different from the devenv environment used by IHP apps!
that is defined in flake-module.nix
*/

{ inputs }:
{
perSystem = { pkgs, lib, ... }: {
perSystem = { nix-filter, pkgs, lib, ... }: let
ghcCompiler = import ./NixSupport/mkGhcCompiler.nix {
inherit pkgs;
ghcCompiler = pkgs.haskell.packages.ghc944;
ihp = ./.;
filter = inputs.nix-filter.lib;
};
in {

apps.migrate = {
type = "app";
program = "${ghcCompiler.ihp}/bin/migrate";
};

devenv.shells.default = {
packages = with pkgs; [ entr nodejs-18_x ];
containers = lib.mkForce {}; # https://github.com/cachix/devenv/issues/528

languages.haskell.enable = true;
languages.haskell.package =
let
ghcCompiler = import ./NixSupport/mkGhcCompiler.nix {
inherit pkgs;
ghcCompiler = pkgs.haskell.packages.ghc944;
ihp = ./.;
};
in
ghcCompiler.ghc.withPackages (p: with p; [
# Copied from ihp.nix
base
Expand Down
6 changes: 1 addition & 5 deletions flake-module.nix
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ ihpFlake:
inherit (cfg) ghcCompiler dontCheckPackages doJailbreakPackages dontHaddockPackages;
ihp = ihp;
haskellPackagesDir = cfg.projectPath + "/Config/nix/haskell-packages";
filter = ihpFlake.inputs.nix-filter.lib;
};
in lib.mkIf cfg.enable {
# release build package
Expand Down Expand Up @@ -125,11 +126,6 @@ ihpFlake:
pkgs = pkgs;
};


migrate = pkgs.writeScriptBin "migrate" ''
${ghcCompiler.ihp}/bin/migrate
'';

ihp-schema = pkgs.stdenv.mkDerivation {
name = "ihp-schema";
src = ihp;
Expand Down
Loading

0 comments on commit d4a77c6

Please sign in to comment.