Move the test module into a separate dir.
This commit is contained in:
parent
0cc421ead0
commit
015935f46e
6 changed files with 150 additions and 148 deletions
|
|
@ -195,7 +195,7 @@
|
||||||
systemConfigs.default = self.lib.makeSystemConfig {
|
systemConfigs.default = self.lib.makeSystemConfig {
|
||||||
system = flake-utils.lib.system.x86_64-linux;
|
system = flake-utils.lib.system.x86_64-linux;
|
||||||
modules = [
|
modules = [
|
||||||
./nix/modules
|
./test/nix/modules
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@ in
|
||||||
config = (lib.evalModules {
|
config = (lib.evalModules {
|
||||||
modules = [
|
modules = [
|
||||||
extraArgsModule
|
extraArgsModule
|
||||||
./modules/system-manager.nix
|
./modules
|
||||||
] ++ modules;
|
] ++ modules;
|
||||||
}).config;
|
}).config;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,80 +1,81 @@
|
||||||
{ lib
|
{ lib
|
||||||
, pkgs
|
, config
|
||||||
, ...
|
, ...
|
||||||
}:
|
}:
|
||||||
{
|
{
|
||||||
config = {
|
imports = [
|
||||||
environment.etc = {
|
./etc.nix
|
||||||
foo = {
|
./systemd.nix
|
||||||
text = ''
|
];
|
||||||
This is just a test!
|
|
||||||
'';
|
|
||||||
target = "foo_test";
|
|
||||||
};
|
|
||||||
|
|
||||||
"foo.conf".text = ''
|
options = {
|
||||||
launch_the_rockets = true
|
assertions = lib.mkOption {
|
||||||
|
type = lib.types.listOf lib.types.unspecified;
|
||||||
|
internal = true;
|
||||||
|
default = [ ];
|
||||||
|
example = [{ assertion = false; message = "you can't enable this for that reason"; }];
|
||||||
|
description = lib.mdDoc ''
|
||||||
|
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.
|
||||||
'';
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
"baz/bar/foo2" = {
|
warnings = lib.mkOption {
|
||||||
text = ''
|
internal = true;
|
||||||
Another test!
|
default = [ ];
|
||||||
'';
|
type = lib.types.listOf lib.types.str;
|
||||||
mode = "symlink";
|
example = [ "The `foo' service is deprecated and will go away soon!" ];
|
||||||
};
|
description = lib.mdDoc ''
|
||||||
|
This option allows modules to show warnings to users during
|
||||||
|
the evaluation of the system configuration.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
foo3 = {
|
system-manager = {
|
||||||
text = "boo!";
|
allowAnyDistro = lib.mkEnableOption "the usage of system-manager on untested distributions";
|
||||||
mode = "0700";
|
|
||||||
user = "root";
|
|
||||||
group = "root";
|
|
||||||
};
|
|
||||||
|
|
||||||
"a/nested/example/foo3" = {
|
preActivationAssertions = lib.mkOption {
|
||||||
text = "boo!";
|
type = with lib.types; attrsOf (submodule ({ name, ... }: {
|
||||||
mode = "0764";
|
options = {
|
||||||
user = "root";
|
enable = lib.mkEnableOption "the assertion";
|
||||||
group = "root";
|
|
||||||
};
|
|
||||||
|
|
||||||
"a/nested/example2/foo3" = {
|
name = lib.mkOption {
|
||||||
text = "boo!";
|
type = lib.types.str;
|
||||||
mode = "0764";
|
default = name;
|
||||||
user = "root";
|
};
|
||||||
group = "root";
|
|
||||||
};
|
|
||||||
|
|
||||||
out-of-store = {
|
script = lib.mkOption {
|
||||||
source = "/run/systemd/system/";
|
type = lib.types.str;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}));
|
||||||
|
default = { };
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
systemd.services =
|
};
|
||||||
lib.listToAttrs
|
|
||||||
(lib.flip lib.genList 10 (ix:
|
config = {
|
||||||
lib.nameValuePair "service-${toString ix}"
|
|
||||||
{
|
system-manager.preActivationAssertions = {
|
||||||
enable = true;
|
osVersion =
|
||||||
description = "service-${toString ix}";
|
let
|
||||||
wants = [ "network-online.target" ];
|
supportedIds = [ "nixos" "ubuntu" ];
|
||||||
after = [
|
in
|
||||||
"network-online.target"
|
{
|
||||||
"avahi-daemon.service"
|
enable = !config.system-manager.allowAnyDistro;
|
||||||
"chrony.service"
|
script = ''
|
||||||
"nss-lookup.target"
|
source /etc/os-release
|
||||||
"tinc.service"
|
${lib.concatStringsSep "\n" (lib.flip map supportedIds (supportedId: ''
|
||||||
"pulseaudio.service"
|
if [ $ID = "${supportedId}" ]; then
|
||||||
];
|
exit 0
|
||||||
serviceConfig = {
|
fi
|
||||||
Type = "oneshot";
|
''))}
|
||||||
RemainAfterExit = true;
|
echo "This OS is not currently supported."
|
||||||
ExecReload = "${lib.getBin pkgs.coreutils}/bin/true";
|
echo "Supported OSs are: ${lib.concatStringsSep ", " supportedIds}"
|
||||||
};
|
exit 1
|
||||||
wantedBy = [ "multi-user.target" ];
|
'';
|
||||||
requiredBy = lib.mkIf (ix > 5) [ "service-0.service" ];
|
};
|
||||||
script = ''
|
};
|
||||||
sleep ${if ix > 5 then "2" else "1"}
|
|
||||||
'';
|
|
||||||
})
|
|
||||||
);
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,81 +0,0 @@
|
||||||
{ lib
|
|
||||||
, config
|
|
||||||
, ...
|
|
||||||
}:
|
|
||||||
{
|
|
||||||
imports = [
|
|
||||||
./etc.nix
|
|
||||||
./systemd.nix
|
|
||||||
];
|
|
||||||
|
|
||||||
options = {
|
|
||||||
assertions = lib.mkOption {
|
|
||||||
type = lib.types.listOf lib.types.unspecified;
|
|
||||||
internal = true;
|
|
||||||
default = [ ];
|
|
||||||
example = [{ assertion = false; message = "you can't enable this for that reason"; }];
|
|
||||||
description = lib.mdDoc ''
|
|
||||||
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 = lib.mkOption {
|
|
||||||
internal = true;
|
|
||||||
default = [ ];
|
|
||||||
type = lib.types.listOf lib.types.str;
|
|
||||||
example = [ "The `foo' service is deprecated and will go away soon!" ];
|
|
||||||
description = lib.mdDoc ''
|
|
||||||
This option allows modules to show warnings to users during
|
|
||||||
the evaluation of the system configuration.
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
|
|
||||||
system-manager = {
|
|
||||||
allowAnyDistro = lib.mkEnableOption "the usage of system-manager on untested distributions";
|
|
||||||
|
|
||||||
preActivationAssertions = lib.mkOption {
|
|
||||||
type = with lib.types; attrsOf (submodule ({ name, ... }: {
|
|
||||||
options = {
|
|
||||||
enable = lib.mkEnableOption "the assertion";
|
|
||||||
|
|
||||||
name = lib.mkOption {
|
|
||||||
type = lib.types.str;
|
|
||||||
default = name;
|
|
||||||
};
|
|
||||||
|
|
||||||
script = lib.mkOption {
|
|
||||||
type = lib.types.str;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
}));
|
|
||||||
default = { };
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
config = {
|
|
||||||
|
|
||||||
system-manager.preActivationAssertions = {
|
|
||||||
osVersion =
|
|
||||||
let
|
|
||||||
supportedIds = [ "nixos" "ubuntu" ];
|
|
||||||
in
|
|
||||||
{
|
|
||||||
enable = !config.system-manager.allowAnyDistro;
|
|
||||||
script = ''
|
|
||||||
source /etc/os-release
|
|
||||||
${lib.concatStringsSep "\n" (lib.flip map supportedIds (supportedId: ''
|
|
||||||
if [ $ID = "${supportedId}" ]; then
|
|
||||||
exit 0
|
|
||||||
fi
|
|
||||||
''))}
|
|
||||||
echo "This OS is not currently supported."
|
|
||||||
echo "Supported OSs are: ${lib.concatStringsSep ", " supportedIds}"
|
|
||||||
exit 1
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
@ -95,6 +95,8 @@ fn find_flake_attr(flake_uri: &str) -> Result<Cow<'_, str>> {
|
||||||
anyhow::bail!("No suitable flake attribute found, giving up.");
|
anyhow::bail!("No suitable flake attribute found, giving up.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO handle errors better.
|
||||||
|
// E.g. when we refer to an unexisting module in the systemConfig definition.
|
||||||
fn try_flake_attr(flake_uri: &str) -> Result<bool> {
|
fn try_flake_attr(flake_uri: &str) -> Result<bool> {
|
||||||
log::info!("Trying flake URI: {flake_uri}...");
|
log::info!("Trying flake URI: {flake_uri}...");
|
||||||
let status = try_nix_eval(flake_uri)?;
|
let status = try_nix_eval(flake_uri)?;
|
||||||
|
|
|
||||||
80
test/nix/modules/default.nix
Normal file
80
test/nix/modules/default.nix
Normal file
|
|
@ -0,0 +1,80 @@
|
||||||
|
{ lib
|
||||||
|
, pkgs
|
||||||
|
, ...
|
||||||
|
}:
|
||||||
|
{
|
||||||
|
config = {
|
||||||
|
environment.etc = {
|
||||||
|
foo = {
|
||||||
|
text = ''
|
||||||
|
This is just a test!
|
||||||
|
'';
|
||||||
|
target = "foo_test";
|
||||||
|
};
|
||||||
|
|
||||||
|
"foo.conf".text = ''
|
||||||
|
launch_the_rockets = true
|
||||||
|
'';
|
||||||
|
|
||||||
|
"baz/bar/foo2" = {
|
||||||
|
text = ''
|
||||||
|
Another test!
|
||||||
|
'';
|
||||||
|
mode = "symlink";
|
||||||
|
};
|
||||||
|
|
||||||
|
foo3 = {
|
||||||
|
text = "boo!";
|
||||||
|
mode = "0700";
|
||||||
|
user = "root";
|
||||||
|
group = "root";
|
||||||
|
};
|
||||||
|
|
||||||
|
"a/nested/example/foo3" = {
|
||||||
|
text = "boo!";
|
||||||
|
mode = "0764";
|
||||||
|
user = "root";
|
||||||
|
group = "root";
|
||||||
|
};
|
||||||
|
|
||||||
|
"a/nested/example2/foo3" = {
|
||||||
|
text = "boo!";
|
||||||
|
mode = "0764";
|
||||||
|
user = "root";
|
||||||
|
group = "root";
|
||||||
|
};
|
||||||
|
|
||||||
|
out-of-store = {
|
||||||
|
source = "/run/systemd/system/";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
systemd.services =
|
||||||
|
lib.listToAttrs
|
||||||
|
(lib.flip lib.genList 10 (ix:
|
||||||
|
lib.nameValuePair "service-${toString ix}"
|
||||||
|
{
|
||||||
|
enable = true;
|
||||||
|
description = "service-${toString ix}";
|
||||||
|
wants = [ "network-online.target" ];
|
||||||
|
after = [
|
||||||
|
"network-online.target"
|
||||||
|
"avahi-daemon.service"
|
||||||
|
"chrony.service"
|
||||||
|
"nss-lookup.target"
|
||||||
|
"tinc.service"
|
||||||
|
"pulseaudio.service"
|
||||||
|
];
|
||||||
|
serviceConfig = {
|
||||||
|
Type = "oneshot";
|
||||||
|
RemainAfterExit = true;
|
||||||
|
ExecReload = "${lib.getBin pkgs.coreutils}/bin/true";
|
||||||
|
};
|
||||||
|
wantedBy = [ "multi-user.target" ];
|
||||||
|
requiredBy = lib.mkIf (ix > 5) [ "service-0.service" ];
|
||||||
|
script = ''
|
||||||
|
sleep ${if ix > 5 then "2" else "1"}
|
||||||
|
'';
|
||||||
|
})
|
||||||
|
);
|
||||||
|
};
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue