Reshuffling stuff

This commit is contained in:
2026-03-18 18:37:07 +00:00
parent a82e8ed459
commit 17076e1b25
3 changed files with 212 additions and 168 deletions
+116 -94
View File
@@ -768,23 +768,84 @@ 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
# ./modules/apps/packages.nix { config, lib, pkgs, flakeRoot, inputs, ... }:
{ lib, config, flakeRoot, ... }:
let let
packagesConfPath = "${flakeRoot}/assets/system/apps/packages.conf"; # --- Path to your packages.conf ---
packagesConfPath = "${flakeRoot}/assets/conf/apps/packages.conf";
# --- Read raw content ---
raw = builtins.readFile packagesConfPath; raw = builtins.readFile packagesConfPath;
# split lines safely # --- Split into lines explicitly on "\n" to avoid accidental char splitting ---
rawLines = lib.splitString "\n" raw; rawLines = lib.splitString "\n" raw;
# guard against accidental character splitting # --- 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;
# clean a line (remove CR, inline comments, whitespace) # --- Clean each line: remove CR, inline comments, trim ---
cleanLine = line:
let
noCR = lib.replaceStrings [ "\r" ] [ "" ] line;
noComment = lib.head (lib.splitString "#" noCR);
in
lib.strings.trim noComment;
# --- Filter empty lines ---
entries = builtins.filter (l: l != "") (map cleanLine rawLines);
# --- Resolve a package name from pkgs ---
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;
# --- Map entries to actual pkgs ---
packages = builtins.seq _guard (map resolvePkg entries);
# --- Zen Browser package from inputs ---
zenBrowser =
inputs.zen-browser.packages.${pkgs.stdenv.hostPlatform.system}.default;
in
{
# --- Add the packages to systemPackages ---
environment.systemPackages = packages ++ [ zenBrowser ];
}
#+END_SRC
** =generated/modules/apps/flatpaks.nix=
This will import all packages listed in ./assets/system/apps/flatpaks.conf
#+BEGIN_SRC nix :tangle generated/modules/apps/flatpaks.nix :noweb tangle :mkdirp yes :eval never-html
{ lib, config, pkgs, flakeRoot, ... }:
let
moduleName = "install-flatpaks";
flatpakConfPath = "${flakeRoot}/assets/system/apps/flatpaks.conf";
# Lees en split het bestand
raw = builtins.readFile flatpakConfPath;
rawLines = lib.splitString "\n" raw;
# Guard: check dat we niet per karakter hebben gesplit
_guard =
assert !(builtins.stringLength raw > 1 && builtins.length rawLines == builtins.stringLength raw);
true;
# Cleanup per regel: CR verwijderen, commentaar weghalen, trim
cleanLine = line: cleanLine = line:
let let
noCR = lib.replaceStrings [ "\r" ] [ "" ] line; noCR = lib.replaceStrings [ "\r" ] [ "" ] line;
@@ -792,129 +853,90 @@ let
in in
lib.strings.trim noInlineComment; lib.strings.trim noInlineComment;
# Filter lege regels
entries = builtins.filter (l: l != "") (map cleanLine rawLines); entries = builtins.filter (l: l != "") (map cleanLine rawLines);
in { # Validatie: check reverse-DNS stijl (min 2 dots)
# --- symbolic config only ---
mySystem.apps.packages = {
enable = true;
packageNames = entries; # just the names, no pkgs references
};
}
#+END_SRC
** =generated/modules/apps/flatpaks.nix=
This will import all packages listed in ./assets/system/apps/flatpaks.conf
#+BEGIN_SRC nix :tangle generated/modules/apps/flatpaks.nix :noweb tangle :mkdirp yes :eval never-html
{
config,
pkgs,
lib,
flakeRoot,
...
}:
let
moduleName = "install-flatpaks";
flatpakConfPath = "${flakeRoot}/assets/system/apps/flatpaks.conf";
raw = builtins.readFile flatpakConfPath;
# Explicit "\n" so we never accidentally split into characters
rawLines = lib.splitString "\n" raw;
# Guard: if we accidentally split into characters, rawLines length ~= stringLength raw
_guard =
assert !(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);
# Flatpak app IDs are reverse-DNS style like org.example.App (at least 2 dots).
# We'll validate and fail early with a clear message.
dotCount = s: builtins.length (lib.splitString "." s) - 1; dotCount = s: builtins.length (lib.splitString "." s) - 1;
isValidId = s: (dotCount s) >= 2;
isValidId = s: (dotCount s) >= 2; # matches the error you're seeing: "at least 2 periods"
_validate = builtins.seq _guard ( _validate = builtins.seq _guard (
builtins.map ( builtins.map (id:
id: if isValidId id then true
if isValidId id then else throw ''
true ${moduleName}: invalid Flatpak ID in flatpaks.conf (needs reverse-DNS with at least 2 dots)
else
throw ''
${moduleName}: invalid Flatpak ID in flatpaks.conf (needs reverse-DNS with at least 2 dots)
Token : ${builtins.toJSON id} Token : ${builtins.toJSON id}
flatpaks.conf : ${toString flatpakConfPath} flatpaks.conf : ${toString flatpakConfPath}
Fix: remove stray tokens/headers, or comment them out with '#'. Fix: remove stray tokens or comment them out with '#'.
'' ''
) entries ) entries
); );
# Use validated entries # Gebruik de gevalideerde lijst
flatpakApps = builtins.seq _validate entries; flatpakApps = builtins.seq _validate entries;
# Maak systemd script
syncFlatpaks = pkgs.writeShellScript "sync-flatpaks" '' syncFlatpaks = pkgs.writeShellScript "sync-flatpaks" ''
set -euo pipefail set -euo pipefail
# Use the deployed config path (matches environment.etc below)
CONF="/etc/flatpak/flatpaks.conf" CONF="/etc/flatpak/flatpaks.conf"
if [[ -f "$CONF" ]]; then if [[ -f "$CONF" ]]; then
echo "flatpak-sync: using $CONF" echo "flatpak-sync: using $CONF"
else else
echo "flatpak-sync: WARNING: $CONF not found, using embedded list" echo "flatpak-sync: WARNING: $CONF not found, using embedded list"
fi fi
if ! flatpak remotes --system --columns=name | grep -qx flathub; then if ! flatpak remotes --system --columns=name | grep -qx flathub; then
flatpak remote-add --system --if-not-exists flathub https://dl.flathub.org/repo/flathub.flatpakrepo flatpak remote-add --system --if-not-exists flathub https://dl.flathub.org/repo/flathub.flatpakrepo
fi fi
desired_apps=( desired_apps=(
${lib.concatStringsSep "\n" (map (a: ''"${a}"'') flatpakApps)} ${lib.concatStringsSep "\n" (map (a: ''"${a}"'') flatpakApps)}
) )
for app in "''${desired_apps[@]}"; do for app in "${desired_apps[@]}"; do
if ! flatpak info --system "$app" >/dev/null 2>&1; then if ! flatpak info --system "$app" >/dev/null 2>&1; then
flatpak install --system -y --noninteractive flathub "$app" flatpak install --system -y --noninteractive flathub "$app"
fi fi
done done
''; '';
in in
{ {
services.flatpak.enable = true; options.mySystem.system.flatpak.enable = lib.mkEnableOption "Enable automatic Flatpak installation";
xdg.portal = { config = lib.mkIf (config.mySystem.system.flatpak.enable or false) {
enable = true;
};
# Deploy the config file for runtime visibility/debugging # Flatpak service zelf
environment.etc."flatpak/flatpaks.conf".source = lib.mkForce flatpakConfPath; services.flatpak.enable = true;
systemd.services.flatpak-sync = { xdg.portal.enable = true;
description = "Install Flatpak apps listed in flatpaks.conf";
wantedBy = [ "multi-user.target" ];
wants = [ "network-online.target" ];
after = [ "network-online.target" ];
serviceConfig = { # Deploy config voor runtime/debug
Type = "oneshot"; environment.etc."flatpak/flatpaks.conf".source = lib.mkForce flatpakConfPath;
ExecStart = syncFlatpaks;
# systemd service
systemd.services.flatpak-sync = {
description = "Install Flatpak apps listed in flatpaks.conf";
wantedBy = [ "multi-user.target" ];
wants = [ "network-online.target" ];
after = [ "network-online.target" ];
serviceConfig = {
Type = "oneshot";
ExecStart = syncFlatpaks;
};
restartTriggers = [ flatpakConfPath ];
path = [
pkgs.flatpak
pkgs.coreutils
pkgs.gnugrep
pkgs.gnused
];
}; };
restartTriggers = [ flatpakConfPath ];
path = [
pkgs.flatpak
pkgs.coreutils
pkgs.gnugrep
pkgs.gnused
];
}; };
} }
#+END_SRC #+END_SRC
+58 -60
View File
@@ -1,111 +1,109 @@
{ { lib, config, pkgs, flakeRoot, ... }:
config,
pkgs,
lib,
flakeRoot,
...
}:
let let
moduleName = "install-flatpaks"; moduleName = "install-flatpaks";
flatpakConfPath = "${flakeRoot}/assets/system/apps/flatpaks.conf"; flatpakConfPath = "${flakeRoot}/assets/system/apps/flatpaks.conf";
# Lees en split het bestand
raw = builtins.readFile flatpakConfPath; raw = builtins.readFile flatpakConfPath;
# Explicit "\n" so we never accidentally split into characters
rawLines = lib.splitString "\n" raw; rawLines = lib.splitString "\n" raw;
# Guard: if we accidentally split into characters, rawLines length ~= stringLength raw # Guard: check dat we niet per karakter hebben gesplit
_guard = _guard =
assert !(builtins.stringLength raw > 1 && builtins.length rawLines == builtins.stringLength raw); assert !(builtins.stringLength raw > 1 && builtins.length rawLines == builtins.stringLength raw);
true; true;
cleanLine = # Cleanup per regel: CR verwijderen, commentaar weghalen, trim
l: cleanLine = line:
let let
noCR = lib.replaceStrings [ "\r" ] [ "" ] l; noCR = lib.replaceStrings [ "\r" ] [ "" ] line;
noInlineComment = lib.head (lib.splitString "#" noCR); noInlineComment = lib.head (lib.splitString "#" noCR);
in in
lib.strings.trim noInlineComment; lib.strings.trim noInlineComment;
# Filter lege regels
entries = builtins.filter (l: l != "") (map cleanLine rawLines); entries = builtins.filter (l: l != "") (map cleanLine rawLines);
# Flatpak app IDs are reverse-DNS style like org.example.App (at least 2 dots). # Validatie: check reverse-DNS stijl (min 2 dots)
# We'll validate and fail early with a clear message.
dotCount = s: builtins.length (lib.splitString "." s) - 1; dotCount = s: builtins.length (lib.splitString "." s) - 1;
isValidId = s: (dotCount s) >= 2;
isValidId = s: (dotCount s) >= 2; # matches the error you're seeing: "at least 2 periods"
_validate = builtins.seq _guard ( _validate = builtins.seq _guard (
builtins.map ( builtins.map (id:
id: if isValidId id then true
if isValidId id then else throw ''
true ${moduleName}: invalid Flatpak ID in flatpaks.conf (needs reverse-DNS with at least 2 dots)
else
throw ''
${moduleName}: invalid Flatpak ID in flatpaks.conf (needs reverse-DNS with at least 2 dots)
Token : ${builtins.toJSON id} Token : ${builtins.toJSON id}
flatpaks.conf : ${toString flatpakConfPath} flatpaks.conf : ${toString flatpakConfPath}
Fix: remove stray tokens/headers, or comment them out with '#'. Fix: remove stray tokens or comment them out with '#'.
'' ''
) entries ) entries
); );
# Use validated entries # Gebruik de gevalideerde lijst
flatpakApps = builtins.seq _validate entries; flatpakApps = builtins.seq _validate entries;
# Maak systemd script
syncFlatpaks = pkgs.writeShellScript "sync-flatpaks" '' syncFlatpaks = pkgs.writeShellScript "sync-flatpaks" ''
set -euo pipefail set -euo pipefail
# Use the deployed config path (matches environment.etc below)
CONF="/etc/flatpak/flatpaks.conf" CONF="/etc/flatpak/flatpaks.conf"
if [[ -f "$CONF" ]]; then if [[ -f "$CONF" ]]; then
echo "flatpak-sync: using $CONF" echo "flatpak-sync: using $CONF"
else else
echo "flatpak-sync: WARNING: $CONF not found, using embedded list" echo "flatpak-sync: WARNING: $CONF not found, using embedded list"
fi fi
if ! flatpak remotes --system --columns=name | grep -qx flathub; then if ! flatpak remotes --system --columns=name | grep -qx flathub; then
flatpak remote-add --system --if-not-exists flathub https://dl.flathub.org/repo/flathub.flatpakrepo flatpak remote-add --system --if-not-exists flathub https://dl.flathub.org/repo/flathub.flatpakrepo
fi fi
desired_apps=( desired_apps=(
${lib.concatStringsSep "\n" (map (a: ''"${a}"'') flatpakApps)} ${lib.concatStringsSep "\n" (map (a: ''"${a}"'') flatpakApps)}
) )
for app in "''${desired_apps[@]}"; do for app in "${desired_apps[@]}"; do
if ! flatpak info --system "$app" >/dev/null 2>&1; then if ! flatpak info --system "$app" >/dev/null 2>&1; then
flatpak install --system -y --noninteractive flathub "$app" flatpak install --system -y --noninteractive flathub "$app"
fi fi
done done
''; '';
in in
{ {
services.flatpak.enable = true; options.mySystem.system.flatpak.enable = lib.mkEnableOption "Enable automatic Flatpak installation";
xdg.portal = { config = lib.mkIf (config.mySystem.system.flatpak.enable or false) {
enable = true;
};
# Deploy the config file for runtime visibility/debugging # Flatpak service zelf
environment.etc."flatpak/flatpaks.conf".source = lib.mkForce flatpakConfPath; services.flatpak.enable = true;
systemd.services.flatpak-sync = { xdg.portal.enable = true;
description = "Install Flatpak apps listed in flatpaks.conf";
wantedBy = [ "multi-user.target" ];
wants = [ "network-online.target" ];
after = [ "network-online.target" ];
serviceConfig = { # Deploy config voor runtime/debug
Type = "oneshot"; environment.etc."flatpak/flatpaks.conf".source = lib.mkForce flatpakConfPath;
ExecStart = syncFlatpaks;
# systemd service
systemd.services.flatpak-sync = {
description = "Install Flatpak apps listed in flatpaks.conf";
wantedBy = [ "multi-user.target" ];
wants = [ "network-online.target" ];
after = [ "network-online.target" ];
serviceConfig = {
Type = "oneshot";
ExecStart = syncFlatpaks;
};
restartTriggers = [ flatpakConfPath ];
path = [
pkgs.flatpak
pkgs.coreutils
pkgs.gnugrep
pkgs.gnused
];
}; };
restartTriggers = [ flatpakConfPath ];
path = [
pkgs.flatpak
pkgs.coreutils
pkgs.gnugrep
pkgs.gnused
];
}; };
} }
+38 -14
View File
@@ -1,33 +1,57 @@
# ./modules/apps/packages.nix { config, lib, pkgs, flakeRoot, inputs, ... }:
{ lib, config, flakeRoot, ... }:
let let
packagesConfPath = "${flakeRoot}/assets/system/apps/packages.conf"; # --- Path to your packages.conf ---
packagesConfPath = "${flakeRoot}/assets/conf/apps/packages.conf";
# --- Read raw content ---
raw = builtins.readFile packagesConfPath; raw = builtins.readFile packagesConfPath;
# split lines safely # --- Split into lines explicitly on "\n" to avoid accidental char splitting ---
rawLines = lib.splitString "\n" raw; rawLines = lib.splitString "\n" raw;
# guard against accidental character splitting # --- 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;
# clean a line (remove CR, inline comments, whitespace) # --- Clean each line: remove CR, inline comments, trim ---
cleanLine = line: cleanLine = line:
let let
noCR = lib.replaceStrings [ "\r" ] [ "" ] line; noCR = lib.replaceStrings [ "\r" ] [ "" ] line;
noInlineComment = lib.head (lib.splitString "#" noCR); noComment = lib.head (lib.splitString "#" noCR);
in in
lib.strings.trim noInlineComment; lib.strings.trim noComment;
# --- Filter empty lines ---
entries = builtins.filter (l: l != "") (map cleanLine rawLines); entries = builtins.filter (l: l != "") (map cleanLine rawLines);
in { # --- Resolve a package name from pkgs ---
# --- symbolic config only --- resolvePkg = name:
mySystem.apps.packages = { let
enable = true; parts = lib.splitString "." name;
packageNames = entries; # just the names, no pkgs references 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;
# --- Map entries to actual pkgs ---
packages = builtins.seq _guard (map resolvePkg entries);
# --- Zen Browser package from inputs ---
zenBrowser =
inputs.zen-browser.packages.${pkgs.stdenv.hostPlatform.system}.default;
in
{
# --- Add the packages to systemPackages ---
environment.systemPackages = packages ++ [ zenBrowser ];
} }