Created
November 11, 2023 23:57
-
-
Save newton-migosi/74d1c9f0ab3b343e20d40f46880a92fa to your computer and use it in GitHub Desktop.
Setting up miso nix flakes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Usage: | |
# | |
# With nix installed, navigate to the directory containing this flake and run | |
# `nix develop --impure`. The `--impure` is necessary in order to store state | |
# locally from "services", such as PostgreSQL. | |
{ | |
description = "Local library app"; | |
inputs = { | |
nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable"; | |
flake-parts.url = "github:hercules-ci/flake-parts"; | |
haskell-flake.url = "github:srid/haskell-flake"; | |
treefmt-nix.url = "github:numtide/treefmt-nix"; | |
treefmt-nix.inputs.nixpkgs.follows = "nixpkgs"; | |
flake-root.url = "github:srid/flake-root"; | |
mission-control.url = "github:Platonic-Systems/mission-control"; | |
devenv.url = "github:cachix/devenv"; | |
devshell-source.url = "github:numtide/devshell"; | |
nix-vscode-extensions.url = "github:nix-community/nix-vscode-extensions"; | |
# Haskell dependencies for frontend and backend. | |
polysemy = { url = "github:polysemy-research/polysemy"; flake = false; }; | |
http-media = { url = "github:zmthy/http-media/develop"; flake = false; }; | |
servant = { url = "github:haskell-servant/servant"; flake = false; }; | |
servant-jsaddle = { url = "github:haskell-servant/servant-jsaddle"; flake = false; }; | |
# Miso uses its own nixpkgs, thus we imported it to use its pinned nixpkgs on the `overlay.nix`. | |
miso = { url = "github:dmjio/miso"; flake = false; }; | |
}; | |
outputs = inputs@{ self, nixpkgs, flake-parts, devenv, nix-vscode-extensions, ... }: | |
let | |
codium = import ./nix/codium { inherit nixpkgs drv-tools nix-vscode-extensions; }; | |
drv-tools = import ./nix/drv-tools.nix { inherit nixpkgs; }; | |
in | |
flake-parts.lib.mkFlake { inherit inputs; } { | |
debug = true; | |
systems = [ "x86_64-linux" ]; | |
imports = [ | |
inputs.haskell-flake.flakeModule | |
inputs.treefmt-nix.flakeModule | |
inputs.flake-root.flakeModule | |
inputs.mission-control.flakeModule | |
inputs.devenv.flakeModule | |
]; | |
perSystem = { self', system, lib, config, inputs', pkgs, ... }: | |
let | |
inherit (codium) mkCodium extensions extensionsCommon settingsCommonNix settingsNix writeSettingsJSON; | |
in | |
{ | |
haskellProjects.other = { | |
devShell = { | |
tools = hp: { | |
inherit (hp) haskell-debug-adapter ghci-dap; | |
treefmt = config.treefmt.build.wrapper; | |
} // config.treefmt.build.programs; | |
hlsCheck.enable = true; | |
mkShellArgs = { | |
shellHook = '' | |
set -a; source ./config.sh; set +a | |
''; | |
}; | |
}; | |
autoWire = [ "packages" "apps" "checks" ]; # Wire all but the devShell | |
}; | |
haskellProjects.ghc865 = import ./nix/haskell/ghc865.nix | |
{ | |
inherit (inputs) servant-jsaddle miso; | |
inherit system; | |
}; | |
haskellProjects.ghcjs86 = import ./nix/haskell/ghcjs86.nix | |
{ | |
inherit (inputs) servant-jsaddle miso; | |
inherit system; | |
}; | |
haskellProjects.default = { | |
debug = true; | |
basePackages = config.haskellProjects.ghc865.outputs.finalPackages; | |
packages = { backend-miso.source = ./backend-miso; }; | |
autoWire = [ "packages" "apps" "checks" ]; | |
}; | |
haskellProjects.frontend-miso = { | |
basePackages = config.haskellProjects.ghcjs86.outputs.finalPackages; | |
packages = { frontend-miso.source = ./frontend-miso; }; | |
autoWire = [ "packages" "checks" ]; | |
}; | |
# Auto formatters. This also adds a flake check to ensure that the | |
# source tree was auto formatted. | |
treefmt.config = { | |
inherit (config.flake-root) projectRootFile; | |
package = pkgs.treefmt; | |
flakeFormatter = false; # For https://github.com/numtide/treefmt-nix/issues/55 | |
programs.ormolu.enable = true; | |
programs.nixpkgs-fmt.enable = true; | |
programs.cabal-fmt.enable = true; | |
programs.hlint.enable = true; | |
programs.prettier.enable = true; | |
settings.formatter.prettier = | |
{ | |
options = [ "--write" ]; | |
includes = [ "*.yaml" ]; | |
}; | |
# We use fourmolu | |
programs.ormolu.package = pkgs.haskellPackages.fourmolu; | |
settings.formatter.ormolu = { | |
options = [ | |
"--ghc-opt" | |
"-XImportQualifiedPost" | |
]; | |
}; | |
}; | |
# Dev shell scripts. | |
mission-control.scripts = { | |
docs = { | |
description = "Start Hoogle server for project dependencies"; | |
exec = '' | |
echo http://127.0.0.1:8888 | |
hoogle serve -p 8888 --local | |
''; | |
category = "Dev Tools"; | |
}; | |
repl = { | |
description = "Start the cabal repl"; | |
exec = '' | |
cabal repl "$@" | |
''; | |
category = "Dev Tools"; | |
}; | |
fmt = { | |
description = "Format the source tree"; | |
exec = config.treefmt.build.wrapper; | |
category = "Dev Tools"; | |
}; | |
run = { | |
description = "Run the project with ghcid auto-recompile"; | |
exec = '' | |
ghcid -c "cabal repl exe:server" --warnings -T :main | |
''; | |
category = "Primary"; | |
}; | |
test = { | |
description = "Run all tests"; | |
exec = '' | |
ghcid -c "cabal repl test:tests" -T :main | |
''; | |
category = "Primary"; | |
}; | |
}; | |
# Default package. | |
packages.default = pkgs.haskell.lib.justStaticExecutables self'.packages.local-library; | |
# Default shell. | |
devShells.default = pkgs.mkShell { | |
inputsFrom = [ | |
config.haskellProjects.default.outputs.devShell | |
config.flake-root.devShell | |
config.mission-control.devShell | |
]; | |
}; | |
}; | |
}; | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
inputs@{ servant-jsaddle, miso, system }: | |
let | |
misoPkgs = import inputs.miso { system = inputs.system; allowBroken = true; }; | |
in | |
{ | |
defaults.packages = { }; # No local packages | |
devShell.enable = false; | |
debug = true; | |
basePackages = misoPkgs.miso-ghc; | |
packages = { | |
# Dependencies from Hackage | |
# frontend | |
aeson.source = "1.4.4.0"; | |
clay.source = "0.13.3"; | |
http-client.source = "0.6.4.1"; | |
# jsaddle-warp is nested in jsaddle as a subdir | |
# http-proxy get from misoPkgs | |
servant.source = "0.16"; | |
servant-client-core.source = "0.16"; | |
servant-server.source = "0.16"; | |
servant-lucid.source = "0.9"; | |
servant-jsaddle.source = inputs.servant-jsaddle; # build from source via cabal2nix | |
websockets.source = "0.12.6.0"; | |
# We're using polysemy for the backend | |
# Requires some special treatment | |
pantry.source = "0.5.1.3"; | |
type-errors.source = "0.2.0.0"; | |
type-errors-pretty.source = "0.0.1.1"; | |
first-class-families.source = "0.5.0.0"; | |
th-abstraction.source = "0.3.1.0"; | |
th-lift.source = "0.8.0.1"; | |
polysemy.source = "1.4.0.0"; | |
time-compat.source = "1.9.2.2"; | |
}; | |
settings = { | |
aeson.check = false; | |
http-proxy.check = false; | |
http-proxy.haddock = false; | |
jsaddle-warp.check = false; | |
jsaddle-warp.haddock = false; | |
servant-jsaddle.check = false; | |
pantry.check = false; | |
polysemy.check = false; | |
polysemy.haddock = false; | |
time-compat.check = false; | |
time-compat.haddock = false; | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment