From 88b23667305f327aa45daa2e744c9421ab4c906a Mon Sep 17 00:00:00 2001 From: magic_rb Date: Thu, 26 Dec 2024 15:11:54 +0100 Subject: [PATCH] Rework `lib` Signed-off-by: magic_rb --- lib/dag.nix | 2 +- lib/default.nix | 55 ++++++++++++++++++++------------------------- lib/generators.nix | 2 +- lib/make-system.nix | 2 +- 4 files changed, 27 insertions(+), 34 deletions(-) diff --git a/lib/dag.nix b/lib/dag.nix index 2c5d7a1..298c33c 100644 --- a/lib/dag.nix +++ b/lib/dag.nix @@ -6,7 +6,7 @@ # License, v. 2.0. If a copy of the MPL was not distributed with this # file, You can obtain one at http://mozilla.org/MPL/2.0/. -{ lib }: +{ lib, ... }: import (builtins.fetchurl { url = "https://raw.githubusercontent.com/nix-community/home-manager/45abf3d38a2b51c00c347cab6950f3734e023bba/modules/lib/dag.nix"; sha256 = "sha256-NN9iKanf86D1MH9Nx8nsQj9T2+Poy9XeW9pLcZIyFHU="; diff --git a/lib/default.nix b/lib/default.nix index 6fd3b9e..0d3ae03 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -1,13 +1,15 @@ lib: -let - inherit (lib) types; - this = { - makeSystem = import ./make-system.nix { - nglib = this; - overlay = import ../overlay; +lib.fix ( + nglib: + let + overlay = import ../overlay; + args = { + inherit lib nglib overlay; }; - dag = import ./dag.nix { inherit lib; }; - generators = import ./generators.nix { inherit lib; }; + in + { + dag = import ./dag.nix args; + generators = import ./generators.nix args; mkDefaultRec = lib.mapAttrsRecursive (_: v: lib.mkDefault v); mkApply = fun: x: { original = x; @@ -18,31 +20,31 @@ let description: lib.mkOption { inherit description; - type = types.attrsOf ( - types.submodule { + type = lib.types.attrsOf ( + lib.types.submodule { options = { data = lib.mkOption { description = '' Script fragment which to run. ''; - type = types.str; + type = lib.types.str; }; before = lib.mkOption { description = '' Script before dependencies. See /lib/dag.nix. ''; - type = with types; listOf str; + type = lib.types.listOf lib.types.str; }; after = lib.mkOption { description = '' Script after dependencies. See /lib/dag.nix ''; - type = with types; listOf str; + type = lib.types.listOf lib.types.str; }; }; } ); - apply = this.dag.dagTopoSort; + apply = nglib.dag.dagTopoSort; default = { }; }; @@ -64,10 +66,7 @@ let )} ''; - nottmpfiles = import ./nottmpfiles { - inherit lib; - nglib = this; - }; + nottmpfiles = import ./nottmpfiles args; maybeChangeUserAndGroup = user: group: script: @@ -75,16 +74,10 @@ let "chpst -u ${user}${lib.optionalString (group != null) ":${group}"} ${script}" else script; - }; -in -this -// { - inherit - (import ./options.nix { - inherit lib; - nglib = this; - }) - mkUserOption - mkGroupOption - ; -} + + inherit (import ./options.nix args) mkUserOption mkGroupOption; + + makeSystem = import ./make-system.nix { inherit lib nglib overlay; }; + + } +) diff --git a/lib/generators.nix b/lib/generators.nix index 551241e..451cd96 100644 --- a/lib/generators.nix +++ b/lib/generators.nix @@ -6,7 +6,7 @@ # License, v. 2.0. If a copy of the MPL was not distributed with this # file, You can obtain one at http://mozilla.org/MPL/2.0/. -{ lib }: +{ lib, ... }: let inherit (lib) isAttrs diff --git a/lib/make-system.nix b/lib/make-system.nix index 1f8ae23..a5bd2aa 100644 --- a/lib/make-system.nix +++ b/lib/make-system.nix @@ -7,7 +7,7 @@ # file, You can obtain one at http://mozilla.org/MPL/2.0/. # These arguments are provided by the overarching NixNG repository and are not user confugurable. -{ nglib, overlay }: +{ nglib, overlay, ... }: # These arguments are user configurable { nixpkgs,