From 682183a88d8f7bc31b6172da9efa07f1f385928d Mon Sep 17 00:00:00 2001 From: Daniel Barlow Date: Fri, 14 Jul 2023 20:22:29 +0100 Subject: [PATCH] move typeChecked into pkgs.liminix.lib --- modules/base.nix | 6 +----- overlay.nix | 4 +++- pkgs/default.nix | 18 ++++++++++++++++++ pkgs/liminix-tools/networking/pppoe.nix | 9 +++------ 4 files changed, 25 insertions(+), 12 deletions(-) diff --git a/modules/base.nix b/modules/base.nix index c64d374..67eba8a 100644 --- a/modules/base.nix +++ b/modules/base.nix @@ -5,11 +5,7 @@ let inherit (pkgs.liminix.networking) address interface; inherit (pkgs.liminix.services) bundle; - type_service = types.package // { - name = "service"; - description = "s6-rc service"; - check = x: isDerivation x && hasAttr "serviceType" x; - }; + type_service = pkgs.liminix.lib.types.service; in { options = { diff --git a/overlay.nix b/overlay.nix index 06aaa2a..0bcf223 100644 --- a/overlay.nix +++ b/overlay.nix @@ -1,6 +1,8 @@ final: prev: let - extraPkgs = import ./pkgs/default.nix { inherit (final) callPackage; }; + extraPkgs = import ./pkgs/default.nix { + inherit (final) lib callPackage; + }; inherit (final) fetchpatch; lua_no_readline = prev.lua5_3.overrideAttrs(o: { name = "lua-tty"; diff --git a/pkgs/default.nix b/pkgs/default.nix index c9565af..0d03d0d 100644 --- a/pkgs/default.nix +++ b/pkgs/default.nix @@ -1,5 +1,6 @@ { callPackage +, lib }: { pseudofile = callPackage ./pseudofile {}; @@ -10,6 +11,23 @@ squashfs = callPackage ./liminix-tools/builders/squashfs.nix {}; kernel = callPackage ./kernel {}; }; + lib = { + types = { + service = + let inherit (lib) types isDerivation hasAttr; + in types.package // { + name = "service"; + description = "s6-rc service"; + check = x: isDerivation x && hasAttr "serviceType" x; + }; + }; + typeChecked = caller: type: value: + let + inherit (lib) types mergeDefinitions; + defs = [{ file = caller; inherit value; }]; + type' = types.submodule { options = type; }; + in (mergeDefinitions [] type' defs).mergedValue; + }; }; writeFennelScript = callPackage ./write-fennel-script {}; writeAshScript = callPackage ./write-ash-script {}; diff --git a/pkgs/liminix-tools/networking/pppoe.nix b/pkgs/liminix-tools/networking/pppoe.nix index 238ad17..bb30648 100644 --- a/pkgs/liminix-tools/networking/pppoe.nix +++ b/pkgs/liminix-tools/networking/pppoe.nix @@ -8,26 +8,23 @@ } : let inherit (liminix.services) longrun; + inherit (liminix.lib) typeChecked; inherit (lib) mergeDefinitions mkEnableOption mkOption isType types isDerivation hasAttr; t = { interface = mkOption { - type = types.package; # actually a service + type = liminix.lib.types.service; description = "ethernet interface to run PPPoE over"; }; ppp-options = mkOption { type = types.listOf types.str; }; }; - t' = types.submodule { options = t; }; - typeChecked = type: value: - let defs = [{ file = "pppoe.nix"; inherit value; }]; - in (lib.mergeDefinitions [ ] type defs).mergedValue; in params: let - inherit (typeChecked t' params) ppp-options interface; + inherit (typeChecked "pppoe.nix" t params) ppp-options interface; name = "${interface.device}.pppoe"; ip-up = writeAshScript "ip-up" {} '' . ${serviceFns}