refactor, ssh keys for root

This commit is contained in:
Henri Dohmen 2025-05-26 11:49:02 +02:00
parent 8fbd9d06b4
commit c45f9f7f46
7 changed files with 78 additions and 54 deletions

View file

@ -21,14 +21,13 @@
lib = nixpkgs.lib; lib = nixpkgs.lib;
lib' = import ./lib.nix { inherit lib; }; lib' = import ./lib.nix { inherit lib; };
mod = lib'.walk-dir ./mod; mod = lib'.walk-dir ./mod;
var = lib'.walk-dir ./var;
specialArgs = { specialArgs = {
inherit inherit inputs lib' mod;
inputs var = (lib'.walk-dir ./var).map_import;
lib' };
mod overlays = _: {
var nixpkgs.overlays = [ colmena.overlay ];
;
}; };
in in
{ {
@ -38,8 +37,9 @@
inherit specialArgs; inherit specialArgs;
modules = [ modules = [
./host/solo ./host/solo
mod.common._nixos_mod mod.common.to_mod
mod.pc-common._nixos_mod mod.pc-common.to_mod
overlays
]; ];
}; };
@ -48,8 +48,9 @@
inherit specialArgs; inherit specialArgs;
modules = [ modules = [
./host/c2 ./host/c2
mod.common._nixos_mod mod.common.to_mod
mod.pc-common._nixos_mod mod.pc-common.to_mod
overlays
]; ];
}; };
}; };
@ -68,7 +69,8 @@
}; };
imports = [ imports = [
./host/roam ./host/roam
mod.common._nixos_mod mod.common.to_mod
overlays
]; ];
}; };
}; };

View file

@ -1,8 +1,11 @@
{ lib', ... }: { lib', ... }:
let
submodules = lib'.walk-dir ./.;
in
{ {
networking.hostName = "roam"; networking.hostName = "roam";
imports = lib'.import-recursive ./.; imports = [ submodules.to_mod_without_default ];
# ====== DON'T CHANGE ====== # ====== DON'T CHANGE ======
system.stateVersion = "24.11"; system.stateVersion = "24.11";

View file

@ -1,8 +1,11 @@
{ lib', ... }: { lib', ... }:
let
submodules = lib'.walk-dir ./.;
in
{ {
networking.hostName = "solo"; networking.hostName = "solo";
imports = lib'.import-recursive ./.; imports = [ submodules.to_mod_without_default ];
powerManagement = { powerManagement = {
enable = true; enable = true;

64
lib.nix
View file

@ -1,33 +1,47 @@
{ lib, ... }: { lib, ... }:
with builtins;
rec { rec {
walk-dir = walk-dir =
path:
let let
dir = builtins.readDir path; walk-dir-inner =
path:
let
dir = readDir path;
subpaths = lib.mapAttrs' (filename: value: { in
name = lib.removeSuffix ".nix" filename; lib.mapAttrs' (filename: value: {
value = name = lib.removeSuffix ".nix" filename;
if value == "regular" then value =
path + "/${filename}" if value == "regular" then
else if value == "directory" then path + "/${filename}"
walk-dir (path + "/${filename}") else if value == "directory" then
else walk-dir-inner (path + "/${filename}")
builtins.throw "Items of type ${value} are unsupported."; else
}) dir; throw "Items of type ${value} are unsupported.";
in }) dir;
subpaths
// rec { helper-attrs =
_files = lib.collect builtins.isPath (subpaths // { default = { }; }); subpaths:
_nix_files = builtins.filter (lib.hasSuffix ".nix") _files; let
_nixos_mod = _files = lib.collect (x: isPath x || isString x) subpaths;
{ ... }: _nix_files = filter (lib.hasSuffix ".nix") _files;
{ in
imports = _nix_files; rec {
to_mod = _: {
imports = _nix_files;
};
to_mod_without_default = without_default.to_mod;
collect_nix_files = _nix_files;
map_import = lib.mapAttrsRecursive (_: import) subpaths;
without_default =
let
subpaths' = removeAttrs subpaths [ "default" ];
in
with-helper-attrs subpaths';
}; };
};
# Takes a path `p` and returns a list of all files in that with-helper-attrs =
# directory recursively, ignoring `p/default.nix`. x: if isAttrs x then lib.mapAttrs (_: with-helper-attrs) x // helper-attrs x else x;
import-recursive = path: (walk-dir path)._files; in
p: with-helper-attrs (walk-dir-inner p);
} }

View file

@ -18,7 +18,7 @@
unzip unzip
wget wget
wl-clipboard wl-clipboard
inputs.colmena.packages."x86_64-linux".colmena # todo use overlay colmena
]; ];
programs = { programs = {

View file

@ -2,6 +2,7 @@
pkgs, pkgs,
lib, lib,
options, options,
var,
... ...
}: }:
{ {
@ -15,24 +16,12 @@
extraGroups = [ "wheel" ]; extraGroups = [ "wheel" ];
shell = pkgs.fish; shell = pkgs.fish;
packages = [ ]; packages = [ ];
openssh.authorizedKeys.keys = [ openssh.authorizedKeys.keys = var.ssh-keys.unprivileged;
"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIEG+dd4m98aKEWfFa/7VZUlJNX0axvIlHVihT8w7RLyY"
"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIIsoj2+esEebRwDV2PuNRt9Vz28oolOy+Hc2THwrWTAB"
];
hashedPassword = "$y$jDT$dhvO.xqs8mopz.sFFul.q/$ud5642o7CnVetU6QEu0ctiVMFh7ngZznDf0wp4cXos8"; hashedPassword = "$y$jDT$dhvO.xqs8mopz.sFFul.q/$ud5642o7CnVetU6QEu0ctiVMFh7ngZznDf0wp4cXos8";
}; };
users.root = { users.root = {
hashedPassword = "!"; hashedPassword = "!";
openssh.authorizedKeys.keys = var.ssh-keys.priviliged;
# I don't like the unprivileged users to have unrestricted access to root
# but this is required for colmena. Better options are
# - only authorize root's pubkey
# - create password protected key
# TODO: do one of the above
openssh.authorizedKeys.keys = [
"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIEG+dd4m98aKEWfFa/7VZUlJNX0axvIlHVihT8w7RLyY"
"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIIsoj2+esEebRwDV2PuNRt9Vz28oolOy+Hc2THwrWTAB"
];
}; };
}; };
} }

13
var/ssh-keys.nix Normal file
View file

@ -0,0 +1,13 @@
rec {
# this is only used for forcing password entry on colmena apply
priviliged-by-host = {
"solo" = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIFsl8pLaGeCL3kacGWf8pzoLQr501ga/2OzvI2wWbTZJ";
};
priviliged = builtins.attrValues priviliged-by-host;
unprivileged-by-host = {
"solo" = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIEG+dd4m98aKEWfFa/7VZUlJNX0axvIlHVihT8w7RLyY";
"c2" = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIIsoj2+esEebRwDV2PuNRt9Vz28oolOy+Hc2THwrWTAB";
};
unprivileged = builtins.attrValues unprivileged-by-host;
}