From 14f8c83cf34c161c1c732e8d9328de476d876ed9 Mon Sep 17 00:00:00 2001 From: hektor Date: Sun, 11 Oct 2026 16:55:03 +0200 Subject: [PATCH] refactor: simplify repo paths --- deploy/colmena.nix | 5 ++++- flake.nix | 13 ++++++++----- home/modules/deploy/default.nix | 8 ++++---- home/modules/shell/bash.nix | 4 ++-- home/modules/ssh/default.nix | 12 ++++++------ modules/common/home-manager.nix | 4 ++-- modules/ssh/authorized-keys.nix | 5 +++-- modules/ssh/known-hosts.nix | 8 ++++---- 8 files changed, 33 insertions(+), 26 deletions(-) diff --git a/deploy/colmena.nix b/deploy/colmena.nix index d8049dc..74bb3a5 100644 --- a/deploy/colmena.nix +++ b/deploy/colmena.nix @@ -42,8 +42,11 @@ inputs.colmena.lib.makeHive ( specialArgs = { inherit inputs; outputs = self; - dotsPath = ../dots; myUtils = utils; + paths = { + dots = ../dots; + hosts = ../hosts; + }; }; }; } diff --git a/flake.nix b/flake.nix index 064ef7c..1dd59d0 100644 --- a/flake.nix +++ b/flake.nix @@ -75,7 +75,10 @@ myUtils = import ./utils { inherit lib; }; hostDirNames = myUtils.dirNames ./hosts; system = "x86_64-linux"; - dotsPath = ./dots; + paths = { + dots = ./dots; + hosts = ./hosts; + }; gitHooks = import ./git-hooks.nix { inherit nixpkgs git-hooks system; src = ./.; @@ -97,7 +100,7 @@ inherit inputs outputs - dotsPath + paths myUtils ; }; @@ -117,7 +120,7 @@ inherit inputs outputs - dotsPath + paths myUtils ; }; @@ -135,7 +138,7 @@ inherit inputs outputs - dotsPath + paths myUtils ; }; @@ -154,7 +157,7 @@ inherit inputs outputs - dotsPath + paths myUtils ; }; diff --git a/home/modules/deploy/default.nix b/home/modules/deploy/default.nix index 33cae31..4a8eedf 100644 --- a/home/modules/deploy/default.nix +++ b/home/modules/deploy/default.nix @@ -4,22 +4,22 @@ pkgs, inputs, myUtils, + paths, ... }: let cfg = config.deploy; - hostDir = ../../../hosts; - hostNames = myUtils.dirNames hostDir; + hostNames = myUtils.dirNames paths.hosts; hostsWithKeys = lib.filter ( - hostname: builtins.pathExists (hostDir + "/${hostname}/ssh_host.pub") + hostname: builtins.pathExists (paths.hosts + "/${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 (hostDir + "/${hostname}")).tags; + hostTags = hostname: (myUtils.hostMeta (paths.hosts + "/${hostname}")).tags; nodeTagsDecl = '' declare -A _colmena_node_tags=( ${lib.concatMapStringsSep "\n" ( diff --git a/home/modules/shell/bash.nix b/home/modules/shell/bash.nix index 4b70641..8139675 100644 --- a/home/modules/shell/bash.nix +++ b/home/modules/shell/bash.nix @@ -1,7 +1,7 @@ { config, lib, - dotsPath, + paths, ... }: @@ -66,6 +66,6 @@ in ''; }; - home.sessionPath = lib.optional cfg.addBinToPath "${dotsPath}/.bin"; + home.sessionPath = lib.optional cfg.addBinToPath "${paths.dots}/.bin"; }; } diff --git a/home/modules/ssh/default.nix b/home/modules/ssh/default.nix index d1588ef..13d5920 100644 --- a/home/modules/ssh/default.nix +++ b/home/modules/ssh/default.nix @@ -3,16 +3,16 @@ lib, pkgs, myUtils, + paths, ... }: let cfg = config.ssh; - - hostDir = ../../../hosts; - hostsWithKeys = lib.filter (hostname: builtins.pathExists (hostDir + "/${hostname}/ssh_host.pub")) ( - myUtils.dirNames hostDir - ); + hostNames = myUtils.dirNames paths.hosts; + hostsWithKeys = lib.filter ( + hostname: builtins.pathExists (paths.hosts + "/${hostname}/ssh_host.pub") + ) hostNames; in { options.ssh.enable = lib.mkEnableOption "ssh"; @@ -37,7 +37,7 @@ in lib.genAttrs hostsWithKeys ( hostname: let - meta = myUtils.hostMeta (hostDir + "/${hostname}"); + meta = myUtils.hostMeta (paths.hosts + "/${hostname}"); in { User = meta.host.username; diff --git a/modules/common/home-manager.nix b/modules/common/home-manager.nix index 0b09f51..ec21459 100644 --- a/modules/common/home-manager.nix +++ b/modules/common/home-manager.nix @@ -1,7 +1,7 @@ { inputs, outputs, - dotsPath, + paths, myUtils, config, lib, @@ -21,7 +21,7 @@ in inherit inputs outputs - dotsPath + paths myUtils ; }; diff --git a/modules/ssh/authorized-keys.nix b/modules/ssh/authorized-keys.nix index 3db84bb..f27caa8 100644 --- a/modules/ssh/authorized-keys.nix +++ b/modules/ssh/authorized-keys.nix @@ -1,12 +1,13 @@ { lib, config, + paths, ... }: let inherit (config.host) username; - adminHosts = (import ../../utils { inherit lib; }).adminHosts ../../hosts; + adminHosts = (import ../../utils { inherit lib; }).adminHosts paths.hosts; in { options.ssh = { @@ -22,7 +23,7 @@ in map ( hostname: let - keyFile = ../../hosts/${hostname}/ssh_user.pub; + keyFile = paths.hosts + "/${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) diff --git a/modules/ssh/known-hosts.nix b/modules/ssh/known-hosts.nix index e0c3be8..8cc646f 100644 --- a/modules/ssh/known-hosts.nix +++ b/modules/ssh/known-hosts.nix @@ -2,19 +2,19 @@ lib, config, outputs, + paths, ... }: let hosts = lib.attrNames outputs.nixosConfigurations; - hostsWithKeys = lib.filter ( - hostname: builtins.pathExists ../../hosts/${hostname}/ssh_host.pub - ) hosts; + keyPath = hostname: paths.hosts + "/${hostname}/ssh_host.pub"; + hostsWithKeys = lib.filter (hostname: builtins.pathExists (keyPath hostname)) hosts; in { config = lib.mkIf config.ssh.enable { programs.ssh.knownHosts = lib.genAttrs hostsWithKeys (hostname: { - publicKeyFile = ../../hosts/${hostname}/ssh_host.pub; + publicKeyFile = keyPath hostname; extraHostNames = lib.optional (hostname == config.networking.hostName) "localhost"; }); };