Reshuffling stuff
This commit is contained in:
@@ -1,39 +1,33 @@
|
||||
{ config, lib, pkgs, flakeRoot, inputs, ... }:
|
||||
# ./modules/apps/packages.nix
|
||||
{ lib, config, flakeRoot, ... }:
|
||||
|
||||
let
|
||||
packagesConfPath = "${flakeRoot}/assets/system/apps/packages.conf";
|
||||
raw = builtins.readFile packagesConfPath;
|
||||
# IMPORTANT: explicit "\n" so we never accidentally split into characters
|
||||
|
||||
# split lines safely
|
||||
rawLines = lib.splitString "\n" raw;
|
||||
# Guard: if we accidentally split into characters, rawLines length ~= stringLength raw
|
||||
|
||||
# guard against accidental character splitting
|
||||
_guard = assert !(
|
||||
builtins.stringLength raw > 1 &&
|
||||
builtins.length rawLines == builtins.stringLength raw
|
||||
builtins.stringLength raw > 1 &&
|
||||
builtins.length rawLines == builtins.stringLength raw
|
||||
); true;
|
||||
cleanLine = l:
|
||||
let
|
||||
noCR = lib.replaceStrings [ "\r" ] [ "" ] l;
|
||||
noInlineComment = lib.head (lib.splitString "#" noCR);
|
||||
in
|
||||
lib.strings.trim noInlineComment;
|
||||
entries =
|
||||
builtins.filter (l: l != "")
|
||||
(map cleanLine rawLines);
|
||||
resolvePkg = name:
|
||||
let
|
||||
parts = lib.splitString "." name;
|
||||
found = lib.attrByPath parts null pkgs;
|
||||
in
|
||||
if found == null then
|
||||
throw ''
|
||||
packages.nix: package not found in pkgs
|
||||
Token : ${builtins.toJSON name}
|
||||
packages.conf : ${toString packagesConfPath}
|
||||
Hint : check the attribute name on search.nixos.org/packages
|
||||
''
|
||||
else
|
||||
found;
|
||||
packages = builtins.seq _guard (map resolvePkg entries);
|
||||
in
|
||||
{
|
||||
environment.systemPackages = packages;
|
||||
|
||||
# clean a line (remove CR, inline comments, whitespace)
|
||||
cleanLine = line:
|
||||
let
|
||||
noCR = lib.replaceStrings [ "\r" ] [ "" ] line;
|
||||
noInlineComment = lib.head (lib.splitString "#" noCR);
|
||||
in
|
||||
lib.strings.trim noInlineComment;
|
||||
|
||||
entries = builtins.filter (l: l != "") (map cleanLine rawLines);
|
||||
|
||||
in {
|
||||
# --- symbolic config only ---
|
||||
mySystem.apps.packages = {
|
||||
enable = true;
|
||||
packageNames = entries; # just the names, no pkgs references
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user