unison/flake.nix

185 lines
7.1 KiB
Nix
Raw Normal View History

2022-06-04 04:33:25 +03:00
{
2023-05-31 16:23:20 +03:00
description = "Unison";
nixConfig = {
extra-substituters = [ "https://unison.cachix.org" ];
2023-07-04 05:10:18 +03:00
extra-trusted-public-keys = [
"unison.cachix.org-1:i1DUFkisRPVOyLp/vblDsbsObmyCviq/zs6eRuzth3k="
2023-06-14 20:40:27 +03:00
];
2023-05-31 16:23:20 +03:00
};
2022-06-04 04:33:25 +03:00
inputs = {
2023-05-31 16:23:20 +03:00
haskellNix.url = "github:input-output-hk/haskell.nix";
nixpkgs.follows = "haskellNix/nixpkgs-unstable";
2022-06-04 04:33:25 +03:00
flake-utils.url = "github:numtide/flake-utils";
2023-05-31 16:23:20 +03:00
flake-compat = {
url = "github:edolstra/flake-compat";
flake = false;
};
2022-06-04 04:33:25 +03:00
};
2023-05-31 16:23:20 +03:00
outputs = { self, nixpkgs, flake-utils, haskellNix, flake-compat }:
flake-utils.lib.eachSystem [
"x86_64-linux"
"x86_64-darwin"
"aarch64-darwin"
2023-06-13 23:18:52 +03:00
]
(system:
let
overlays = [
haskellNix.overlay
(final: prev: {
unison-project = with prev.lib.strings;
let
cleanSource = pth:
let
src' = prev.lib.cleanSourceWith {
filter = filt;
src = pth;
};
filt = path: type:
let
bn = baseNameOf path;
isHiddenFile = hasPrefix "." bn;
isFlakeLock = bn == "flake.lock";
isNix = hasSuffix ".nix" bn;
in
!isHiddenFile && !isFlakeLock && !isNix;
in
src';
in
final.haskell-nix.project' {
src = cleanSource ./.;
projectFileName = "stack.yaml";
modules = [
# enable profiling
{
enableLibraryProfiling = true;
profilingDetail = "none";
}
# remove buggy build tool dependencies
({ lib, ... }: {
# this component has the build tool
# `unison-cli:unison` and somehow haskell.nix
# decides to add some file sharing package
# `unison` as a build-tool dependency.
2023-07-04 05:10:18 +03:00
packages.unison-cli.components.exes.cli-integration-tests.build-tools =
lib.mkForce [ ];
2023-06-13 23:18:52 +03:00
})
];
branchMap = {
"https://github.com/unisonweb/configurator.git"."e47e9e9fe1f576f8c835183b9def52d73c01327a" =
"unison";
"https://github.com/unisonweb/shellmet.git"."2fd348592c8f51bb4c0ca6ba4bc8e38668913746" =
"topic/avoid-callCommand";
2023-05-31 16:23:20 +03:00
};
};
2023-06-13 23:18:52 +03:00
})
2023-07-04 05:16:42 +03:00
(final: prev: {
unison-stack = prev.symlinkJoin {
name = "stack";
paths = [ final.stack ];
buildInputs = [ final.makeWrapper ];
postBuild =
let
flags = [ "--no-nix" "--system-ghc" "--no-install-ghc" ];
add-flags =
"--add-flags '${prev.lib.concatStringsSep " " flags}'";
in
''
wrapProgram "$out/bin/stack" ${add-flags}
'';
};
})
2023-06-13 23:18:52 +03:00
];
pkgs = import nixpkgs {
inherit system overlays;
inherit (haskellNix) config;
};
flake = pkgs.unison-project.flake { };
2023-07-04 05:10:18 +03:00
commonShellArgs = args:
args // {
# workaround:
# https://github.com/input-output-hk/haskell.nix/issues/1793
# https://github.com/input-output-hk/haskell.nix/issues/1885
allToolDeps = false;
2023-07-07 19:11:05 +03:00
additional = hpkgs: with hpkgs; [ Cabal stm exceptions ghc ghc-heap ];
2023-07-05 18:57:50 +03:00
buildInputs =
let
native-packages = pkgs.lib.optionals pkgs.stdenv.isDarwin
(with pkgs.darwin.apple_sdk.frameworks; [ Cocoa ]);
in
2023-07-07 18:17:18 +03:00
(args.buildInputs or [ ]) ++ (with pkgs; [ unison-stack pkg-config zlib glibcLocales ]) ++ native-packages;
2023-07-04 05:10:55 +03:00
# workaround for https://gitlab.haskell.org/ghc/ghc/-/issues/11042
shellHook = ''
export LD_LIBRARY_PATH=${pkgs.zlib}/lib:$LD_LIBRARY_PATH
'';
2023-07-04 05:10:18 +03:00
tools =
let ormolu-ver = "0.5.2.0";
in (args.tools or { }) // {
cabal = { };
ormolu = { version = ormolu-ver; };
haskell-language-server = {
version = "latest";
modules = [
{
packages.haskell-language-server.components.exes.haskell-language-server.postInstall = ''
ln -sr "$out/bin/haskell-language-server" "$out/bin/haskell-language-server-wrapper"
'';
}
];
2023-07-04 05:10:18 +03:00
# specify flags via project file rather than a module override
# https://github.com/input-output-hk/haskell.nix/issues/1509
cabalProject = ''
packages: .
package haskell-language-server
flags: -brittany -fourmolu -stylishhaskell -hlint
constraints: ormolu == ${ormolu-ver}
'';
};
2023-05-31 16:23:20 +03:00
};
2023-07-04 05:10:18 +03:00
};
2023-06-13 23:18:52 +03:00
shellFor = args: pkgs.unison-project.shellFor (commonShellArgs args);
localPackages = with pkgs.lib;
filterAttrs (k: v: v.isLocal or false) pkgs.unison-project.hsPkgs;
localPackageNames = builtins.attrNames localPackages;
devShells =
let
2023-07-04 05:10:18 +03:00
mkDevShell = pkgName:
shellFor {
2023-06-13 23:18:52 +03:00
packages = hpkgs: [ hpkgs."${pkgName}" ];
withHoogle = true;
};
2023-07-04 05:10:18 +03:00
localPackageDevShells =
pkgs.lib.genAttrs localPackageNames mkDevShell;
2023-06-13 23:18:52 +03:00
in
{
default = devShells.only-tools;
only-tools = shellFor {
packages = _: [ ];
withHoogle = false;
};
local = shellFor {
packages = hpkgs: (map (p: hpkgs."${p}") localPackageNames);
withHoogle = true;
};
} // localPackageDevShells;
in
flake // {
2023-07-04 05:10:18 +03:00
defaultPackage = flake.packages."unison-cli:exe:unison";
inherit (pkgs) unison-project;
2023-06-13 23:18:52 +03:00
inherit devShells localPackageNames;
2023-08-03 17:43:49 +03:00
packages = flake.packages // {
all = pkgs.symlinkJoin {
name = "all-packages";
paths =
let
all-other-packages = builtins.attrValues (builtins.removeAttrs self.packages."${system}" [ "all" ]);
devshell-inputs = builtins.concatMap (devShell: devShell.buildInputs ++ devShell.nativeBuildInputs) [ devShells.only-tools ];
in
all-other-packages ++ devshell-inputs;
};
};
2023-06-13 23:18:52 +03:00
});
2022-06-04 04:33:25 +03:00
}