Skip to content

Commit e58be2b

Browse files
committed
attrsOf -> lazyAttrsOf
This means we don't support `mkIf` in the exact places where the type was `attrsOf`. Almost always, `mkIf` can be replaced by `optionalAttrs`. The benefit is that the code becomes much lazier, improving performance and - Fixes srid#270
1 parent 938888c commit e58be2b

File tree

7 files changed

+13
-12
lines changed

7 files changed

+13
-12
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
- Breaking changes
1313
- #221: Switch to `buildFromSdist`, to allow using non-standard package sets (wherein `cabal-install` is otherwise built without using user's overrides)
1414
- #253: Turn off `buildFromSdist` by default. It can now be enabled manually by setting `settings.<name>.buildFromSdist` to `true`.
15+
- #271: Change all `types.attrsOf` to `types.lazyAttrsOf`. If you use `lib.mkIf` for `attrsOf` values (not `submodule` options), use `lib.optionalAttrs` instead. This fixes #270 (`basePackages`) and improves performance.
1516

1617
## 0.4.0 (Aug 22, 2023)
1718

nix/modules/project-tests.nix

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ in
1717
will create a flake check automatically.
1818
'';
1919
default = { };
20-
type = types.attrsOf (types.submoduleWith {
20+
type = types.lazyAttrsOf (types.submoduleWith {
2121
specialArgs = { inherit pkgs self; };
2222
modules = [
2323
{

nix/modules/project/default.nix

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ in
4141
else cls;
4242
};
4343
log = mkOption {
44-
type = types.attrsOf (types.functionTo types.raw);
44+
type = types.lazyAttrsOf (types.functionTo types.raw);
4545
default = import ../../logging.nix {
4646
name = config.projectFlakeName + "#haskellProjects." + name;
4747
};
@@ -52,7 +52,7 @@ in
5252
'';
5353
};
5454
basePackages = mkOption {
55-
type = types.attrsOf raw;
55+
type = types.lazyAttrsOf raw;
5656
description = ''
5757
Which Haskell package set / compiler to use.
5858

nix/modules/project/devshell.nix

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ let
2828
default = hp: { };
2929
};
3030
extraLibraries = mkOption {
31-
type = types.nullOr (functionTo (types.attrsOf (types.nullOr types.package)));
31+
type = types.nullOr (functionTo (types.lazyAttrsOf (types.nullOr types.package)));
3232
description = ''
3333
Extra Haskell libraries available in the shell's environment.
3434
These can be used in the shell's `runghc` and `ghci` for instance.
@@ -43,7 +43,7 @@ let
4343
};
4444

4545
mkShellArgs = mkOption {
46-
type = types.attrsOf types.raw;
46+
type = types.lazyAttrsOf types.raw;
4747
description = ''
4848
Extra arguments to pass to `pkgs.mkShell`.
4949
'';

nix/modules/project/outputs.nix

+4-4
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@ let
1616
};
1717
finalPackages = mkOption {
1818
# This must be raw because the Haskell package set also contains functions.
19-
type = types.attrsOf types.raw;
19+
type = types.lazyAttrsOf types.raw;
2020
readOnly = true;
2121
description = ''
2222
The final Haskell package set including local packages and any
2323
overrides, on top of `basePackages`.
2424
'';
2525
};
2626
packages = mkOption {
27-
type = types.attrsOf packageInfoSubmodule;
27+
type = types.lazyAttrsOf packageInfoSubmodule;
2828
readOnly = true;
2929
description = ''
3030
Package information for all local packages. Contains the following keys:
@@ -34,7 +34,7 @@ let
3434
'';
3535
};
3636
apps = mkOption {
37-
type = types.attrsOf appType;
37+
type = types.lazyAttrsOf appType;
3838
readOnly = true;
3939
description = ''
4040
Flake apps for each Cabal executable in the project.
@@ -52,7 +52,7 @@ let
5252
'';
5353
};
5454
exes = mkOption {
55-
type = types.attrsOf appType;
55+
type = types.lazyAttrsOf appType;
5656
description = ''
5757
Attrset of executables from `.cabal` file.
5858

nix/modules/project/settings/all.nix

+2-2
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ in
4545
if enable then markBroken else unmarkBroken;
4646
};
4747
brokenVersions = {
48-
type = types.attrsOf types.str;
48+
type = types.lazyAttrsOf types.str;
4949
description = ''
5050
List of versions that are known to be broken.
5151
'';
@@ -200,7 +200,7 @@ in
200200
removeConfigureFlags;
201201
};
202202
cabalFlags = {
203-
type = types.attrsOf types.bool;
203+
type = types.lazyAttrsOf types.bool;
204204
description = ''
205205
Cabal flags to enable or disable explicitly.
206206
'';

nix/modules/projects.nix

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ in
1212
options = {
1313
haskellProjects = mkOption {
1414
description = "Haskell projects";
15-
type = types.attrsOf (types.submoduleWith {
15+
type = types.lazyAttrsOf (types.submoduleWith {
1616
specialArgs = { inherit pkgs self; };
1717
modules = [
1818
./project

0 commit comments

Comments
 (0)