mirror of
https://github.com/ilyakooo0/haskell.nix.git
synced 2024-10-26 09:37:17 +03:00
a443611ecf
This adds a way to specify the `evalSystem` or `evalPackages` explicitly when calling the `project` functions. Currently if we want to make a `flake` that supports multiple systems we have few options: * Require builders for all the supported systems (even just for `nix flake show`). * Pass `--impure` so that haskell.nix can see `builtins.currentSystem` to set up `pkgs.evalPackages` to use that. Unfortunately this prevents nix from caching some of the work it does and often results in it recalculating for each supported system when it would otherwise be cached and take no time at all. * Add an overlay to replace `evalPackages`. This works, but it is not straight forward. * Materialize the nix files for the project. This change allows `evalSystem = "x86_64-linux";` to be passed telling `haskell.nix` to run `cabal` and `nix-tools` on that system. The user will have to have a builder for that system, but does not need to have builders for the others (unless building outputs for them).
78 lines
2.5 KiB
Nix
78 lines
2.5 KiB
Nix
{ src
|
|
, userDefaults ? {}
|
|
, nixpkgs ? null
|
|
, nixpkgsPin ? null
|
|
, pkgs ? null
|
|
, checkMaterialization ? null
|
|
, compiler-nix-name ? null
|
|
, shell ? null
|
|
, ...}@commandArgs:
|
|
let
|
|
inherit ((lib.evalModules {
|
|
modules = [
|
|
(import ../modules/project-common.nix)
|
|
(import ../modules/stack-project.nix)
|
|
(import ../modules/cabal-project.nix)
|
|
(import ../modules/project.nix)
|
|
(import ../modules/hix-project.nix)
|
|
projectDefaults
|
|
commandArgs'
|
|
{ _module.args.pkgs = {}; }
|
|
];
|
|
}).config) name;
|
|
inherit (import ./.. {}) sources;
|
|
lib = import (sources.nixpkgs-unstable + "/lib");
|
|
commandArgs' =
|
|
builtins.listToAttrs (
|
|
builtins.concatMap (
|
|
name:
|
|
if commandArgs.${name} == null || name == "src" || name == "userDefaults" || name == "inNixShell"
|
|
then []
|
|
else [{ inherit name; value = commandArgs.${name}; }]
|
|
) (builtins.attrNames commandArgs));
|
|
defaultArgs = {
|
|
nixpkgsPin = "nixpkgs-unstable";
|
|
};
|
|
importDefaults = src:
|
|
if src == null || !(__pathExists src)
|
|
then {}
|
|
else import src;
|
|
userDefaults = importDefaults (commandArgs.userDefaults or null);
|
|
projectDefaults = importDefaults (toString (src.origSrcSubDir or src) + "/nix/hix.nix");
|
|
inherit ((lib.evalModules {
|
|
modules = [
|
|
(import ../modules/project-common.nix)
|
|
(import ../modules/stack-project.nix)
|
|
(import ../modules/cabal-project.nix)
|
|
(import ../modules/project.nix)
|
|
(import ../modules/hix-project.nix)
|
|
userDefaults
|
|
projectDefaults
|
|
commandArgs'
|
|
({config, pkgs, ...}: {
|
|
haskellNix = import ./.. { inherit checkMaterialization; };
|
|
nixpkgsPin = "nixpkgs-unstable";
|
|
nixpkgs = config.haskellNix.sources.${config.nixpkgsPin};
|
|
nixpkgsArgs = config.haskellNix.nixpkgsArgs // {
|
|
overlays = config.haskellNix.nixpkgsArgs.overlays ++ config.overlays;
|
|
};
|
|
_module.args.pkgs = import config.nixpkgs config.nixpkgsArgs;
|
|
project = pkgs.haskell-nix.project [
|
|
(import ../modules/hix-project.nix)
|
|
userDefaults
|
|
projectDefaults
|
|
commandArgs'
|
|
({config, ...}: {
|
|
src =
|
|
if __pathExists (toString (src.origSrcSubDir or src) + "/.git")
|
|
then config.evalPackages.haskell-nix.haskellLib.cleanGit {
|
|
inherit src name;
|
|
}
|
|
else src;
|
|
})
|
|
];
|
|
})
|
|
];
|
|
}).config) project shell;
|
|
in project
|