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; udp-over-tcp.flake = false;
}; };
outputs = inputs@{ flake-parts, self, ... }: outputs = inputs@{ flake-parts, self, secret, ... }:
flake-parts.lib.mkFlake { inherit inputs; } ({ config, ... }: { flake-parts.lib.mkFlake { inherit inputs; } ({ config, lib', ... }: {
imports = [ imports = [
modules/nixngConfigurations.nix modules/nixngConfigurations.nix
modules/lib_overlays.nix
lib/load_secrets.nix
nixos/systems/omen nixos/systems/omen
nixos/systems/heater nixos/systems/heater
@ -83,9 +85,19 @@
inputs.uterranix.flakeModule 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 = flake.hydraJobs =
let let
inherit (lib) inherit (lib')
mapAttrs; mapAttrs;
in in
{ {
@ -96,6 +108,7 @@
uterranix.config = [ uterranix.config = [
./terranix/default.nix ./terranix/default.nix
{ {
_module.args.secret = secret;
_module.args.vars = { _module.args.vars = {
flake_rev = self.rev or null; flake_rev = self.rev or null;
flake_sha = self.sha or null; flake_sha = self.sha or null;
@ -137,7 +150,7 @@
{ {
packages = packages =
let let
inherit (lib) inherit (lib')
attrValues; attrValues;
pkgs' = pkgs.appendOverlays (attrValues config.flake.overlays); pkgs' = pkgs.appendOverlays (attrValues config.flake.overlays);
in 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-FileCopyrightText: 2022 Richard Brežák <richard@brezak.sk>
# #
# SPDX-License-Identifier: LGPL-3.0-or-later # SPDX-License-Identifier: LGPL-3.0-or-later
{ inputs, lib, config, ... }: { inputs, lib', config, ... }:
let let
inherit (lib) inherit (lib')
flip flip
mapAttrs mapAttrs
singleton; singleton;
@ -17,11 +17,7 @@ in
specialArgs = { specialArgs = {
config' = config'; config' = config';
inputs' = inputs; inputs' = inputs;
secret = secret = lib'.loadSecrets inputs.secret;
if builtins.pathExists "${inputs.secret}/default.nix" then
import inputs.secret { inherit lib; }
else
{};
}; };
modules = singleton modules = singleton

View file

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

View file

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

View file

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

View file

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