-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from the-computer-club/flake-guard-self-error
Option depreciations
- Loading branch information
Showing
6 changed files
with
106 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
{ lib, ... }: | ||
with lib; | ||
{ | ||
options = { | ||
assertions = mkOption { | ||
type = types.listOf types.unspecified; | ||
internal = true; | ||
default = []; | ||
example = [ { assertion = false; message = "you can't enable this for that reason"; } ]; | ||
description = '' | ||
This option allows modules to express conditions that must | ||
hold for the evaluation of the system configuration to | ||
succeed, along with associated error messages for the user. | ||
''; | ||
}; | ||
|
||
warnings = mkOption { | ||
internal = true; | ||
default = []; | ||
type = types.listOf types.str; | ||
example = [ "The `foo' service is deprecated and will go away soon!" ]; | ||
description = '' | ||
This option allows modules to show warnings to users during | ||
the evaluation of the system configuration. | ||
''; | ||
}; | ||
}; | ||
|
||
# impl of this is in lib.nix:evalFlakeModules | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
{ flake-parts-lib, ... }: | ||
with builtins; | ||
let | ||
inherit (flake-parts-lib) evalFlakeModule; | ||
|
||
singleModuleBase = x: { | ||
imports = [ | ||
./flake-modules/builtins/assertions.nix | ||
x | ||
]; | ||
}; | ||
|
||
evalAssertions = eval: | ||
let | ||
failedAssertions = map (x: x.message) (filter (x: !x.assertion) eval.config.assertions); | ||
warnings = eval.config.warnings; | ||
in | ||
if (failedAssertions != []) | ||
then | ||
builtins.abort (concatStringsSep "\n\n" failedAssertions) | ||
else | ||
if (warnings != []) | ||
then | ||
builtins.trace (concatStringsSep "\n\n" warnings) | ||
eval | ||
else eval; | ||
|
||
|
||
evalFlakeModuleWithAssertions = a: m: | ||
evalAssertions (evalFlakeModule a (singleModuleBase m)); | ||
in | ||
{ | ||
inherit evalFlakeModuleWithAssertions; | ||
mkFlakeWithAssertions = args: module: | ||
let | ||
eval = evalFlakeModuleWithAssertions args module; | ||
in | ||
eval.config.flake; | ||
} |