mirror of
https://github.com/oqyude/nixos.git
synced 2026-10-07 20:47:14 +03:00
big refactoring
This commit is contained in:
+14
-12
@@ -2,26 +2,28 @@
|
||||
inputs,
|
||||
...
|
||||
}:
|
||||
# Builds a NixOS system from a host record.
|
||||
#
|
||||
# `xlib` is the pure host value (lib/xlib.nix `mkXlib`) built in
|
||||
# configurations/default.nix. It is handed to every module as the `xlib`
|
||||
# argument, so modules read plain `xlib.*` data instead of `config.xlib.*`
|
||||
# and the host record stays the single source of truth.
|
||||
{
|
||||
deviceType,
|
||||
hostname ? null,
|
||||
xlib,
|
||||
modules ? [ ],
|
||||
system ? "x86_64-linux",
|
||||
...
|
||||
}:
|
||||
let
|
||||
lib = inputs.nixpkgs.lib;
|
||||
in
|
||||
lib.nixosSystem {
|
||||
inherit system;
|
||||
modules = modules ++ [
|
||||
{
|
||||
xlib.device = {
|
||||
type = deviceType;
|
||||
}
|
||||
// lib.optionalAttrs (hostname != null) { inherit hostname; };
|
||||
}
|
||||
];
|
||||
inherit
|
||||
system
|
||||
modules
|
||||
;
|
||||
specialArgs = {
|
||||
inherit deviceType inputs;
|
||||
inherit inputs;
|
||||
inherit xlib;
|
||||
};
|
||||
}
|
||||
|
||||
+119
-10
@@ -2,9 +2,49 @@
|
||||
lib,
|
||||
...
|
||||
}:
|
||||
# Shared pure helper functions for module definitions.
|
||||
# Injected into every module via `xlib.helpers` (see options.nix).
|
||||
# Pure host library: no module system involved.
|
||||
#
|
||||
# `mkXlib` derives everything a host needs to know about itself (identity,
|
||||
# well-known paths, capability flags, shared helpers) from a single record.
|
||||
# It is built in flake-level code (configurations/default.nix) and handed to
|
||||
# every module as the `xlib` argument via lib/mkSystem.nix, so modules read
|
||||
# plain `xlib.*` values instead of `config.xlib.*` and nothing in xlib can be
|
||||
# overridden per host — the host record is the only place to change it.
|
||||
let
|
||||
# Every supported device type and its capabilities. Single source of truth:
|
||||
# replaces the old `lib.types.enum` in modules/options.nix and the
|
||||
# hand-written type lists in modules/default.nix and home/home.nix.
|
||||
devices = {
|
||||
minimal = {
|
||||
desktop = false;
|
||||
headless = false;
|
||||
};
|
||||
primary = {
|
||||
desktop = true;
|
||||
headless = false;
|
||||
};
|
||||
secondary = {
|
||||
desktop = true;
|
||||
headless = false;
|
||||
};
|
||||
server = {
|
||||
desktop = false;
|
||||
headless = true;
|
||||
};
|
||||
vds = {
|
||||
desktop = false;
|
||||
headless = true;
|
||||
};
|
||||
wsl = {
|
||||
desktop = false;
|
||||
headless = true;
|
||||
};
|
||||
termux = {
|
||||
desktop = false;
|
||||
headless = true;
|
||||
};
|
||||
};
|
||||
|
||||
# tmpfiles rule: "type dir mode user group -"
|
||||
mkTmpfile =
|
||||
type: dir: mode: user: group:
|
||||
@@ -138,16 +178,85 @@ let
|
||||
name = targetPath;
|
||||
value.source = config.lib.file.mkOutOfStoreSymlink "${sourcePath}";
|
||||
}) paths;
|
||||
|
||||
helpers = {
|
||||
inherit
|
||||
mkTmpfile
|
||||
mkTmpDirs
|
||||
mkBindMount
|
||||
mkSystemdBind
|
||||
mkServiceStorage
|
||||
mkNtfsMount
|
||||
mkExfatMount
|
||||
mkSymlinks
|
||||
;
|
||||
};
|
||||
|
||||
# Well-known paths. Everything derives from `username`, which is why the
|
||||
# whole set can be computed outside the module system.
|
||||
mkDirs =
|
||||
username:
|
||||
let
|
||||
user-home = "/home/${username}";
|
||||
wsl-home = "/mnt/c/Users/${username}";
|
||||
server-home = "${user-home}/External";
|
||||
services-mnt-folder = "/mnt/services";
|
||||
in
|
||||
{
|
||||
inherit
|
||||
user-home
|
||||
wsl-home
|
||||
server-home
|
||||
services-mnt-folder
|
||||
;
|
||||
|
||||
user-storage = "${user-home}/Storage";
|
||||
wsl-storage = "${wsl-home}/Storage";
|
||||
server-credentials = "${server-home}/Credentials/server";
|
||||
storage = "${server-home}/Storage";
|
||||
calibre-library = "${server-home}/Books-Library";
|
||||
services-folder = "${server-home}/Services";
|
||||
services-nodes-folder = "${services-mnt-folder}/nodes";
|
||||
postgresql-folder = "${services-mnt-folder}/postgresql";
|
||||
music-library = "${user-home}/Music";
|
||||
|
||||
archive-drive = "/mnt/archive";
|
||||
lamet-drive = "/mnt/lamet";
|
||||
mobile-drive = "/mnt/mobile";
|
||||
therima-drive = "/mnt/therima";
|
||||
vetymae-drive = "/mnt/vetymae";
|
||||
soptur-drive = "/mnt/soptur";
|
||||
};
|
||||
|
||||
mkXlib =
|
||||
{
|
||||
hostname,
|
||||
type,
|
||||
username ? "oqyude",
|
||||
}:
|
||||
let
|
||||
# Unknown device type fails here, at flake level, with the valid list.
|
||||
capabilities = devices.${type} or (throw "xlib: unknown device type '${type}', expected one of ${lib.concatStringsSep ", " (builtins.attrNames devices)}");
|
||||
in
|
||||
{
|
||||
device = {
|
||||
inherit
|
||||
hostname
|
||||
type
|
||||
username
|
||||
;
|
||||
};
|
||||
isDesktop = capabilities.desktop;
|
||||
isHeadless = capabilities.headless;
|
||||
dirs = mkDirs username;
|
||||
inherit helpers;
|
||||
};
|
||||
in
|
||||
{
|
||||
inherit
|
||||
mkTmpfile
|
||||
mkTmpDirs
|
||||
mkBindMount
|
||||
mkSystemdBind
|
||||
mkServiceStorage
|
||||
mkNtfsMount
|
||||
mkExfatMount
|
||||
mkSymlinks
|
||||
devices
|
||||
helpers
|
||||
mkDirs
|
||||
mkXlib
|
||||
;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user