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 let
inherit (inputs.nixpkgs) lib; 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 # 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) # 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> # see <https://github.com/nix-community/colmena/issues/38>
# <https://github.com/nix-community/colmena/issues/344> # <https://github.com/nix-community/colmena/issues/344>
hostnames = lib.filter ( hostnames = lib.filter (
hostname: !((utils.hostMeta ../hosts/${hostname}).deploy.autoRollback or false) hostname: !((lib'.hostMeta hostname).deploy.autoRollback or false)
) (utils.dirNames ../hosts); ) lib'.nixosHosts;
mkNode = mkNode =
hostname: hostname:
let let
meta = utils.hostMeta ../hosts/${hostname}; meta = lib'.hostMeta hostname;
isArm = meta.system == "aarch64-linux"; isArm = meta.system == "aarch64-linux";
in in
{ {
@@ -40,13 +40,9 @@ inputs.colmena.lib.makeHive (
meta = { meta = {
nixpkgs = import inputs.nixpkgs { localSystem = "x86_64-linux"; }; nixpkgs = import inputs.nixpkgs { localSystem = "x86_64-linux"; };
specialArgs = { specialArgs = {
inherit inputs; inherit inputs lib';
outputs = self; outputs = self;
myUtils = utils; dotsPath = ../dots;
paths = {
dots = ../dots;
hosts = ../hosts;
};
}; };
}; };
} }
+4 -4
View File
@@ -5,18 +5,18 @@
let let
inherit (inputs.nixpkgs) lib; 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) # only include hosts that need auto rollback (until `colmena` supports it)
# `colmena` is used for other hosts (see ./colmena.nix) # `colmena` is used for other hosts (see ./colmena.nix)
hostnames = lib.filter ( hostnames = lib.filter (
hostname: (utils.hostMeta ../hosts/${hostname}).deploy.autoRollback or false hostname: (lib'.hostMeta hostname).deploy.autoRollback or false
) (utils.dirNames ../hosts); ) lib'.nixosHosts;
mkNode = mkNode =
hostname: hostname:
let let
meta = utils.hostMeta ../hosts/${hostname}; meta = lib'.hostMeta hostname;
in in
{ {
inherit hostname; inherit hostname;
+7 -21
View File
@@ -74,15 +74,9 @@
... ...
}@inputs: }@inputs:
let let
inherit (self) outputs;
inherit (inputs.nixpkgs) lib; inherit (inputs.nixpkgs) lib;
myUtils = import ./utils { inherit lib; }; lib' = import ./lib { inherit lib; };
hostDirNames = myUtils.dirNames ./hosts;
system = "x86_64-linux"; system = "x86_64-linux";
paths = {
dots = ./dots;
hosts = ./hosts;
};
gitHooks = import ./git-hooks.nix { gitHooks = import ./git-hooks.nix {
inherit nixpkgs git-hooks system; inherit nixpkgs git-hooks system;
src = ./.; src = ./.;
@@ -90,22 +84,20 @@
in in
{ {
nixosConfigurations = nixosConfigurations =
(lib.genAttrs hostDirNames ( (lib.genAttrs lib'.nixosHosts (
host: host:
nixpkgs.lib.nixosSystem { nixpkgs.lib.nixosSystem {
modules = [ modules = [
./hosts/${host} ./hosts/${host}
{ {
nixpkgs.hostPlatform = (myUtils.hostMeta ./hosts/${host}).system; nixpkgs.hostPlatform = (lib'.hostMeta host).system;
host.name = host; host.name = host;
} }
]; ];
specialArgs = { specialArgs = {
inherit inherit
inputs inputs
outputs lib'
paths
myUtils
; ;
}; };
} }
@@ -123,9 +115,7 @@
specialArgs = { specialArgs = {
inherit inherit
inputs inputs
outputs lib'
paths
myUtils
; ;
}; };
}; };
@@ -141,9 +131,7 @@
specialArgs = { specialArgs = {
inherit inherit
inputs inputs
outputs lib'
paths
myUtils
; ;
}; };
}; };
@@ -160,9 +148,7 @@
osConfig = null; osConfig = null;
inherit inherit
inputs inputs
outputs lib'
paths
myUtils
; ;
}; };
}; };
+3 -3
View File
@@ -2,21 +2,21 @@
config, config,
lib, lib,
pkgs, pkgs,
myUtils, lib',
osConfig ? null, osConfig ? null,
inputs ? null, inputs ? null,
... ...
}: }:
let let
sops = myUtils.sopsAvailability config osConfig; sops = lib'.sopsAvailability config osConfig;
standalone = osConfig == null; standalone = osConfig == null;
in in
{ {
config = lib.mkIf config.ai-tools.opencode.enable ( config = lib.mkIf config.ai-tools.opencode.enable (
lib.optionalAttrs standalone { lib.optionalAttrs standalone {
sops = { sops = {
secrets = myUtils.mkSopsSecrets "${toString inputs.nix-secrets}/secrets" { secrets = lib'.mkSopsSecrets "${toString inputs.nix-secrets}/secrets" null {
opencode = [ "api-key" ]; opencode = [ "api-key" ];
}; };
templates."opencode/auth.json" = { templates."opencode/auth.json" = {
+3 -3
View File
@@ -2,7 +2,7 @@
config, config,
lib, lib,
pkgs, pkgs,
myUtils, lib',
osConfig ? null, osConfig ? null,
inputs ? null, inputs ? null,
... ...
@@ -10,7 +10,7 @@
let let
cfg = config.anki; cfg = config.anki;
sops = myUtils.sopsAvailability config osConfig; sops = lib'.sopsAvailability config osConfig;
standalone = osConfig == null; standalone = osConfig == null;
in in
{ {
@@ -18,7 +18,7 @@ in
config = lib.mkIf cfg.enable ( config = lib.mkIf cfg.enable (
lib.optionalAttrs standalone { lib.optionalAttrs standalone {
sops.secrets = myUtils.mkSopsSecrets "${toString inputs.nix-secrets}/secrets" { sops.secrets = lib'.mkSopsSecrets "${toString inputs.nix-secrets}/secrets" null {
anki = [ anki = [
"sync-user" "sync-user"
"sync-key" "sync-key"
+2 -2
View File
@@ -2,14 +2,14 @@
config, config,
lib, lib,
pkgs, pkgs,
myUtils, lib',
... ...
}: }:
{ {
imports = imports =
let let
dirs = myUtils.dirNames ./.; dirs = lib'.dirNames ./.;
hasDef = name: builtins.pathExists ./${name}/default.nix; hasDef = name: builtins.pathExists ./${name}/default.nix;
in in
map (name: ./${name}) (builtins.filter hasDef dirs); map (name: ./${name}) (builtins.filter hasDef dirs);
+4 -5
View File
@@ -3,23 +3,22 @@
lib, lib,
pkgs, pkgs,
inputs, inputs,
myUtils, lib',
paths,
... ...
}: }:
let let
cfg = config.deploy; cfg = config.deploy;
hostNames = myUtils.dirNames paths.hosts; inherit (lib') hostNames;
hostsWithKeys = lib.filter ( hostsWithKeys = lib.filter (
hostname: builtins.pathExists (paths.hosts + "/${hostname}/ssh_host.pub") hostname: builtins.pathExists (lib'.hostsPath + "/${hostname}/ssh_host.pub")
) hostNames; ) hostNames;
colmena = inputs.colmena.packages.${pkgs.stdenv.hostPlatform.system}.colmena; colmena = inputs.colmena.packages.${pkgs.stdenv.hostPlatform.system}.colmena;
deployRs = inputs.deploy-rs.packages.${pkgs.stdenv.hostPlatform.system}.default; 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 = '' nodeTagsDecl = ''
declare -A _colmena_node_tags=( declare -A _colmena_node_tags=(
${lib.concatMapStringsSep "\n" ( ${lib.concatMapStringsSep "\n" (
+3 -3
View File
@@ -2,14 +2,14 @@
config, config,
inputs, inputs,
lib, lib,
myUtils, lib',
osConfig ? null, osConfig ? null,
... ...
}: }:
let let
cfg = config.git; cfg = config.git;
sops = myUtils.sopsAvailability config osConfig; sops = lib'.sopsAvailability config osConfig;
standalone = osConfig == null; standalone = osConfig == null;
personalEmail = sops.templates.".gitconfig.email".path; personalEmail = sops.templates.".gitconfig.email".path;
@@ -50,7 +50,7 @@ in
config = lib.mkIf cfg.enable ( config = lib.mkIf cfg.enable (
lib.optionalAttrs standalone { lib.optionalAttrs standalone {
sops = { sops = {
secrets = myUtils.mkSopsSecrets "${toString inputs.nix-secrets}/secrets" { secrets = lib'.mkSopsSecrets "${toString inputs.nix-secrets}/secrets" null {
email = [ email = [
"personal" "personal"
"work" "work"
+2 -2
View File
@@ -1,7 +1,7 @@
{ {
config, config,
lib, 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, config,
lib, lib,
pkgs, pkgs,
myUtils, lib',
paths,
... ...
}: }:
let let
cfg = config.ssh; cfg = config.ssh;
hostNames = myUtils.dirNames paths.hosts;
hostsWithKeys = lib.filter ( hostsWithKeys = lib.filter (
hostname: builtins.pathExists (paths.hosts + "/${hostname}/ssh_host.pub") hostname: builtins.pathExists (lib'.hostsPath + "/${hostname}/ssh_host.pub")
) hostNames; ) lib'.hostNames;
in in
{ {
options.ssh.enable = lib.mkEnableOption "ssh"; options.ssh.enable = lib.mkEnableOption "ssh";
@@ -37,7 +36,7 @@ in
lib.genAttrs hostsWithKeys ( lib.genAttrs hostsWithKeys (
hostname: hostname:
let let
meta = myUtils.hostMeta (paths.hosts + "/${hostname}"); meta = lib'.hostMeta hostname;
in in
{ {
User = meta.host.username; User = meta.host.username;
+3 -3
View File
@@ -2,14 +2,14 @@
config, config,
lib, lib,
pkgs, pkgs,
myUtils, lib',
osConfig ? null, osConfig ? null,
inputs ? null, inputs ? null,
... ...
}: }:
let let
sops = myUtils.sopsAvailability config osConfig; sops = lib'.sopsAvailability config osConfig;
standalone = osConfig == null; standalone = osConfig == null;
syncHook = pkgs.writers.writePython3 "on-exit.sync.py" { flakeIgnore = [ "E501" ]; } '' syncHook = pkgs.writers.writePython3 "on-exit.sync.py" { flakeIgnore = [ "E501" ]; } ''
@@ -64,7 +64,7 @@ in
config = lib.mkIf config.taskwarrior.enable ( config = lib.mkIf config.taskwarrior.enable (
lib.optionalAttrs standalone { lib.optionalAttrs standalone {
sops = { sops = {
secrets = myUtils.mkSopsSecrets "${toString inputs.nix-secrets}/secrets" { secrets = lib'.mkSopsSecrets "${toString inputs.nix-secrets}/secrets" null {
taskwarrior = [ taskwarrior = [
"sync-server-url" "sync-server-url"
"sync-server-client-id" "sync-server-client-id"
+3 -1
View File
@@ -4,5 +4,7 @@ let
fs = import ./fs.nix { inherit lib; }; fs = import ./fs.nix { inherit lib; };
hosts = import ./hosts.nix { inherit lib; }; hosts = import ./hosts.nix { inherit lib; };
secrets = import ./secrets.nix { inherit lib; }; secrets = import ./secrets.nix { inherit lib; };
dotsPath = ../dots;
in 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, inputs,
outputs, lib',
paths,
myUtils,
config, config,
lib, lib,
... ...
@@ -20,9 +18,7 @@ in
extraSpecialArgs = { extraSpecialArgs = {
inherit inherit
inputs inputs
outputs lib'
paths
myUtils
; ;
}; };
sharedModules = [ sharedModules = [
+2 -2
View File
@@ -3,7 +3,7 @@
inputs, inputs,
pkgs, pkgs,
config, config,
myUtils, lib',
... ...
}: }:
@@ -61,7 +61,7 @@ in
config = lib.mkIf cfg.enable { config = lib.mkIf cfg.enable {
sops = { 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 [ nix.settings.secret-key-files = lib.mkIf cfg.nixSigningKey.enable [
+3 -3
View File
@@ -1,13 +1,13 @@
{ {
lib, lib,
config, config,
paths, lib',
... ...
}: }:
let let
inherit (config.host) username; inherit (config.host) username;
adminHosts = (import ../../utils { inherit lib; }).adminHosts paths.hosts; inherit (lib') adminHosts;
in in
{ {
options.ssh = { options.ssh = {
@@ -23,7 +23,7 @@ in
map ( map (
hostname: hostname:
let let
keyFile = paths.hosts + "/${hostname}/ssh_user.pub"; keyFile = lib'.hostsPath + "/${hostname}/ssh_user.pub";
in in
lib.optionals (builtins.pathExists keyFile) (lib.splitString "\n" (builtins.readFile keyFile)) lib.optionals (builtins.pathExists keyFile) (lib.splitString "\n" (builtins.readFile keyFile))
) ((builtins.filter (h: h != config.host.name) adminHosts) ++ config.ssh.authorizedHosts) ) ((builtins.filter (h: h != config.host.name) adminHosts) ++ config.ssh.authorizedHosts)
+3 -4
View File
@@ -1,14 +1,13 @@
{ {
lib, lib,
config, config,
outputs, lib',
paths,
... ...
}: }:
let let
hosts = lib.attrNames outputs.nixosConfigurations; hosts = lib'.nixosHosts;
keyPath = hostname: paths.hosts + "/${hostname}/ssh_host.pub"; keyPath = hostname: lib'.hostsPath + "/${hostname}/ssh_host.pub";
hostsWithKeys = lib.filter (hostname: builtins.pathExists (keyPath hostname)) hosts; hostsWithKeys = lib.filter (hostname: builtins.pathExists (keyPath hostname)) hosts;
in in
{ {
+4 -5
View File
@@ -1,16 +1,15 @@
{ {
lib, lib,
config, config,
outputs, inputs,
paths, lib',
myUtils,
pkgs, pkgs,
... ...
}: }:
let let
hosts = myUtils.dirNames paths.hosts; hosts = lib'.nixosHosts;
interfaces = host: outputs.nixosConfigurations.${host}.config.wol.interfaces; interfaces = host: inputs.self.nixosConfigurations.${host}.config.wol.interfaces;
in in
{ {
options.wol = { 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;
};
}