forked from DGNum/liminix
WIP introduce nixos module system for configuration
This commit is contained in:
parent
0f999f9ae4
commit
887a4ff966
6 changed files with 59 additions and 0 deletions
8
merge-modules.nix
Normal file
8
merge-modules.nix
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
module : initial : pkgs :
|
||||||
|
let evalModules = (import <nixpkgs/lib>).evalModules;
|
||||||
|
in evalModules {
|
||||||
|
modules = [
|
||||||
|
{ _module.args = { inherit pkgs; }; }
|
||||||
|
module
|
||||||
|
];
|
||||||
|
}
|
10
tests/module/configuration.nix
Normal file
10
tests/module/configuration.nix
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
{ config, pkgs, ... } :
|
||||||
|
{
|
||||||
|
imports = [ ./defs.nix ./module.nix ];
|
||||||
|
config = {
|
||||||
|
services.a.enable = true;
|
||||||
|
services.b.enable = true;
|
||||||
|
|
||||||
|
systemPackages = [ pkgs.hello ] ;
|
||||||
|
};
|
||||||
|
}
|
16
tests/module/defs.nix
Normal file
16
tests/module/defs.nix
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
{ lib, ...}:
|
||||||
|
let inherit (lib) mkEnableOption mkOption types;
|
||||||
|
in {
|
||||||
|
options = {
|
||||||
|
services.a = {
|
||||||
|
enable = mkEnableOption "hello service";
|
||||||
|
};
|
||||||
|
services.b = {
|
||||||
|
enable = mkEnableOption "other service";
|
||||||
|
};
|
||||||
|
services.z = mkOption { };
|
||||||
|
systemPackages = mkOption {
|
||||||
|
type = types.listOf types.package;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
6
tests/module/module.nix
Normal file
6
tests/module/module.nix
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
{ config, pkgs, ... } :
|
||||||
|
{
|
||||||
|
services.z = pkgs.figlet;
|
||||||
|
|
||||||
|
systemPackages = [ pkgs.units ] ;
|
||||||
|
}
|
2
tests/module/run.sh
Executable file
2
tests/module/run.sh
Executable file
|
@ -0,0 +1,2 @@
|
||||||
|
set -e
|
||||||
|
NIXPKGS_ALLOW_UNSUPPORTED_SYSTEM=1 nix-build --arg device "import <liminix/devices/qemu.nix>" test.nix
|
17
tests/module/test.nix
Normal file
17
tests/module/test.nix
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
{ device }:
|
||||||
|
let
|
||||||
|
overlay = import <liminix/overlay.nix> ;
|
||||||
|
nixpkgs = import <nixpkgs> ( device.system // {overlays = [overlay]; });
|
||||||
|
inherit (nixpkgs) lib pkgs;
|
||||||
|
inherit (lib.asserts) assertMsg;
|
||||||
|
config =
|
||||||
|
(import <liminix/merge-modules.nix>) ./configuration.nix {} pkgs;
|
||||||
|
res1 = assertMsg
|
||||||
|
# check we have packages from both modules
|
||||||
|
(config.config.systemPackages == ( with pkgs; [ units hello ])) "failed";
|
||||||
|
res2 = let s = config.config.services;
|
||||||
|
in assertMsg (s.a.enable && s.b.enable && (s.z != null) ) "failed";
|
||||||
|
in pkgs.writeText "foo" ''
|
||||||
|
${if res1 then "OK" else "not OK"}
|
||||||
|
${if res2 then "OK" else "not OK"}
|
||||||
|
''
|
Loading…
Reference in a new issue