Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

big Nix refactor #56

Merged
merged 9 commits into from
Feb 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 34 additions & 37 deletions flake.lock

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

112 changes: 19 additions & 93 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,112 +2,38 @@
description = "Haskell bindings to the Temporal Core library as well as an SDK built on top of it.";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
flake-utils.url = "github:numtide/flake-utils";
devenv.url = "github:cachix/devenv/v1.0.5";
flake-parts.url = "github:hercules-ci/flake-parts";
fenix = {
url = "github:nix-community/fenix";
inputs = {nixpkgs.follows = "nixpkgs";};
inputs.nixpkgs.follows = "nixpkgs";
};
};

outputs = inputs @ {
self,
nixpkgs,
devenv,
flake-utils,
...
}: let
inherit (nixpkgs) lib;
inherit
(import ./nix/matrix.nix)
supportedSystems
;
in
{
lib = {
haskellOverlay = import ./nix/overlays/temporal-sdk.nix;
};
}
// flake-utils.lib.eachSystem supportedSystems (system: let
pkgs = import nixpkgs {inherit system;};
temporalBridgeAndFriends = import ./nix/temporal-bridge.nix {
inherit
pkgs
;
};
temporal-bridge = temporalBridgeAndFriends.temporal-bridge;
haskellPackageUtils = import ./nix/haskell-packages.nix {
inherit
lib
pkgs
temporal-bridge
;
};
inherit (haskellPackageUtils) extendedPackageSetByGHCVersions;

mkShellForGHC = ghcVersion: let
myHaskellPackages = extendedPackageSetByGHCVersions.${ghcVersion};
in
devenv.lib.mkShell {
inherit inputs pkgs;
modules = [
({...}: {
packages = with pkgs; [
ghciwatch
];
env.LIBRARY_PATH = "${temporal-bridge.lib}/lib";
env.TEMPORAL_BRIDGE_LIB_DIR = "${temporal-bridge.lib}/lib";

languages.haskell = {
enable = true;
package = myHaskellPackages.ghc.withHoogle (
hpkgs:
lib.attrVals (builtins.attrNames (haskellPackageUtils.localDevPackageDepsAsAttrSet myHaskellPackages)) hpkgs
);
};
})
(import ./nix/devenv/temporal-dev-server.nix)
(import ./nix/devenv/temporal-bridge.nix {
proto-lens-protoc = extendedPackageSetByGHCVersions.${ghcVersion}.proto-lens-protoc;
temporal-sdk-core = temporalBridgeAndFriends.temporal-sdk-core-src;
})
(import ./nix/devenv/repo-wide-checks.nix)
];
};
in {
packages =
{
inherit temporal-bridge;
devenv-up = self.devShells.${system}.default.config.procfileScript;
}
// haskellPackageUtils.localPackageMatrix;

devShells = rec {
default = ghc96;
ghc96 = mkShellForGHC "ghc96";
ghc98 = mkShellForGHC "ghc98";
};

checks = {
# pre-commit-check = devenv.inputs.pre-commit-hooks.lib.${system}.run {
# src = ./.;
# hooks = pre-commit-hooks;
# };
};
});
outputs =
inputs@{ self, ... }:
inputs.flake-parts.lib.mkFlake { inherit inputs; } {
systems = (import ./nix/utils/matrix.nix).systems;
imports = [
./nix/overlays/temporal-bridge/module.nix
./nix/overlays/haskell/module.nix
./nix/devenv/module.nix
./nix/packages/module.nix
];
};

# --- Flake Local Nix Configuration ----------------------------
# --- Flake Local Nix Configuration -----------------------------------------
nixConfig = {
# This sets the flake to use the IOG nix cache.
# Nix should ask for permission before using it,
# but remove it here if you do not want it to.
# This sets the flake to use several upstream substituters that have cached
# artifacts for some of our dependencies.
#
# Nix should ask for permission before using it, but remove it here if you
# do not want it to.
extra-substituters = [
"https://cache.iog.io"
"https://cache.garnix.io"
"https://devenv.cachix.org"
];
extra-trusted-public-keys = [
"hydra.iohk.io:f/Ea+s+dFdN+3Y/G+FDgSq+a5NEWhJGzdjvKNGv0/EQ="
"cache.garnix.io:CTFPyKSLcx5RMJKfLo5EEPUObbA78b0YQ2DTCJXqr9g="
"devenv.cachix.org-1:w1cLUi8dv3hnoSPGAuibQv+f9TZLr6cv/Hm9XgU50cw="
];
Expand Down
18 changes: 6 additions & 12 deletions garnix.yaml
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
builds:
- include:
- 'checks.x86_64-linux.*'
- 'packages.x86_64-linux.*'
- 'packages.*.temporal-bridge'
- 'packages.*.*'
exclude:
- 'packages.*.default'
- 'packages.*.devenv-up'
# Unable to build because devenv is impure
- 'devShells.*.*'
- include:
- 'packages.aarch64-darwin.*'
- 'packages.aarch64-linux.*'
exclude: []
branch: main
# `x86_64-darwin` isn't a supported architecture.
- 'packages.x86_64-darwin.*'
# Unable to build because devenv is impure.
- 'devShells.*.*'
- 'packages.*.devenv-up'
42 changes: 42 additions & 0 deletions nix/devenv/module.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{ inputs, ... }: {
perSystem =
{ pkgs, ... }:
let
# TODO: There's almost definitely a cleaner way to do this, but for now
# it's quicker to copy the previous implementation and shim it in here.
inherit (import ../utils/matrix.nix) ghcVersions;
haskellUtils = (import ../utils/haskell.nix) pkgs;
mkShell = ghcVersion: inputs.devenv.lib.mkShell {
inherit inputs pkgs;
modules = [
./temporal-bridge.nix
./temporal-dev-server.nix
({pkgs, ...}: {
# XXX: Do we need to pull `proto-lens-protoc` from the selected package
# set or will any version work? If it doesn't need to be from the same
# package set as the dev shell, then this a flake package output.
#
packages = [
(pkgs.callPackage ../packages/protogen.nix {
inherit (pkgs.haskell.packages.${ghcVersion}) proto-lens-protoc;
})
];
languages.haskell = {
languageServer = null;
enable = true;
package = pkgs.haskell.packages.${ghcVersion}.ghc.withHoogle (
hpkgs: builtins.attrValues (haskellUtils.localDevPackageDepsAttrSet hpkgs)
);
};
})
];
};
in {
devShells = rec {
default = ghc910;
ghc96 = mkShell "ghc96";
ghc98 = mkShell "ghc98";
ghc910 = mkShell "ghc910";
};
};
}
36 changes: 1 addition & 35 deletions nix/devenv/temporal-bridge.nix
Original file line number Diff line number Diff line change
@@ -1,40 +1,6 @@
{
proto-lens-protoc,
temporal-sdk-core,
}: {pkgs, ...}: let
protogen = pkgs.writeShellApplication {
name = "protogen";
runtimeInputs = [pkgs.protobuf pkgs.hpack];
text = ''
shopt -s globstar

repo_root="$( git rev-parse --show-toplevel )"
package_dir="$repo_root/protos"

protoc \
--plugin=protoc-gen-haskell=${pkgs.lib.getExe proto-lens-protoc} \
--haskell_out="$package_dir/src" \
--proto_path=${temporal-sdk-core}/sdk-core-protos/protos/local \
--proto_path=${temporal-sdk-core}/sdk-core-protos/protos/api_upstream \
--proto_path=${temporal-sdk-core}/sdk-core-protos/protos/grpc \
--proto_path=${temporal-sdk-core}/sdk-core-protos/protos/google \
--proto_path=${temporal-sdk-core}/sdk-core-protos/protos/testsrv_upstream \
${temporal-sdk-core}/sdk-core-protos/protos/local/**/*.proto \
${temporal-sdk-core}/sdk-core-protos/protos/api_upstream/**/*.proto \
${temporal-sdk-core}/sdk-core-protos/protos/grpc/**/*.proto \
${temporal-sdk-core}/sdk-core-protos/protos/google/**/*.proto \
${temporal-sdk-core}/sdk-core-protos/protos/testsrv_upstream/temporal/**/*.proto

# Remove codegen for well-known types (`proto-lens` provides these).
rm -rf "$package_dir/src/Proto/Google/Protobuf"
# Re-generate cabal file to include new/updated modules.
hpack "$package_dir"
'';
};
in {
{pkgs, ...}: {
packages =
[
protogen
pkgs.crate2nix
pkgs.protobuf
pkgs.rust-cbindgen
Expand Down
Loading