refactor: rename utils to lib'
check / lint (push) Successful in 15s

This commit is contained in:
hektor committed 2026-11-06 14:35:01 +01:00
1 parent 1947ee0c9f
commit 6fa74fead8
22 files changed
+116 -144

No files matched your search

+6 -10
View File
@@ -5,20 +5,20 @@
let
inherit (inputs.nixpkgs) lib;
utils = import ../utils { inherit lib; };
lib' = import ../lib { inherit lib; };
# exclude hosts that need auto rollback (until `colmena` supports it) for
# now, we use `deploy-rs` (which has magic rollback) for those (also see ./deploy-rs.nix)
#
# see <https://github.com/nix-community/colmena/issues/38>
# <https://github.com/nix-community/colmena/issues/344>
hostnames = lib.filter (
hostname: !((utils.hostMeta ../hosts/${hostname}).deploy.autoRollback or false)
) (utils.dirNames ../hosts);
hostname: !((lib'.hostMeta hostname).deploy.autoRollback or false)
) lib'.nixosHosts;
mkNode =
hostname:
let
meta = utils.hostMeta ../hosts/${hostname};
meta = lib'.hostMeta hostname;
isArm = meta.system == "aarch64-linux";
in
{
@@ -40,13 +40,9 @@ inputs.colmena.lib.makeHive (
meta = {
nixpkgs = import inputs.nixpkgs { localSystem = "x86_64-linux"; };
specialArgs = {
inherit inputs;
inherit inputs lib';
outputs = self;
myUtils = utils;
paths = {
dots = ../dots;
hosts = ../hosts;
};
dotsPath = ../dots;
};
};
}
+4 -4
View File
@@ -5,18 +5,18 @@
let
inherit (inputs.nixpkgs) lib;
utils = import ../utils { inherit lib; };
lib' = import ../lib { inherit lib; };
# only include hosts that need auto rollback (until `colmena` supports it)
# `colmena` is used for other hosts (see ./colmena.nix)
hostnames = lib.filter (
hostname: (utils.hostMeta ../hosts/${hostname}).deploy.autoRollback or false
) (utils.dirNames ../hosts);
hostname: (lib'.hostMeta hostname).deploy.autoRollback or false
) lib'.nixosHosts;
mkNode =
hostname:
let
meta = utils.hostMeta ../hosts/${hostname};
meta = lib'.hostMeta hostname;
in
{
inherit hostname;
+7 -21
View File
@@ -74,15 +74,9 @@
...
}@inputs:
let
inherit (self) outputs;
inherit (inputs.nixpkgs) lib;
myUtils = import ./utils { inherit lib; };
hostDirNames = myUtils.dirNames ./hosts;
lib' = import ./lib { inherit lib; };
system = "x86_64-linux";
paths = {
dots = ./dots;
hosts = ./hosts;
};
gitHooks = import ./git-hooks.nix {
inherit nixpkgs git-hooks system;
src = ./.;
@@ -90,22 +84,20 @@
in
{
nixosConfigurations =
(lib.genAttrs hostDirNames (
(lib.genAttrs lib'.nixosHosts (
host:
nixpkgs.lib.nixosSystem {
modules = [
./hosts/${host}
{
nixpkgs.hostPlatform = (myUtils.hostMeta ./hosts/${host}).system;
nixpkgs.hostPlatform = (lib'.hostMeta host).system;
host.name = host;
}
];
specialArgs = {
inherit
inputs
outputs
paths
myUtils
lib'
;
};
}
@@ -123,9 +115,7 @@
specialArgs = {
inherit
inputs
outputs
paths
myUtils
lib'
;
};
};
@@ -141,9 +131,7 @@
specialArgs = {
inherit
inputs
outputs
paths
myUtils
lib'
;
};
};
@@ -160,9 +148,7 @@
osConfig = null;
inherit
inputs
outputs
paths
myUtils
lib'
;
};
};
+3 -3
View File
@@ -2,21 +2,21 @@
config,
lib,
pkgs,
myUtils,
lib',
osConfig ? null,
inputs ? null,
...
}:
let
sops = myUtils.sopsAvailability config osConfig;
sops = lib'.sopsAvailability config osConfig;
standalone = osConfig == null;
in
{
config = lib.mkIf config.ai-tools.opencode.enable (
lib.optionalAttrs standalone {
sops = {
secrets = myUtils.mkSopsSecrets "${toString inputs.nix-secrets}/secrets" {
secrets = lib'.mkSopsSecrets "${toString inputs.nix-secrets}/secrets" null {
opencode = [ "api-key" ];
};
templates."opencode/auth.json" = {
+3 -3
View File
@@ -2,7 +2,7 @@
config,
lib,
pkgs,
myUtils,
lib',
osConfig ? null,
inputs ? null,
...
@@ -10,7 +10,7 @@
let
cfg = config.anki;
sops = myUtils.sopsAvailability config osConfig;
sops = lib'.sopsAvailability config osConfig;
standalone = osConfig == null;
in
{
@@ -18,7 +18,7 @@ in
config = lib.mkIf cfg.enable (
lib.optionalAttrs standalone {
sops.secrets = myUtils.mkSopsSecrets "${toString inputs.nix-secrets}/secrets" {
sops.secrets = lib'.mkSopsSecrets "${toString inputs.nix-secrets}/secrets" null {
anki = [
"sync-user"
"sync-key"
+2 -2
View File
@@ -2,14 +2,14 @@
config,
lib,
pkgs,
myUtils,
lib',
...
}:
{
imports =
let
dirs = myUtils.dirNames ./.;
dirs = lib'.dirNames ./.;
hasDef = name: builtins.pathExists ./${name}/default.nix;
in
map (name: ./${name}) (builtins.filter hasDef dirs);
+4 -5
View File
@@ -3,23 +3,22 @@
lib,
pkgs,
inputs,
myUtils,
paths,
lib',
...
}:
let
cfg = config.deploy;
hostNames = myUtils.dirNames paths.hosts;
inherit (lib') hostNames;
hostsWithKeys = lib.filter (
hostname: builtins.pathExists (paths.hosts + "/${hostname}/ssh_host.pub")
hostname: builtins.pathExists (lib'.hostsPath + "/${hostname}/ssh_host.pub")
) hostNames;
colmena = inputs.colmena.packages.${pkgs.stdenv.hostPlatform.system}.colmena;
deployRs = inputs.deploy-rs.packages.${pkgs.stdenv.hostPlatform.system}.default;
hostTags = hostname: (myUtils.hostMeta (paths.hosts + "/${hostname}")).tags;
hostTags = hostname: (lib'.hostMeta hostname).tags;
nodeTagsDecl = ''
declare -A _colmena_node_tags=(
${lib.concatMapStringsSep "\n" (
+3 -3
View File
@@ -2,14 +2,14 @@
config,
inputs,
lib,
myUtils,
lib',
osConfig ? null,
...
}:
let
cfg = config.git;
sops = myUtils.sopsAvailability config osConfig;
sops = lib'.sopsAvailability config osConfig;
standalone = osConfig == null;
personalEmail = sops.templates.".gitconfig.email".path;
@@ -50,7 +50,7 @@ in
config = lib.mkIf cfg.enable (
lib.optionalAttrs standalone {
sops = {
secrets = myUtils.mkSopsSecrets "${toString inputs.nix-secrets}/secrets" {
secrets = lib'.mkSopsSecrets "${toString inputs.nix-secrets}/secrets" null {
email = [
"personal"
"work"
+2 -2
View File
@@ -1,7 +1,7 @@
{
config,
lib,
paths,
lib',
...
}:
@@ -66,6 +66,6 @@ in
'';
};
home.sessionPath = lib.optional cfg.addBinToPath "${paths.dots}/.bin";
home.sessionPath = lib.optional cfg.addBinToPath "${lib'.dotsPath}/.bin";
};
}
+5 -6
View File
@@ -2,17 +2,16 @@
config,
lib,
pkgs,
myUtils,
paths,
lib',
...
}:
let
cfg = config.ssh;
hostNames = myUtils.dirNames paths.hosts;
hostsWithKeys = lib.filter (
hostname: builtins.pathExists (paths.hosts + "/${hostname}/ssh_host.pub")
) hostNames;
hostname: builtins.pathExists (lib'.hostsPath + "/${hostname}/ssh_host.pub")
) lib'.hostNames;
in
{
options.ssh.enable = lib.mkEnableOption "ssh";
@@ -37,7 +36,7 @@ in
lib.genAttrs hostsWithKeys (
hostname:
let
meta = myUtils.hostMeta (paths.hosts + "/${hostname}");
meta = lib'.hostMeta hostname;
in
{
User = meta.host.username;
+3 -3
View File
@@ -2,14 +2,14 @@
config,
lib,
pkgs,
myUtils,
lib',
osConfig ? null,
inputs ? null,
...
}:
let
sops = myUtils.sopsAvailability config osConfig;
sops = lib'.sopsAvailability config osConfig;
standalone = osConfig == null;
syncHook = pkgs.writers.writePython3 "on-exit.sync.py" { flakeIgnore = [ "E501" ]; } ''
@@ -64,7 +64,7 @@ in
config = lib.mkIf config.taskwarrior.enable (
lib.optionalAttrs standalone {
sops = {
secrets = myUtils.mkSopsSecrets "${toString inputs.nix-secrets}/secrets" {
secrets = lib'.mkSopsSecrets "${toString inputs.nix-secrets}/secrets" null {
taskwarrior = [
"sync-server-url"
"sync-server-client-id"
+3 -1
View File
@@ -4,5 +4,7 @@ let
fs = import ./fs.nix { inherit lib; };
hosts = import ./hosts.nix { inherit lib; };
secrets = import ./secrets.nix { inherit lib; };
dotsPath = ../dots;
in
fs // hosts // secrets
fs // hosts // secrets // { inherit dotsPath; }
View File
File renamed without changes.
+23
View File
@@ -0,0 +1,23 @@
{ lib }:
let
fs = import ./fs.nix { inherit lib; };
hostsPath = ../hosts;
hostMeta =
host:
let
metaPath = hostsPath + "/${host}/meta.nix";
in
if builtins.pathExists metaPath then
import metaPath
else
throw "meta.nix required in ${toString metaPath}";
hostNames = fs.dirNames hostsPath;
in
{
inherit hostsPath hostMeta hostNames;
adminHosts = builtins.filter (host: (hostMeta host).host.admin or false) hostNames;
nixosHosts = hostNames;
}
+34
View File
@@ -0,0 +1,34 @@
{ lib }:
{
mkSopsSecrets =
sopsDir: owner: groups:
let
opts = lib.optionalAttrs (owner != null) { inherit owner; };
mkGroup =
group: names:
lib.listToAttrs (
map (name: {
name = "${group}/${name}";
value = {
sopsFile = "${sopsDir}/${group}.yaml";
key = name;
}
// opts;
}) names
);
in
lib.mergeAttrsList (lib.mapAttrsToList mkGroup groups);
sopsAvailability =
config: osConfig:
let
osSopsAvailable = osConfig != null && osConfig ? sops && osConfig.sops ? secrets;
hmSopsAvailable = config ? sops && config.sops ? secrets;
in
{
available = osSopsAvailable || hmSopsAvailable;
secrets = if osSopsAvailable then osConfig.sops.secrets else config.sops.secrets;
templates = if osSopsAvailable then osConfig.sops.templates else config.sops.templates;
};
}
+2 -6
View File
@@ -1,8 +1,6 @@
{
inputs,
outputs,
paths,
myUtils,
lib',
config,
lib,
...
@@ -20,9 +18,7 @@ in
extraSpecialArgs = {
inherit
inputs
outputs
paths
myUtils
lib'
;
};
sharedModules = [
+2 -2
View File
@@ -3,7 +3,7 @@
inputs,
pkgs,
config,
myUtils,
lib',
...
}:
@@ -61,7 +61,7 @@ in
config = lib.mkIf cfg.enable {
sops = {
secrets = myUtils.mkSopsSecrets sopsDir system // myUtils.mkSopsUserSecrets sopsDir owner cfg.user;
secrets = lib'.mkSopsSecrets sopsDir null system // lib'.mkSopsSecrets sopsDir owner cfg.user;
};
nix.settings.secret-key-files = lib.mkIf cfg.nixSigningKey.enable [
+3 -3
View File
@@ -1,13 +1,13 @@
{
lib,
config,
paths,
lib',
...
}:
let
inherit (config.host) username;
adminHosts = (import ../../utils { inherit lib; }).adminHosts paths.hosts;
inherit (lib') adminHosts;
in
{
options.ssh = {
@@ -23,7 +23,7 @@ in
map (
hostname:
let
keyFile = paths.hosts + "/${hostname}/ssh_user.pub";
keyFile = lib'.hostsPath + "/${hostname}/ssh_user.pub";
in
lib.optionals (builtins.pathExists keyFile) (lib.splitString "\n" (builtins.readFile keyFile))
) ((builtins.filter (h: h != config.host.name) adminHosts) ++ config.ssh.authorizedHosts)
+3 -4
View File
@@ -1,14 +1,13 @@
{
lib,
config,
outputs,
paths,
lib',
...
}:
let
hosts = lib.attrNames outputs.nixosConfigurations;
keyPath = hostname: paths.hosts + "/${hostname}/ssh_host.pub";
hosts = lib'.nixosHosts;
keyPath = hostname: lib'.hostsPath + "/${hostname}/ssh_host.pub";
hostsWithKeys = lib.filter (hostname: builtins.pathExists (keyPath hostname)) hosts;
in
{
+4 -5
View File
@@ -1,16 +1,15 @@
{
lib,
config,
outputs,
paths,
myUtils,
inputs,
lib',
pkgs,
...
}:
let
hosts = myUtils.dirNames paths.hosts;
interfaces = host: outputs.nixosConfigurations.${host}.config.wol.interfaces;
hosts = lib'.nixosHosts;
interfaces = host: inputs.self.nixosConfigurations.${host}.config.wol.interfaces;
in
{
options.wol = {
-19
View File
@@ -1,19 +0,0 @@
{ lib }:
let
fs = import ./fs.nix { inherit lib; };
in
{
hostMeta =
hostDir:
if builtins.pathExists (hostDir + "/meta.nix") then
import (hostDir + "/meta.nix")
else
throw "meta.nix required in ${toString hostDir}";
adminHosts =
hostsPath:
builtins.filter (host: ((import (hostsPath + "/${host}/meta.nix")).host.admin or false)) (
fs.dirNames hostsPath
);
}
-42
View File
@@ -1,42 +0,0 @@
{ lib }:
let
mkSecrets =
sopsDir: owner: groups:
let
opts = lib.optionalAttrs (owner != null) { inherit owner; };
mkGroup =
group: names:
let
file = "${group}.yaml";
in
lib.foldl' lib.mergeAttrs { } (
map (name: {
"${group}/${name}" = {
sopsFile = "${sopsDir}/${file}";
key = name;
}
// opts;
}) names
);
in
lib.foldl' lib.mergeAttrs { } (lib.mapAttrsToList mkGroup groups);
in
{
mkSopsSecrets = sopsDir: mkSecrets sopsDir null;
mkSopsUserSecrets = mkSecrets;
sopsAvailability =
config: osConfig:
let
osSopsAvailable = osConfig != null && osConfig ? sops && osConfig.sops ? secrets;
hmSopsAvailable = config ? sops && config.sops ? secrets;
preferOs = osSopsAvailable;
in
{
available = osSopsAvailable || hmSopsAvailable;
secrets = if preferOs then osConfig.sops.secrets else config.sops.secrets;
templates = if preferOs then osConfig.sops.templates else config.sops.templates;
};
}