Skip to content

Commit

Permalink
Tidy up project modules
Browse files Browse the repository at this point in the history
  • Loading branch information
hamishmack committed Jun 19, 2021
1 parent 3ee4600 commit 9755952
Show file tree
Hide file tree
Showing 9 changed files with 87 additions and 119 deletions.
63 changes: 7 additions & 56 deletions hix/project.nix
Expand Up @@ -8,53 +8,13 @@
, shell ? null
, ...}@commandArgs:
let
hixProject = {
options = {
haskellNix = lib.mkOption {
type = lib.types.unspecified;
default = null;
};
nixpkgsPin = lib.mkOption {
type = lib.types.str;
default = "nixpkgs-unstable";
};
nixpkgs = lib.mkOption {
type = lib.types.unspecified;
default = null;
};
nixpkgsArgs = lib.mkOption {
type = lib.types.unspecified;
default = null;
};
overlays = lib.mkOption {
type = lib.types.unspecified;
default = [];
};
pkgs = lib.mkOption {
type = lib.types.unspecified;
default = null;
};
project = lib.mkOption {
type = lib.types.unspecified;
default = null;
};
};
};
hixDefaults = { compiler-nix-name = lib.mkDefault "ghc8105"; };
inherit ((lib.evalModules {
modules = [
hixProject
{
options = {
projectFileName = lib.mkOption {
type = lib.types.nullOr lib.types.str;
default = null;
};
};
}
(import ../modules/project.nix)
(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 = {}; }
Expand All @@ -81,19 +41,11 @@ let
projectDefaults = importDefaults (toString (src.origSrcSubDir or src) + "/nix/hix.nix");
inherit ((lib.evalModules {
modules = [
hixProject
{
options = {
projectFileName = lib.mkOption {
type = lib.types.nullOr lib.types.str;
default = null;
};
};
}
(import ../modules/project.nix)
(import ../modules/project-common.nix)
(import ../modules/stack-project.nix)
(import ../modules/cabal-project.nix)
hixDefaults
(import ../modules/project.nix)
(import ../modules/hix-project.nix)
userDefaults
projectDefaults
commandArgs'
Expand All @@ -106,8 +58,7 @@ let
};
pkgs = import config.nixpkgs config.nixpkgsArgs;
project = config.pkgs.haskell-nix.project [
hixProject
hixDefaults
(import ../modules/hix-project.nix)
userDefaults
projectDefaults
commandArgs'
Expand Down
2 changes: 1 addition & 1 deletion lib/default.nix
Expand Up @@ -341,7 +341,7 @@ in {
(lib.evalModules {
modules = (if builtins.isList m then m else [m]) ++ [
# Include ../modules/cabal-project.nix or ../modules/stack-project.nix
(import ../modules/project.nix)
(import ../modules/project-common.nix)
(import projectType)
# Pass the pkgs to the modules
({ config, lib, ... }: {
Expand Down
12 changes: 0 additions & 12 deletions modules/cabal-project.nix
Expand Up @@ -129,17 +129,5 @@ in {
type = nullOr (listOf unspecified);
default = [];
};

# Default shell arguments
shell = mkOption {
# TODO make this a submodule
type = unspecified;
default = {};
description = ''
Arguments to use for the default shell `p.shell` (these are passed to p.shellFor).
For instance to include `cabal` and `ghcjs` support use
shell = { tools.cabal = {}; crossPlatforms = p: [ p.ghcjs ]; }
'';
};
};
}
40 changes: 40 additions & 0 deletions modules/hix-project.nix
@@ -0,0 +1,40 @@
{ lib, ... }: {
_file = "haskell.nix/modules/hix-project.nix";
options = {
# These are options that only the Hix command wrappers use. If you make a flake
# with `haskell-nix.hix.project`, then they are ignored.
haskellNix = lib.mkOption {
type = lib.types.unspecified;
default = null;
};
nixpkgsPin = lib.mkOption {
type = lib.types.str;
default = "nixpkgs-unstable";
};
nixpkgs = lib.mkOption {
type = lib.types.unspecified;
default = null;
};
nixpkgsArgs = lib.mkOption {
type = lib.types.unspecified;
default = null;
};
overlays = lib.mkOption {
type = lib.types.unspecified;
default = [];
};
pkgs = lib.mkOption {
type = lib.types.unspecified;
default = null;
};
project = lib.mkOption {
type = lib.types.unspecified;
default = null;
};
};

# Default values for other project options (things that do not have defaults for non hix projects)
config = {
compiler-nix-name = lib.mkDefault "ghc8105";
};
}
28 changes: 28 additions & 0 deletions modules/project-common.nix
@@ -0,0 +1,28 @@
{ lib, ... }:
with lib;
with lib.types;
{
_file = "haskell.nix/modules/project-common.nix";
options = {
# Used by callCabalProjectToNix and callStackToNix
name = mkOption {
type = nullOr str;
default = "haskell-project"; # TODO figure out why `config.src.name or null` breaks hix;
description = "Optional name for better error messages";
};
src = mkOption {
type = either path package;
};
# Default shell arguments
shell = mkOption {
# TODO make this a submodule
type = unspecified;
default = {};
description = ''
Arguments to use for the default shell `p.shell` (these are passed to p.shellFor).
For instance to include `cabal` and `ghcjs` support use
shell = { tools.cabal = {}; crossPlatforms = p: [ p.ghcjs ]; }
'';
};
};
}
24 changes: 5 additions & 19 deletions modules/project.nix
@@ -1,23 +1,9 @@
{ lib, config, pkgs, haskellLib, ... }:
with lib;
with types;
let readIfExists = src: fileName:
let origSrcDir = src.origSrcSubDir or src;
in
if builtins.elem ((__readDir origSrcDir)."${fileName}" or "") ["regular" "symlink"]
then __readFile (origSrcDir + "/${fileName}")
else null;
in {
{ lib, ... }: {
_file = "haskell.nix/modules/project.nix";
options = {
# Used by callCabalProjectToNix and callStackToNix
name = mkOption {
type = nullOr str;
default = "haskell-project"; # TODO figure out why `config.src.name or null` breaks hix;
description = "Optional name for better error messages";
};
src = mkOption {
type = either path package;
projectFileName = lib.mkOption {
type = lib.types.nullOr lib.types.str;
default = null;
};
};
}
}
12 changes: 0 additions & 12 deletions modules/stack-project.nix
Expand Up @@ -101,17 +101,5 @@ with types;
default = null;
description = "Deprecated in favour of `compiler-nix-name`";
};

# Default shell arguments
shell = mkOption {
# TODO make this a submodule
type = unspecified;
default = {};
description = ''
Arguments to use for the default shell `p.shell` (these are passed to p.shellFor).
For instance to include `cabal` and `ghcjs` support use
shell = { tools.cabal = {}; crossPlatforms = p: [ p.ghcjs ]; }
'';
};
};
}
11 changes: 2 additions & 9 deletions overlays/haskell.nix
Expand Up @@ -814,17 +814,10 @@ final: prev: {
projectModule' = if builtins.isList projectModule then projectModule else [projectModule];
inherit ((final.lib.evalModules {
modules = [
{
options = {
projectFileName = final.lib.mkOption {
type = final.lib.types.nullOr final.lib.types.string;
default = null;
};
};
}
(import ../modules/project.nix)
(import ../modules/project-common.nix)
(import ../modules/stack-project.nix)
(import ../modules/cabal-project.nix)
(import ../modules/project.nix)
] ++ projectModule';
}).config) src projectFileName;
dir = __readDir (src.origSrcSubDir or src);
Expand Down
14 changes: 4 additions & 10 deletions overlays/hix.nix
Expand Up @@ -12,17 +12,11 @@ final: prev: { haskell-nix = prev.haskell-nix // { hix = {
hixDefaults = { compiler-nix-name = lib.mkDefault "ghc8105"; };
inherit ((lib.evalModules {
modules = [
{
options = {
projectFileName = lib.mkOption {
type = lib.types.nullOr lib.types.str;
default = null;
};
};
}
(import ../modules/project.nix)
(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 = {}; }
Expand All @@ -42,7 +36,7 @@ final: prev: { haskell-nix = prev.haskell-nix // { hix = {
else import src;
projectDefaults = importDefaults (toString (src.origSrcSubDir or src) + "/nix/hix.nix");
in final.haskell-nix.project [
hixDefaults
(import ../modules/hix-project.nix)
projectDefaults
commandArgs'
{
Expand Down

0 comments on commit 9755952

Please sign in to comment.