Enable the extension of lib

Signed-off-by: Magic_RB <magic_rb@redalder.org>
This commit is contained in:
Magic_RB 2023-06-18 20:07:47 +02:00
parent 734e9ab6a4
commit 3b5a09f9cb
No known key found for this signature in database
GPG key ID: 08D5287CC5DDCA0E
8 changed files with 89 additions and 40 deletions

View file

@ -36,10 +36,12 @@
udp-over-tcp.flake = false;
};
outputs = inputs@{ flake-parts, self, ... }:
flake-parts.lib.mkFlake { inherit inputs; } ({ config, ... }: {
outputs = inputs@{ flake-parts, self, secret, ... }:
flake-parts.lib.mkFlake { inherit inputs; } ({ config, lib', ... }: {
imports = [
modules/nixngConfigurations.nix
modules/lib_overlays.nix
lib/load_secrets.nix
nixos/systems/omen
nixos/systems/heater
@ -83,9 +85,19 @@
inputs.uterranix.flakeModule
];
_module.args.lib' =
let
inherit (inputs.nixpkgs) lib;
inherit (inputs.nixpkgs.lib)
extend;
in
lib.foldl (acc: x: acc.extend x) lib (with config.flake.libOverlays; [
loadSecrets
]);
flake.hydraJobs =
let
inherit (lib)
inherit (lib')
mapAttrs;
in
{
@ -96,6 +108,7 @@
uterranix.config = [
./terranix/default.nix
{
_module.args.secret = secret;
_module.args.vars = {
flake_rev = self.rev or null;
flake_sha = self.sha or null;
@ -137,7 +150,7 @@
{
packages =
let
inherit (lib)
inherit (lib')
attrValues;
pkgs' = pkgs.appendOverlays (attrValues config.flake.overlays);
in

14
lib/load_secrets.nix Normal file
View file

@ -0,0 +1,14 @@
# SPDX-FileCopyrightText: 2022 Richard Brežák <richard@brezak.sk>
#
# SPDX-License-Identifier: LGPL-3.0-or-later
{ lib, ... }:
{
flake.libOverlays.loadSecrets =
final: prev: (lib.traceVal {
loadSecrets = path:
if builtins.pathExists "${path}/default.nix" then
import path { lib = final; }
else
{};
});
}

38
modules/lib_overlays.nix Normal file
View file

@ -0,0 +1,38 @@
{ lib, flake-parts-lib, ... }:
let
inherit (lib)
mkOption
types
;
inherit (flake-parts-lib)
mkSubmoduleOptions
;
in
{
options = {
flake = mkSubmoduleOptions {
libOverlays = mkOption {
# uniq -> ordered: https://github.com/NixOS/nixpkgs/issues/147052
# also update description when done
type = types.lazyAttrsOf (types.uniq (types.functionTo (types.functionTo (types.lazyAttrsOf types.unspecified))));
# This eta expansion exists for the sole purpose of making nix flake check happy.
apply = lib.mapAttrs (_k: f: final: prev: f final prev);
default = { };
example = lib.literalExpression or lib.literalExample ''
{
default = final: prev: {};
}
'';
description = ''
An attribute set of lib overlays, they're similar to normal
[overlays](https://nixos.org/manual/nixpkgs/stable/#chap-overlays).
Note that the overlays themselves are not mergeable. While overlays
can be composed, the order of composition is significant, but the
module system does not guarantee sufficiently deterministic
definition ordering, across versions and when changing `imports`.
'';
};
};
};
}

View file

@ -1,9 +1,9 @@
# SPDX-FileCopyrightText: 2022 Richard Brežák <richard@brezak.sk>
#
# SPDX-License-Identifier: LGPL-3.0-or-later
{ inputs, lib, config, ... }:
{ inputs, lib', config, ... }:
let
inherit (lib)
inherit (lib')
flip
mapAttrs
singleton;
@ -17,11 +17,7 @@ in
specialArgs = {
config' = config';
inputs' = inputs;
secret =
if builtins.pathExists "${inputs.secret}/default.nix" then
import inputs.secret { inherit lib; }
else
{};
secret = lib'.loadSecrets inputs.secret;
};
modules = singleton

View file

@ -1,9 +1,9 @@
# SPDX-FileCopyrightText: 2022 Richard Brežák <richard@brezak.sk>
#
# SPDX-License-Identifier: LGPL-3.0-or-later
{ inputs, lib, config, secret, ... }:
{ inputs, lib', config, secret, ... }:
let
inherit (lib)
inherit (lib')
flip
mapAttrs
singleton;
@ -13,15 +13,12 @@ in
{
flake.nixosConfigurations.heater = inputs.nixpkgs.lib.nixosSystem {
system = "x86_64-linux";
lib = lib';
specialArgs = {
config' = config';
inputs' = inputs;
secret =
if builtins.pathExists "${inputs.secret}/default.nix" then
import inputs.secret { inherit lib; }
else
{};
secret = lib'.loadSecrets;
};
modules = singleton
({ pkgs, config, ... }:

View file

@ -1,9 +1,9 @@
# SPDX-FileCopyrightText: 2022 Richard Brežák <richard@brezak.sk>
#
# SPDX-License-Identifier: LGPL-3.0-or-later
{ inputs, lib, config, ... }:
{ inputs, lib', config, ... }:
let
inherit (lib)
inherit (lib')
flip
mapAttrs
singleton;
@ -13,15 +13,12 @@ in
{
flake.nixosConfigurations.liveusb = inputs.nixpkgs.lib.nixosSystem {
system = "x86_64-linux";
lib = lib';
specialArgs = {
config' = config';
inputs' = inputs;
secret =
if builtins.pathExists "${inputs.secret}/default.nix" then
import inputs.secret { inherit lib; }
else
{};
secret = lib'.loadSecrets inputs.secrets;
};
modules = singleton

View file

@ -1,27 +1,25 @@
# SPDX-FileCopyrightText: 2022 Richard Brežák <richard@brezak.sk>
#
# SPDX-License-Identifier: LGPL-3.0-or-later
{ inputs, lib, config, secret, ... }:
{ inputs, lib', config, secret, ... }:
let
inherit (lib)
inherit (lib')
flip
mapAttrs
singleton;
singleton
loadSecrets;
config' = config;
in
{
flake.nixosConfigurations.omen = inputs.nixpkgs.lib.nixosSystem {
system = "x86_64-linux";
lib = lib';
specialArgs = {
config' = config';
inputs' = inputs;
secret =
if builtins.pathExists "${inputs.secret}/default.nix" then
import inputs.secret { inherit lib; }
else
{};
secret = loadSecrets inputs.secret;
};
modules = singleton

View file

@ -1,9 +1,9 @@
# SPDX-FileCopyrightText: 2022 Richard Brežák <richard@brezak.sk>
#
# SPDX-License-Identifier: LGPL-3.0-or-later
{ inputs, lib, config, ... }:
{ inputs, lib', config, ... }:
let
inherit (lib)
inherit (lib')
flip
mapAttrs
singleton;
@ -17,11 +17,7 @@ in
specialArgs = {
config' = config';
inputs' = inputs;
secret =
if builtins.pathExists "${inputs.secret}/default.nix" then
import inputs.secret { inherit lib; }
else
{};
secret = lib'.loadSecrets inputs.secret;
};
modules = singleton