Reshuffling stuff
This commit is contained in:
+26
-32
@@ -768,44 +768,38 @@ This is top file of this level which contains just an import statement for all r
|
|||||||
** =generated/modules/apps/packages.nix=
|
** =generated/modules/apps/packages.nix=
|
||||||
This will import all packages listed in ./assets/system/apps/packlages.conf
|
This will import all packages listed in ./assets/system/apps/packlages.conf
|
||||||
#+BEGIN_SRC nix :tangle generated/modules/apps/packages.nix :noweb tangle :mkdirp yes :eval never-html
|
#+BEGIN_SRC nix :tangle generated/modules/apps/packages.nix :noweb tangle :mkdirp yes :eval never-html
|
||||||
{ config, lib, pkgs, flakeRoot, inputs, ... }:
|
# ./modules/apps/packages.nix
|
||||||
|
{ lib, config, flakeRoot, ... }:
|
||||||
|
|
||||||
let
|
let
|
||||||
packagesConfPath = "${flakeRoot}/assets/system/apps/packages.conf";
|
packagesConfPath = "${flakeRoot}/assets/system/apps/packages.conf";
|
||||||
raw = builtins.readFile packagesConfPath;
|
raw = builtins.readFile packagesConfPath;
|
||||||
# IMPORTANT: explicit "\n" so we never accidentally split into characters
|
|
||||||
|
# split lines safely
|
||||||
rawLines = lib.splitString "\n" raw;
|
rawLines = lib.splitString "\n" raw;
|
||||||
# Guard: if we accidentally split into characters, rawLines length ~= stringLength raw
|
|
||||||
|
# guard against accidental character splitting
|
||||||
_guard = assert !(
|
_guard = assert !(
|
||||||
builtins.stringLength raw > 1 &&
|
builtins.stringLength raw > 1 &&
|
||||||
builtins.length rawLines == builtins.stringLength raw
|
builtins.length rawLines == builtins.stringLength raw
|
||||||
); true;
|
); true;
|
||||||
cleanLine = l:
|
|
||||||
let
|
# clean a line (remove CR, inline comments, whitespace)
|
||||||
noCR = lib.replaceStrings [ "\r" ] [ "" ] l;
|
cleanLine = line:
|
||||||
noInlineComment = lib.head (lib.splitString "#" noCR);
|
let
|
||||||
in
|
noCR = lib.replaceStrings [ "\r" ] [ "" ] line;
|
||||||
lib.strings.trim noInlineComment;
|
noInlineComment = lib.head (lib.splitString "#" noCR);
|
||||||
entries =
|
in
|
||||||
builtins.filter (l: l != "")
|
lib.strings.trim noInlineComment;
|
||||||
(map cleanLine rawLines);
|
|
||||||
resolvePkg = name:
|
entries = builtins.filter (l: l != "") (map cleanLine rawLines);
|
||||||
let
|
|
||||||
parts = lib.splitString "." name;
|
in {
|
||||||
found = lib.attrByPath parts null pkgs;
|
# --- symbolic config only ---
|
||||||
in
|
mySystem.apps.packages = {
|
||||||
if found == null then
|
enable = true;
|
||||||
throw ''
|
packageNames = entries; # just the names, no pkgs references
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
#+END_SRC
|
#+END_SRC
|
||||||
|
|
||||||
|
|||||||
@@ -1,39 +1,33 @@
|
|||||||
{ config, lib, pkgs, flakeRoot, inputs, ... }:
|
# ./modules/apps/packages.nix
|
||||||
|
{ lib, config, flakeRoot, ... }:
|
||||||
|
|
||||||
let
|
let
|
||||||
packagesConfPath = "${flakeRoot}/assets/system/apps/packages.conf";
|
packagesConfPath = "${flakeRoot}/assets/system/apps/packages.conf";
|
||||||
raw = builtins.readFile packagesConfPath;
|
raw = builtins.readFile packagesConfPath;
|
||||||
# IMPORTANT: explicit "\n" so we never accidentally split into characters
|
|
||||||
|
# split lines safely
|
||||||
rawLines = lib.splitString "\n" raw;
|
rawLines = lib.splitString "\n" raw;
|
||||||
# Guard: if we accidentally split into characters, rawLines length ~= stringLength raw
|
|
||||||
|
# guard against accidental character splitting
|
||||||
_guard = assert !(
|
_guard = assert !(
|
||||||
builtins.stringLength raw > 1 &&
|
builtins.stringLength raw > 1 &&
|
||||||
builtins.length rawLines == builtins.stringLength raw
|
builtins.length rawLines == builtins.stringLength raw
|
||||||
); true;
|
); true;
|
||||||
cleanLine = l:
|
|
||||||
let
|
# clean a line (remove CR, inline comments, whitespace)
|
||||||
noCR = lib.replaceStrings [ "\r" ] [ "" ] l;
|
cleanLine = line:
|
||||||
noInlineComment = lib.head (lib.splitString "#" noCR);
|
let
|
||||||
in
|
noCR = lib.replaceStrings [ "\r" ] [ "" ] line;
|
||||||
lib.strings.trim noInlineComment;
|
noInlineComment = lib.head (lib.splitString "#" noCR);
|
||||||
entries =
|
in
|
||||||
builtins.filter (l: l != "")
|
lib.strings.trim noInlineComment;
|
||||||
(map cleanLine rawLines);
|
|
||||||
resolvePkg = name:
|
entries = builtins.filter (l: l != "") (map cleanLine rawLines);
|
||||||
let
|
|
||||||
parts = lib.splitString "." name;
|
in {
|
||||||
found = lib.attrByPath parts null pkgs;
|
# --- symbolic config only ---
|
||||||
in
|
mySystem.apps.packages = {
|
||||||
if found == null then
|
enable = true;
|
||||||
throw ''
|
packageNames = entries; # just the names, no pkgs references
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user