8 Commits

18 changed files with 133 additions and 232 deletions

21
flake.lock generated
View File

@@ -404,21 +404,6 @@
"type": "github"
}
},
"monorepo": {
"inputs": {
"nixpkgs": "nixpkgs_2"
},
"locked": {
"lastModified": 1788059616,
"narHash": "sha256-HBYT3h0vXRsvmgPOhUW3kgPTkgdl73PEwRTJQ5X48aM=",
"path": "/home/alexion/dev",
"type": "path"
},
"original": {
"path": "/home/alexion/dev",
"type": "path"
}
},
"nixos-hardware": {
"inputs": {
"nixpkgs": [
@@ -557,12 +542,8 @@
"firefox-addons": "firefox-addons",
"gitea-axi": "gitea-axi",
"home-manager": "home-manager_3",
"monorepo": "monorepo",
"nixos-hardware": "nixos-hardware",
"nixpkgs": [
"monorepo",
"nixpkgs"
],
"nixpkgs": "nixpkgs_2",
"nixpkgs-stable": "nixpkgs-stable",
"nixpkgs-unstable": "nixpkgs-unstable",
"nixvim": "nixvim",

View File

@@ -2,10 +2,8 @@
description = "Alexion's NixOS configuration — one flake for every host";
inputs = {
monorepo.url = "path:/home/alexion/dev";
# Base package set shared with the monorepo.
nixpkgs.follows = "monorepo/nixpkgs";
# Base channel.
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
# Fresher packages, reachable per-package as `unstable.<name>`.
nixpkgs-unstable.url = "github:nixos/nixpkgs/nixpkgs-unstable";
@@ -78,9 +76,13 @@
{ self, nixpkgs, ... }@inputs:
let
inherit (nixpkgs) lib;
flake = import ./flake { inherit lib inputs self; };
in
{
inherit (import ./flake { inherit lib inputs self; }) nixosConfigurations;
# Every host under hosts/ is discovered and built.
nixosConfigurations = flake.mkHosts {
root = self + "/hosts";
};
# A project shell for agent-local resources that should travel with this
# checkout rather than the operator's global profile.

View File

@@ -4,50 +4,55 @@
self,
}:
let
# TODO: refactor the registry code
registryAssembly = import ./registry.nix { inherit lib self; };
util = import ../lib { inherit lib; };
mkModules = import ./module.nix { inherit util; };
registry = import ./registry.nix {
inherit lib;
hosts = self.nixosConfigurations;
root = self + "/registry";
};
modules = import ./module.nix {
inherit util;
modules = mkModules {
root = self + "/modules";
};
guestModules = import ./guest.nix {
inherit
inputs
lib
registry
specialArgs
util
;
repositoryModules = modules;
guestModules = guests.mkGuests {
root = self + "/guests";
};
#----------------------------------------------------------
collectedRegistry = registryAssembly.collect { hosts = self.nixosConfigurations; };
specialArgs = {
inherit
inputs
self
util
;
registry = registry.collected;
registry = collectedRegistry;
};
in
{
nixosConfigurations = import ./host.nix {
guests = import ./guest.nix {
inherit
inputs
lib
specialArgs
registryAssembly
util
;
repositoryModules = modules;
};
hosts = import ./host.nix {
inherit
inputs
lib
specialArgs
guestModules
registryAssembly
;
registryModule = registry.module;
repositoryModules = modules;
root = self + "/hosts";
};
in
{
inherit (hosts) mkHosts;
}

View File

@@ -1,10 +1,9 @@
{
inputs,
lib,
root,
specialArgs,
repositoryModules,
registry,
registryAssembly,
util,
}:
let
@@ -66,7 +65,7 @@ let
enable = lib.mkEnableOption "a reverse-proxy route for this guest";
route = lib.mkOption {
type = registry.types.route;
type = registryAssembly.definitions.route.type;
description = "Route registry entry published for this guest.";
};
};
@@ -248,7 +247,7 @@ let
inputs.stylix.nixosModules.stylix
repositoryModules
registry.module
registryAssembly.module
cfg.interior
{
@@ -269,11 +268,15 @@ let
};
};
in
let
files = util.collectNixFiles root;
guestFiles = lib.filterAttrs (file: type: type == "regular" && lib.hasSuffix ".nix" file) (builtins.readDir root);
names = map (file: lib.removeSuffix ".nix" file) (lib.attrNames guestFiles);
in
{
imports = files ++ map mkGuest names;
mkGuests =
{ root }:
let
files = util.collectNixFiles root;
guestFiles = lib.filterAttrs (file: type: type == "regular" && lib.hasSuffix ".nix" file) (builtins.readDir root);
names = map (file: lib.removeSuffix ".nix" file) (lib.attrNames guestFiles);
in
{
imports = files ++ map mkGuest names;
};
}

View File

@@ -1,12 +1,12 @@
{
inputs,
lib,
root,
specialArgs,
repositoryModules,
guestModules,
registryModule,
# TODO refactor registry
registryAssembly,
}:
let
mkHost =
@@ -26,7 +26,7 @@ let
guestModules
# TODO: refactor
registryModule (root + "/${name}")
registryAssembly.module (root + "/${name}")
{
networking.hostName = name;
@@ -35,11 +35,15 @@ let
];
};
in
let
directories = lib.filterAttrs (_name: type: type == "directory") (builtins.readDir root);
names = lib.attrNames directories;
in
lib.genAttrs names (
name:
mkHost { inherit root name; }
)
{
mkHosts =
{ root }:
let
directories = lib.filterAttrs (_name: type: type == "directory") (builtins.readDir root);
names = lib.attrNames directories;
in
lib.genAttrs names (
name:
mkHost { inherit root name; }
);
}

View File

@@ -1,7 +1,5 @@
{
root,
util,
}:
{ util }:
{ root }:
{
imports = util.collectNixFiles root;
}

View File

@@ -1,16 +1,35 @@
{ hosts, lib, root }:
{ lib, self }:
let
checkType = lib.types.submodule {
inherit (lib)
all
concatLists
concatMapStringsSep
filter
filterAttrs
foldl'
hasAttr
hasSuffix
mapAttrs
mapAttrs'
mapAttrsToList
mkOption
nameValuePair
removeSuffix
types
unique
;
checkType = types.submodule {
options = {
assertion = lib.mkOption {
type = lib.types.functionTo lib.types.bool;
assertion = mkOption {
type = types.functionTo types.bool;
description = ''
Predicate run against this registry's flattened collected entries.
'';
};
message = lib.mkOption {
type = lib.types.str;
message = mkOption {
type = types.str;
description = ''
Error message shown when this registry validation check fails.
'';
@@ -19,7 +38,7 @@ let
};
predicates = {
uniqueValue = value: entries: builtins.length (lib.unique (map value entries)) == builtins.length entries;
uniqueValue = value: entries: builtins.length (unique (map value entries)) == builtins.length entries;
};
registryLib = lib // {
@@ -30,23 +49,23 @@ let
registryDefinitionModule = {
options = {
type = lib.mkOption {
type = lib.types.raw;
type = mkOption {
type = types.raw;
description = ''
NixOS option type for one registry entry.
'';
};
replicate = lib.mkOption {
type = lib.types.bool;
replicate = mkOption {
type = types.bool;
default = false;
description = ''
Whether collected entries are merged and published under every host key.
'';
};
checks = lib.mkOption {
type = lib.types.listOf checkType;
checks = mkOption {
type = types.listOf checkType;
default = [ ];
description = ''
Validation checks for this registry's flattened collected entries.
@@ -55,10 +74,10 @@ let
};
};
registryName = fileName: lib.removeSuffix ".nix" fileName;
registryName = fileName: removeSuffix ".nix" fileName;
registryOption = registry: lib.mkOption {
type = lib.types.attrsOf (lib.types.attrsOf registry.type);
registryOption = registry: mkOption {
type = types.attrsOf (types.attrsOf registry.type);
default = { };
description = ''
Lazily collected fleet-visible registry entries, nested by host and entry name.
@@ -79,19 +98,19 @@ let
inherit (evaluated.config) type replicate checks;
};
definitions = lib.mapAttrs' (
definitions = mapAttrs' (
name: type:
let
path = root + "/${name}";
path = self + "/registry/${name}";
in
lib.nameValuePair (registryName name) (mkRegistry path)
) (lib.filterAttrs (name: type: type == "regular" && lib.hasSuffix ".nix" name) (builtins.readDir root));
nameValuePair (registryName name) (mkRegistry path)
) (filterAttrs (name: type: type == "regular" && hasSuffix ".nix" name) (builtins.readDir (self + "/registry")));
flattenRegistryEntries = registryName: data:
lib.concatLists (
lib.mapAttrsToList (
concatLists (
mapAttrsToList (
host: entries:
lib.mapAttrsToList (entry: value: {
mapAttrsToList (entry: value: {
path = "registry.${registryName}.${host}.${entry}";
inherit host entry value;
}) entries
@@ -99,17 +118,17 @@ let
);
rawDeclarations = registryName: hosts:
lib.mapAttrs (_hostName: host: host.config.registry.${registryName} or { }) hosts;
mapAttrs (_hostName: host: host.config.registry.${registryName} or { }) hosts;
replicatedEntries = registryName: raw:
let
entries = lib.concatLists (
lib.concatLists (
lib.mapAttrsToList (
entries = concatLists (
concatLists (
mapAttrsToList (
_evalHost: hostDeclarations:
lib.mapAttrsToList (
mapAttrsToList (
hostName: declarations:
lib.mapAttrsToList (entryName: value: {
mapAttrsToList (entryName: value: {
path = "registry.${registryName}.${hostName}.${entryName}";
inherit entryName value;
}) declarations
@@ -118,9 +137,9 @@ let
)
);
in
lib.foldl' (
foldl' (
acc: entry:
if lib.hasAttr entry.entryName acc then
if hasAttr entry.entryName acc then
if acc.${entry.entryName}.value == entry.value then
acc
else
@@ -133,13 +152,13 @@ let
replicatedData = registryName: hosts: raw:
let
entries = lib.mapAttrs (_entryName: entry: entry.value) (replicatedEntries registryName raw);
entries = mapAttrs (_entryName: entry: entry.value) (replicatedEntries registryName raw);
in
lib.mapAttrs (_hostName: _host: entries) hosts;
mapAttrs (_hostName: _host: entries) hosts;
validationAssertions = data:
lib.concatLists (
lib.mapAttrsToList (
concatLists (
mapAttrsToList (
registryName: registry:
let
entries = flattenRegistryEntries registryName data.${registryName};
@@ -154,28 +173,28 @@ let
assertValid = data:
let
assertions = validationAssertions data;
failures = lib.filter (assertion: !assertion.assertion) assertions;
failures = filter (assertion: !assertion.assertion) assertions;
in
assert lib.assertMsg (lib.all (assertion: assertion.assertion) assertions) (
lib.concatMapStringsSep "\n" (assertion: assertion.message) failures
assert lib.assertMsg (all (assertion: assertion.assertion) assertions) (
concatMapStringsSep "\n" (assertion: assertion.message) failures
);
data;
join = registry: host: entry:
lib.filterAttrs (_name: value: value != null) (
lib.mapAttrs (registryName: _registry: (registry.${registryName}.${host} or { }).${entry} or null) definitions
filterAttrs (_name: value: value != null) (
mapAttrs (registryName: _registry: (registry.${registryName}.${host} or { }).${entry} or null) definitions
);
collectData =
{ hosts }:
let
raw = lib.mapAttrs (registryName: _registry: rawDeclarations registryName hosts) definitions;
data = lib.mapAttrs (
raw = mapAttrs (registryName: _registry: rawDeclarations registryName hosts) definitions;
data = mapAttrs (
registryName: registry:
if registry.replicate or false then
replicatedData registryName hosts raw.${registryName}
else
lib.mapAttrs (hostName: host: host.config.registry.${registryName}.${hostName} or { }) hosts
mapAttrs (hostName: host: host.config.registry.${registryName}.${hostName} or { }) hosts
) definitions;
in
assertValid data;
@@ -187,11 +206,11 @@ let
};
in
{
types = lib.mapAttrs (_name: definition: definition.type) definitions;
inherit definitions predicates;
module = {
options.registry = lib.mapAttrs (_name: registry: registryOption registry) definitions;
options.registry = mapAttrs (_name: registry: registryOption registry) definitions;
};
collected = withOperations (collectData { inherit hosts; });
collect = args: withOperations (collectData args);
}

View File

@@ -121,6 +121,5 @@ in
modules.shell.nvim.enable = lib.mkDefault true;
modules.shell.git.enable = lib.mkDefault true;
modules.shell.direnv.enable = lib.mkDefault true;
modules.shell.yazi.enable = lib.mkDefault true;
};
}

View File

@@ -1,18 +0,0 @@
{
config,
lib,
pkgs,
...
}:
# Ghostty as the desktop terminal.
let
cfg = config.modules.desktop.apps.ghostty;
user = config.user.name;
in
{
options.modules.desktop.apps.ghostty.enable = lib.mkEnableOption "Ghostty as the desktop terminal";
config = lib.mkIf cfg.enable {
home-manager.users.${user}.home.packages = [ pkgs.ghostty ];
};
}

View File

@@ -9,8 +9,8 @@ in
# Each piece is turned on at default priority, so a host can still override
# any one of them while the single flag above enables the whole desktop.
config = lib.mkIf cfg.enable {
modules.desktop.apps.alacritty.enable = lib.mkDefault true;
modules.desktop.apps.firefox.enable = lib.mkDefault true;
modules.desktop.apps.ghostty.enable = lib.mkDefault true;
modules.desktop.session.hyprland.enable = lib.mkDefault true;
modules.desktop.session.hyprland.hypridle.enable = lib.mkDefault true;
modules.desktop.session.hyprland.hyprlock.enable = lib.mkDefault true;

View File

@@ -61,7 +61,7 @@ in
settings = {
"$mod" = "SUPER";
"$terminal" = "ghostty";
"$terminal" = "alacritty";
# Session variables handed to the compositor directly.
# UWSM launches the session without the shell profile that would carry

View File

@@ -89,7 +89,6 @@ in
window-rewrite-default = g "f2d0";
window-rewrite = {
"class<Alacritty>" = g "f120";
"class<com.mitchellh.ghostty>" = g "f120";
"class<.*[Ff]irefox.*>" = g "f269";
"class<chromium.*>" = g "f268";
"class<[Cc]ode>" = g "f121";

View File

@@ -20,7 +20,6 @@ in
# nix-direnv caches the evaluated shell so re-entering a directory is instant
# instead of re-running `nix develop`, and adds the `use flake` stdlib helper.
nix-direnv.enable = true;
stdlib = builtins.readFile ./repo-flake.sh;
};
};
}

View File

@@ -1,33 +0,0 @@
if declare -f use_flake >/dev/null; then
__dotfiles_use_flake_definition="$(declare -f use_flake)"
eval "${__dotfiles_use_flake_definition/use_flake/__dotfiles_nix_direnv_use_flake}"
unset __dotfiles_use_flake_definition
use_flake() {
local flake_expr="${1:-.}"
if [[ "$flake_expr" == //* ]]; then
local git_root
if ! git_root="$(git rev-parse --show-toplevel 2>/dev/null)"; then
log_error 'use flake // requires a Git repository'
return 1
fi
local flake_suffix="${flake_expr#//}"
if [[ -n "$flake_suffix" && "$flake_suffix" != \#* && "$flake_suffix" != /* ]]; then
flake_expr="path:${git_root}/${flake_suffix}"
else
flake_expr="path:${git_root}${flake_suffix}"
fi
shift
__dotfiles_nix_direnv_use_flake "$flake_expr" "$@"
return
fi
__dotfiles_nix_direnv_use_flake "$@"
}
else
log_error 'nix-direnv must define use_flake before the // wrapper loads'
return 1
fi

View File

@@ -38,9 +38,6 @@ in
[ui]
prompt_new_tab_name = false
[experimental]
kitty_graphics = true
'';
};
};

View File

@@ -16,16 +16,6 @@ vim.api.nvim_create_autocmd("FileType", {
end,
})
-- Soft-wrap prose buffers without inserting line breaks.
vim.api.nvim_create_autocmd("FileType", {
pattern = { "gitcommit", "markdown", "text" },
callback = function()
vim.opt_local.wrap = true
vim.opt_local.linebreak = true
vim.opt_local.breakindent = true
end,
})
-- Turn line blame off again once the Neogit status buffer is closed.
vim.api.nvim_create_autocmd("BufUnload", {
callback = function(args)

View File

@@ -92,18 +92,6 @@ in
action = "<cmd>nohlsearch<CR>";
options.desc = "Clear search highlight";
}
{
mode = "n";
key = "j";
action = "gj";
options.desc = "Move down by display line";
}
{
mode = "n";
key = "k";
action = "gk";
options.desc = "Move up by display line";
}
{
mode = "n";
key = "<leader>e";

View File

@@ -1,32 +0,0 @@
{
config,
lib,
pkgs,
...
}:
# Yazi, a terminal file manager.
let
cfg = config.modules.shell.yazi;
user = config.user.name;
in
{
options.modules.shell.yazi.enable = lib.mkEnableOption "Yazi, a terminal file manager";
config = lib.mkIf cfg.enable {
home-manager.users.${user}.programs.yazi = {
enable = true;
enableFishIntegration = true;
extraPackages = with pkgs; [
fd
ffmpegthumbnailer
fzf
imagemagick
jq
poppler
ripgrep
unar
zoxide
];
};
};
}