diff --git a/Guide/package-management.markdown b/Guide/package-management.markdown index 3d781b355..0c29b701e 100644 --- a/Guide/package-management.markdown +++ b/Guide/package-management.markdown @@ -371,47 +371,53 @@ After that try to run `devenv up`. ### Building Postgres With Extensions -**TODO: Fix this for IHP v1.1.0** - For some applications you may want to install custom postgres extension libraries and have them available in the nix store. For example to enable the [postgis](https://postgis.net/) spatial and geographic objects in PostgreSQL add -`postgresExtensions = (p: [ p.postgis ]);` to your project's `default.nix` file as -an attribute of the `"{ihp}/NixSupport/default.nix"` expression. +`services.postgres.extensions = extensions: [ extensions.postgis ];` to your project's `flake.nix`: ```nix -let - ihp = builtins.fetchGit { - url = "https://github.com/digitallyinduced/ihp.git"; - rev = "c6d40612697bb7905802f23b7753702d33b9e2c1"; - }; - haskellEnv = import "${ihp}/NixSupport/default.nix" { - ihp = ihp; - postgresExtensions = (p: [ p.postgis ]); - haskellDeps = p: with p; [ - cabal-install - base - wai - text - hlint - p.ihp - google-oauth2 - ]; - otherDeps = p: with p; [ - ]; - projectPath = ./.; +{ + inputs = { + ihp.url = "path:///Users/marc/digitallyinduced/ihp"; + ihp.inputs.nixpkgs.url = "github:mpscholten/nixpkgs/fix-th-desugar"; + nixpkgs.follows = "ihp/nixpkgs"; + flake-parts.follows = "ihp/flake-parts"; + devenv.follows = "ihp/devenv"; + systems.follows = "ihp/systems"; }; -in - haskellEnv + + outputs = inputs@{ ihp, flake-parts, systems, nixpkgs, ... }: + flake-parts.lib.mkFlake { inherit inputs; } { + systems = import systems; + imports = [ ihp.flakeModules.default ]; + + perSystem = { pkgs, ... }: { + ihp = { + inherit appName; + enable = true; + projectPath = ./.; + packages = with pkgs; []; + haskellPackages = p: with p; [ + # ... + ]; + }; + devenv.shells.default = { + services.postgres.extensions = extensions: [ extensions.postgis ]; + }; + }; + }; +} + ``` Behind the scenes this will pass a function to the postgres nix expressions `postgresql.withPackages` function making the extension in your app's nix store postgres package. -After the install you can run `create extension postgis;` to enable all the features of the +After the install you can run `CREATE EXTENSION postgis;` to enable all the features of the installed extension. ### Stopping Nix From Running Tests for a Haskell Dependency diff --git a/NixSupport/default.nix b/NixSupport/default.nix index 0b44c4fd4..b754aeaea 100644 --- a/NixSupport/default.nix +++ b/NixSupport/default.nix @@ -7,9 +7,7 @@ , otherDeps ? (p: []) , projectPath ? ./. , withHoogle ? false -, postgresExtensions ? (p: []) , optimized ? false -, includeDevTools ? !optimized # Include Postgres? , rtsFlags ? "" , appName ? "app" , optimizationLevel ? "2" @@ -175,7 +173,6 @@ in [ pkgs.makeWrapper pkgs.cacert # Needed for npm install to work from within the IHP build process ] - (if includeDevTools then [(pkgs.postgresql_13.withPackages postgresExtensions)] else []) ]; shellHook = "eval $(egrep ^export ${allHaskellPackages}/bin/ghc)"; enableParallelBuilding = true; diff --git a/flake-module.nix b/flake-module.nix index 9748e195d..a9e54de7d 100644 --- a/flake-module.nix +++ b/flake-module.nix @@ -139,8 +139,6 @@ ihpFlake: haskellDeps = cfg.haskellPackages; otherDeps = p: cfg.packages; projectPath = cfg.projectPath; - # Dev tools are not needed in the release build - includeDevTools = false; # Set optimized = true to get more optimized binaries, but slower build times optimized = true; ghc = ghcCompiler; @@ -156,7 +154,6 @@ ihpFlake: haskellDeps = cfg.haskellPackages; otherDeps = p: cfg.packages; projectPath = cfg.projectPath; - includeDevTools = false; optimized = false; ghc = ghcCompiler; pkgs = pkgs; @@ -204,9 +201,21 @@ ihpFlake: }; devenv.shells.default = lib.mkIf cfg.enable { - packages = [ ghcCompiler.ihp ghcCompiler.ihp-ide pkgs.postgresql_13 pkgs.gnumake ] + packages = [ ghcCompiler.ihp ghcCompiler.ihp-ide pkgs.gnumake ] ++ cfg.packages ++ [pkgs.mktemp] # Without this 'make build/bin/RunUnoptimizedProdServer' fails on macOS + ++ [(let cfg = config.devenv.shells.default.services.postgres; in + if cfg.extensions != null + then + if builtins.hasAttr "withPackages" cfg.package + then cfg.package.withPackages cfg.extensions + else + builtins.throw '' + Cannot add extensions to the PostgreSQL package. + `services.postgres.package` is missing the `withPackages` attribute. Did you already add extensions to the package? + '' + else cfg.package + )] ; /* @@ -239,6 +248,7 @@ ihpFlake: # As the devenv postgres uses a different location for the socket # this would break lots of known commands such as `make db` services.postgres.enable = false; + services.postgres.package = pkgs.postgresql_13; services.postgres.initialDatabases = [ { name = "app";