Skip to content

Commit

Permalink
more tests
Browse files Browse the repository at this point in the history
Signed-off-by: lucasew <[email protected]>
  • Loading branch information
lucasew committed Jan 8, 2025
1 parent c8a8afa commit d496a92
Show file tree
Hide file tree
Showing 9 changed files with 133 additions and 0 deletions.
1 change: 1 addition & 0 deletions tests/nowith-nixos-submodule-shadow/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import <test-nixpkgs> { root = ./.; }
1 change: 1 addition & 0 deletions tests/nowith-nixos-submodule-shadow/expected
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- test.nix: Top level with is discouraged as it may shadow variables and break static checks.
38 changes: 38 additions & 0 deletions tests/nowith-nixos-submodule-shadow/test.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{ config
, lib
}:

let
cfg = config.foo;
in {
options.foo = lib.mkOption {
type = # random example from nixpkgs
with lib.types;
attrsOf (
either path (submodule {
options = {
service = lib.mkOption {
type = nullOr str;
default = null;
description = "The service on which to perform \<action\> after fetching.";
};

action = lib.mkOption {
type = addCheck str (
x:
cfg.svcManager == "command"
|| lib.elem x [
"restart"
"reload"
"nop"
]
);
default = "nop";
description = "The action to take after fetching.";
};
};
})
);
};
}

1 change: 1 addition & 0 deletions tests/nowith-nixos-submodule-unshadow-inherit/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import <test-nixpkgs> { root = ./.; }
1 change: 1 addition & 0 deletions tests/nowith-nixos-submodule-unshadow-inherit/expected
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Validated successfully
52 changes: 52 additions & 0 deletions tests/nowith-nixos-submodule-unshadow-inherit/test.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{ config
, lib
}:

let
cfg = config.foo;

inherit (lib)
mkOption
elem
;

inherit (lib.types)
attrsOf
either
path
submodule
nullOr
str
addCheck
;
in {
options.foo = mkOption {
type = # random example from nixpkgs
attrsOf (
either path (submodule {
options = {
service = mkOption {
type = nullOr str;
default = null;
description = "The service on which to perform \<action\> after fetching.";
};

action = mkOption {
type = addCheck str (
x:
cfg.svcManager == "command"
|| elem x [
"restart"
"reload"
"nop"
]
);
default = "nop";
description = "The action to take after fetching.";
};
};
})
);
};
}

1 change: 1 addition & 0 deletions tests/nowith-nixos-submodule-unshadow/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import <test-nixpkgs> { root = ./.; }
1 change: 1 addition & 0 deletions tests/nowith-nixos-submodule-unshadow/expected
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Validated successfully
37 changes: 37 additions & 0 deletions tests/nowith-nixos-submodule-unshadow/test.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{ config
, lib
}:

let
cfg = config.foo;
in {
options.foo = lib.mkOption {
type = # random example from nixpkgs
lib.types.attrsOf (
lib.types.either lib.types.path (lib.types.submodule {
options = {
service = lib.mkOption {
type = lib.types.nullOr lib.types.str;
default = null;
description = "The service on which to perform \<action\> after fetching.";
};

action = lib.mkOption {
type = lib.types.addCheck lib.types.str (
x:
cfg.svcManager == "command"
|| lib.elem x [
"restart"
"reload"
"nop"
]
);
default = "nop";
description = "The action to take after fetching.";
};
};
})
);
};
}

0 comments on commit d496a92

Please sign in to comment.