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

Don't read swap files during evaluation #352252

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
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
22 changes: 20 additions & 2 deletions lib/types.nix
Original file line number Diff line number Diff line change
Expand Up @@ -1029,8 +1029,26 @@ rec {
getSubOptions = finalType.getSubOptions;
getSubModules = finalType.getSubModules;
substSubModules = m: coercedTo coercedType coerceFunc (finalType.substSubModules m);
typeMerge = t: null;
functor = (defaultFunctor name) // { wrapped = finalType; };
typeMerge = f':
let coercedType' = coercedType.typeMerge (f'.coercedType).functor;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably merge with either instead of a typeMerge, and support multiple coercion functions that way.

(not the original goal of this PR at all though...)

finalType' = finalType.typeMerge (f'.wrapped).functor;
coerceFunc' =
if coerceFunc == null
then f'.coerceFunc
else if f'.coerceFunc == null
then coerceFunc
else # both are non-null, but only one conversion function can be used
null;
in
if name == f'.name
&& coercedType' != null
&& finalType' != null
then functor.type coercedType' coerceFunc' finalType'
else null;
functor = (defaultFunctor name) // {
wrapped = finalType;
inherit coercedType coerceFunc;
};
nestedTypes.coercedType = coercedType;
nestedTypes.finalType = finalType;
};
Expand Down
8 changes: 6 additions & 2 deletions nixos/modules/config/swap.nix
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,12 @@ in
{command}`mkswap -L`). Using a label is
recommended.
'';

type = types.listOf (types.submodule swapCfg);
type =
let
t = types.submodule swapCfg;
disallow = s: throw "Definitions for swapDevices items must be submodules, normally either { device = \"…\"; } or { label = \"…\"; }, but got a definition that is just ${lib.strings.escapeNixString s}";
in
types.listOf (types.coercedTo types.str disallow t // { inherit (t) description; });
};

};
Expand Down
2 changes: 1 addition & 1 deletion nixos/modules/tasks/encrypted-devices.nix
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ in
type = with lib.types; attrsOf (submodule encryptedFSOptions);
};
swapDevices = mkOption {
type = with lib.types; listOf (submodule encryptedFSOptions);
type = with lib.types; listOf (coercedTo str null (submodule encryptedFSOptions));
};
};

Expand Down