57 lines
1.7 KiB
Nix
57 lines
1.7 KiB
Nix
{
|
|
# Defines a minimal NixOS module with one option and one config effect,
|
|
# exposes it as `nixosModules.default`, and verifies it by evaluating a
|
|
# throwaway NixOS configuration that imports the module.
|
|
description = "A minimal NixOS module";
|
|
|
|
inputs = {
|
|
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
|
|
};
|
|
|
|
outputs =
|
|
{ self, nixpkgs, ... }:
|
|
let
|
|
system = "x86_64-linux";
|
|
pkgs = nixpkgs.legacyPackages.${system};
|
|
|
|
# Throwaway NixOS configuration used only by the check below.
|
|
# We never build `system.build.toplevel`, so bootloader and
|
|
# `fileSystems` assertions never fire; reading a single config
|
|
# attribute is enough to prove the module evaluates.
|
|
testConfig = nixpkgs.lib.nixosSystem {
|
|
inherit system;
|
|
modules = [
|
|
self.nixosModules.default
|
|
{
|
|
system.stateVersion = "24.11";
|
|
playground.greeter = {
|
|
enable = true;
|
|
name = "flakes";
|
|
};
|
|
}
|
|
];
|
|
};
|
|
in
|
|
{
|
|
# Other flakes consume the module via:
|
|
# imports = [ inputs.nix-playground.nixosModules.default ];
|
|
nixosModules.default = import ./module.nix;
|
|
|
|
# Builds only if the merged config's greeting matches expectation.
|
|
checks.${system}.greeting =
|
|
pkgs.runCommand "greeting-check"
|
|
{
|
|
got = testConfig.config.environment.etc."greeting".text;
|
|
expected = "hello, flakes";
|
|
}
|
|
''
|
|
if [ "$got" = "$expected" ]; then
|
|
echo ok > $out
|
|
else
|
|
echo "unexpected greeting: $got" >&2
|
|
exit 1
|
|
fi
|
|
'';
|
|
};
|
|
}
|