Colmena connects with BatchMode=yes and no TTY (src/nix/host/ssh.rs),
so a sudo password prompt can never be answered - non-root deploys
REQUIRE NOPASSWD. New extraServices.colmenaDeploy (enabled on all
five hosts) grants m3tam3re passwordless sudo for exactly the two
invocations colmena performs (verified against colmena 0.5/0.6
profile.rs + host/{ssh,local}.rs, default NixFlags are empty):
- /run/current-system/sw/bin/nix-env --profile /nix/var/nix/profiles/system --set /nix/store/*
(system profile switch, goals switch/boot)
- /nix/store/*/bin/switch-to-configuration <boot|switch|test|dry-activate>
(activation, exact single argument)
Everything else keeps requiring the sudo password; extraRules sort
after the wheel rules, so last-match-wins keeps the exception scoped.
Also enables passwordless 'colmena apply-local' on the desktops, which
uses the same activation path.
Residual risk (documented in the module): anyone holding the deploy
user's SSH key can activate arbitrary store closures - that is the
deploy capability itself, inherent to NixOS remote activation.
One-time bootstrap per server (rules arrive WITH a deploy, and the
first deploy cannot answer a password prompt):
nixos-rebuild switch --flake .#m3-atlas --target-host m3tam3re@m3-atlas --use-remote-sudo
269 lines
8.2 KiB
Nix
269 lines
8.2 KiB
Nix
{
|
|
description = ''
|
|
For questions just DM me on X: https://twitter.com/@m3tam3re
|
|
There is also some NIXOS content on my YT channel: https://www.youtube.com/@m3tam3re
|
|
|
|
One of the best ways to learn NIXOS is to read other peoples configurations. I have personally learned a lot from Gabriel Fontes configs:
|
|
https://github.com/Misterio77/nix-starter-configs
|
|
https://github.com/Misterio77/nix-config
|
|
|
|
Please also check out the starter configs mentioned above.
|
|
'';
|
|
|
|
inputs = {
|
|
home-manager = {
|
|
url = "github:nix-community/home-manager";
|
|
inputs.nixpkgs.follows = "nixpkgs";
|
|
};
|
|
nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
|
|
nixpkgs-stable.url = "github:nixos/nixpkgs/nixos-26.05";
|
|
# nixpkgs-45570c2.url = "github:nixos/nixpkgs/45570c299dc2b63c8c574c4cd77f0b92f7e2766e";
|
|
# nixpkgs-locked.url = "github:nixos/nixpkgs/2744d988fa116fc6d46cdfa3d1c936d0abd7d121";
|
|
# nixpkgs-9e58ed7.url = "github:nixos/nixpkgs/9e58ed7ba759d81c98f033b7f5eba21ca68f53b0";
|
|
nixpkgs-master.url = "github:nixos/nixpkgs/master";
|
|
|
|
m3ta-nixpkgs = {
|
|
url = "git+ssh://gitea@code.m3ta.dev/m3tam3re/nixpkgs";
|
|
inputs.nixpkgs.follows = "nixpkgs";
|
|
# url = "path:/home/m3tam3re/p/NIX/nixpkgs";
|
|
};
|
|
|
|
# Nix library for rendering agent skill source selections into store
|
|
# dirs (mkHermesSkillsDir). Consumed directly by hosts/m3-hermes.
|
|
# agent-lib = {
|
|
# url = "git+ssh://gitea@code.m3ta.dev/m3tam3re/agent-lib-legacy";
|
|
# inputs.nixpkgs.follows = "nixpkgs";
|
|
# };
|
|
|
|
llm-agents.url = "github:numtide/llm-agents.nix";
|
|
|
|
nur = {
|
|
url = "github:nix-community/NUR";
|
|
inputs.nixpkgs.follows = "nixpkgs";
|
|
};
|
|
agenix.url = "github:ryantm/agenix";
|
|
|
|
# Deployment tool (colmena >= 0.5.0 reads the colmenaHive output).
|
|
# Also provides colmena.lib.makeHive used by our flake outputs.
|
|
colmena = {
|
|
url = "github:nix-community/colmena";
|
|
inputs.nixpkgs.follows = "nixpkgs";
|
|
};
|
|
|
|
disko = {
|
|
url = "github:nix-community/disko";
|
|
inputs.nixpkgs.follows = "nixpkgs";
|
|
};
|
|
|
|
nixos-generators = {url = "github:nix-community/nixos-generators";};
|
|
|
|
rose-pine-hyprcursor.url = "github:ndom91/rose-pine-hyprcursor";
|
|
nix-colors.url = "github:misterio77/nix-colors";
|
|
|
|
m3ta-home = {
|
|
# url = "git+ssh://gitea@code.m3ta.dev/m3tam3re/m3ta-home";
|
|
url = "path:/home/m3tam3re/p/NIX/m3ta-home";
|
|
inputs.nixpkgs.follows = "nixpkgs";
|
|
};
|
|
|
|
hermes-agent.url = "github:NousResearch/hermes-agent/v2026.9.24";
|
|
};
|
|
|
|
outputs = {
|
|
self,
|
|
agenix,
|
|
colmena,
|
|
home-manager,
|
|
nixpkgs,
|
|
m3ta-nixpkgs,
|
|
nur,
|
|
...
|
|
} @ inputs: let
|
|
inherit (self) outputs;
|
|
systems = [
|
|
"aarch64-linux"
|
|
"i686-linux"
|
|
"x86_64-linux"
|
|
"aarch64-darwin"
|
|
"x86_64-darwin"
|
|
];
|
|
forAllSystems = nixpkgs.lib.genAttrs systems;
|
|
allOverlays = import ./overlays {inherit inputs outputs;};
|
|
|
|
# Single source of truth for all NixOS hosts. Consumed by both
|
|
# nixosConfigurations (nixos-rebuild/nh) and the Colmena hive below,
|
|
# so local rebuilds and remote deploys can never drift apart.
|
|
nixosHosts = {
|
|
m3-ares = {
|
|
hostname = "m3-ares";
|
|
modules = [
|
|
./hosts/m3-ares
|
|
agenix.nixosModules.default
|
|
m3ta-nixpkgs.nixosModules.default
|
|
inputs.hermes-agent.nixosModules.default
|
|
];
|
|
};
|
|
m3-atlas = {
|
|
modules = [
|
|
./hosts/m3-atlas
|
|
inputs.disko.nixosModules.disko
|
|
agenix.nixosModules.default
|
|
m3ta-nixpkgs.nixosModules.default
|
|
];
|
|
};
|
|
m3-kratos = {
|
|
hostname = "m3-kratos";
|
|
modules = [
|
|
./hosts/m3-kratos
|
|
agenix.nixosModules.default
|
|
nur.modules.nixos.default
|
|
m3ta-nixpkgs.nixosModules.default
|
|
inputs.hermes-agent.nixosModules.default
|
|
];
|
|
};
|
|
m3-helios = {
|
|
modules = [
|
|
./hosts/m3-helios
|
|
inputs.disko.nixosModules.disko
|
|
agenix.nixosModules.default
|
|
m3ta-nixpkgs.nixosModules.default
|
|
];
|
|
};
|
|
m3-hermes = {
|
|
modules = [
|
|
./hosts/m3-hermes
|
|
inputs.disko.nixosModules.disko
|
|
agenix.nixosModules.default
|
|
m3ta-nixpkgs.nixosModules.default
|
|
inputs.hermes-agent.nixosModules.default
|
|
];
|
|
};
|
|
};
|
|
|
|
mkSpecialArgs = hostname:
|
|
{
|
|
inherit inputs outputs;
|
|
system = "x86_64-linux";
|
|
}
|
|
// nixpkgs.lib.optionalAttrs (hostname != null) {inherit hostname;};
|
|
|
|
# Colmena deployment hive (https://colmena.cli.rs):
|
|
# nix develop -c colmena apply --on @server # all servers via SSH
|
|
# nix develop -c colmena apply --on m3-atlas # single host
|
|
# nix develop -c colmena apply-local # this machine (desktops)
|
|
# meta.nixpkgs overlays/config are merged with mkBefore, so the overlays
|
|
# set in hosts/common/default.nix keep working unchanged.
|
|
rawHive = {
|
|
meta = {
|
|
# NOTE: Colmena imports nixpkgs without flake sourceInfo, so
|
|
# system.nixos.version renders as "26.11pre-git" instead of
|
|
# "26.11.<date>.<rev>" under `colmena` builds. Purely cosmetic
|
|
# (os-release) — package closure, overlays and options are identical
|
|
# to nixosConfigurations. Documented colmena behavior.
|
|
nixpkgs = import nixpkgs {
|
|
system = "x86_64-linux";
|
|
overlays = [];
|
|
};
|
|
specialArgs = mkSpecialArgs null;
|
|
nodeSpecialArgs =
|
|
nixpkgs.lib.mapAttrs
|
|
(_: host: mkSpecialArgs host.hostname)
|
|
(nixpkgs.lib.filterAttrs (_: host: host ? hostname) nixosHosts);
|
|
# Guard against bare `colmena apply` hitting every node (including
|
|
# desktops in active use). Use --on filters or apply-local instead.
|
|
allowApplyAll = false;
|
|
};
|
|
|
|
defaults = {
|
|
deployment.targetUser = "m3tam3re";
|
|
};
|
|
|
|
m3-ares = {
|
|
imports = nixosHosts.m3-ares.modules;
|
|
deployment = {
|
|
targetHost = "m3-ares";
|
|
tags = ["desktop"];
|
|
allowLocalDeployment = true;
|
|
};
|
|
};
|
|
m3-atlas = {
|
|
imports = nixosHosts.m3-atlas.modules;
|
|
deployment = {
|
|
targetHost = "m3-atlas";
|
|
tags = ["server"];
|
|
};
|
|
};
|
|
m3-kratos = {
|
|
imports = nixosHosts.m3-kratos.modules;
|
|
deployment = {
|
|
targetHost = "m3-kratos";
|
|
tags = ["desktop"];
|
|
allowLocalDeployment = true;
|
|
};
|
|
};
|
|
m3-helios = {
|
|
imports = nixosHosts.m3-helios.modules;
|
|
deployment = {
|
|
targetHost = "m3-helios";
|
|
tags = ["server"];
|
|
};
|
|
};
|
|
m3-hermes = {
|
|
imports = nixosHosts.m3-hermes.modules;
|
|
deployment = {
|
|
targetHost = "m3-hermes";
|
|
tags = ["server"];
|
|
};
|
|
};
|
|
};
|
|
in {
|
|
packages =
|
|
forAllSystems (system: import ./pkgs nixpkgs.legacyPackages.${system});
|
|
overlays = allOverlays;
|
|
homeManagerModules = import ./modules/home-manager;
|
|
|
|
nixosConfigurations =
|
|
nixpkgs.lib.mapAttrs
|
|
(_: host:
|
|
nixpkgs.lib.nixosSystem {
|
|
specialArgs = mkSpecialArgs (host.hostname or null);
|
|
modules = host.modules;
|
|
})
|
|
nixosHosts;
|
|
|
|
# Colmena >= 0.5.0 (direct flake evaluation) and legacy CLIs alike.
|
|
colmenaHive = colmena.lib.makeHive rawHive;
|
|
colmena = rawHive;
|
|
homeConfigurations = {
|
|
"m3tam3re@m3-daedalus" = home-manager.lib.homeManagerConfiguration {
|
|
pkgs = nixpkgs.legacyPackages."x86_64-linux";
|
|
extraSpecialArgs = {
|
|
inherit inputs outputs;
|
|
system = "x86_64-linux";
|
|
hostname = "m3-daedalus";
|
|
};
|
|
modules = [./home/m3tam3re/m3-daedalus.nix];
|
|
};
|
|
};
|
|
devShells = forAllSystems (system: let
|
|
pkgs = import nixpkgs {
|
|
inherit system;
|
|
config.allowUnfree = true; # Allow unfree packages in devShell
|
|
};
|
|
in {
|
|
default = pkgs.mkShell {
|
|
buildInputs = with pkgs;
|
|
[
|
|
alejandra
|
|
nixd
|
|
openssh
|
|
agenix.packages.${system}.default
|
|
statix
|
|
deadnix
|
|
]
|
|
++ [colmena.packages.${system}.default];
|
|
};
|
|
});
|
|
};
|
|
}
|