Compare commits
2 Commits
f0676f9fc7
...
263f02c12a
| Author | SHA1 | Date | |
|---|---|---|---|
| 263f02c12a | |||
| 4835191bbd |
+29
-24
@@ -774,34 +774,34 @@ in {
|
|||||||
** =generated/modules/apps/flatpaks.nix=
|
** =generated/modules/apps/flatpaks.nix=
|
||||||
This will import all packages listed in ./assets/system/apps/flatpaks.conf
|
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
|
#+BEGIN_SRC nix :tangle generated/modules/apps/flatpaks.nix :noweb tangle :mkdirp yes :eval never-html
|
||||||
{ lib, ... }:
|
{ lib, pkgs, config, ... }:
|
||||||
|
|
||||||
let
|
let
|
||||||
moduleName = "install-flatpaks";
|
moduleName = "flatpaks";
|
||||||
|
|
||||||
# --- Relatief pad binnen deze module (geen flakeRoot) ---
|
# --- Path to your Flatpak list ---
|
||||||
flatpakConfPath = ./assets/system/apps/flatpaks.conf;
|
flatpakConfPath = ./assets/system/apps/flatpaks.conf;
|
||||||
|
|
||||||
# --- Lees en split het bestand ---
|
# --- Read and split file ---
|
||||||
raw = builtins.readFile flatpakConfPath;
|
raw = builtins.readFile flatpakConfPath;
|
||||||
rawLines = lib.splitString "\n" raw;
|
rawLines = lib.splitString "\n" raw;
|
||||||
|
|
||||||
# --- Guard: check dat we niet per karakter hebben gesplit ---
|
# --- Guard against splitting per character ---
|
||||||
_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;
|
||||||
|
|
||||||
# --- Cleanup per regel ---
|
# --- Clean each line ---
|
||||||
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;
|
||||||
|
|
||||||
entries = builtins.filter (l: l != "") (map cleanLine rawLines);
|
entries = builtins.filter (l: l != "") (map cleanLine rawLines);
|
||||||
|
|
||||||
# --- Validatie: min 2 dots (reverse-DNS stijl) ---
|
# --- Validate reverse-DNS style ---
|
||||||
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;
|
||||||
|
|
||||||
@@ -810,10 +810,8 @@ let
|
|||||||
if isValidId id then true
|
if isValidId id then true
|
||||||
else throw ''
|
else throw ''
|
||||||
${moduleName}: invalid Flatpak ID in flatpaks.conf (needs reverse-DNS with at least 2 dots)
|
${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 or comment them out with '#'.
|
Fix: remove stray tokens or comment them out with '#'.
|
||||||
''
|
''
|
||||||
) entries
|
) entries
|
||||||
@@ -821,12 +819,7 @@ let
|
|||||||
|
|
||||||
flatpakApps = builtins.seq _validate entries;
|
flatpakApps = builtins.seq _validate entries;
|
||||||
|
|
||||||
in
|
# --- Script to install Flatpaks ---
|
||||||
{
|
|
||||||
# --- Export as NixOS module via flake.nixosModules ---
|
|
||||||
flake.nixosModules.flatpaks = { config, pkgs, lib, ... }:
|
|
||||||
|
|
||||||
let
|
|
||||||
syncFlatpaks = pkgs.writeShellScript "sync-flatpaks" ''
|
syncFlatpaks = pkgs.writeShellScript "sync-flatpaks" ''
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
@@ -851,18 +844,31 @@ in
|
|||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
'';
|
'';
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
options.mySystem.system.flatpaks.enable = lib.mkEnableOption "Enable automatic Flatpak installation";
|
# --- Top-level toggle ---
|
||||||
|
options.enableFlatpaks = lib.mkEnableOption "Enable automatic Flatpak installation";
|
||||||
|
|
||||||
config = lib.mkIf (config.mySystem.system.flatpaks.enable or false) {
|
# --- Configuration wrapped in mkIf ---
|
||||||
|
config = lib.mkIf (config.enableFlatpaks or false) {
|
||||||
|
myApps = {
|
||||||
|
flatpaks = {
|
||||||
|
enable = true;
|
||||||
|
assetsDir = flatpakConfPath;
|
||||||
|
files = entries;
|
||||||
|
user = config.defaultUser or "henrov";
|
||||||
|
script = syncFlatpaks;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
# Enable Flatpak service
|
||||||
services.flatpak.enable = true;
|
services.flatpak.enable = true;
|
||||||
xdg.portal.enable = true;
|
xdg.portal.enable = true;
|
||||||
|
|
||||||
# Deploy de conf voor runtime/debug
|
# Deploy flatpaks.conf to /etc
|
||||||
environment.etc."flatpak/flatpaks.conf".source = lib.mkForce flatpakConfPath;
|
environment.etc."flatpak/flatpaks.conf".source = lib.mkForce flatpakConfPath;
|
||||||
|
|
||||||
# Systemd service voor automatische installatie
|
# Systemd service for auto-install
|
||||||
systemd.services.flatpak-sync = {
|
systemd.services.flatpak-sync = {
|
||||||
description = "Install Flatpak apps listed in flatpaks.conf";
|
description = "Install Flatpak apps listed in flatpaks.conf";
|
||||||
wantedBy = [ "multi-user.target" ];
|
wantedBy = [ "multi-user.target" ];
|
||||||
@@ -884,7 +890,6 @@ in
|
|||||||
];
|
];
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
|
||||||
}
|
}
|
||||||
#+END_SRC
|
#+END_SRC
|
||||||
|
|
||||||
|
|||||||
@@ -1,31 +1,31 @@
|
|||||||
{ lib, ... }:
|
{ lib, pkgs, config, ... }:
|
||||||
|
|
||||||
let
|
let
|
||||||
moduleName = "install-flatpaks";
|
moduleName = "flatpaks";
|
||||||
|
|
||||||
# --- Relatief pad binnen deze module (geen flakeRoot) ---
|
# --- Path to your Flatpak list ---
|
||||||
flatpakConfPath = ./assets/system/apps/flatpaks.conf;
|
flatpakConfPath = ./assets/system/apps/flatpaks.conf;
|
||||||
|
|
||||||
# --- Lees en split het bestand ---
|
# --- Read and split file ---
|
||||||
raw = builtins.readFile flatpakConfPath;
|
raw = builtins.readFile flatpakConfPath;
|
||||||
rawLines = lib.splitString "\n" raw;
|
rawLines = lib.splitString "\n" raw;
|
||||||
|
|
||||||
# --- Guard: check dat we niet per karakter hebben gesplit ---
|
# --- Guard against splitting per character ---
|
||||||
_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;
|
||||||
|
|
||||||
# --- Cleanup per regel ---
|
# --- Clean each line ---
|
||||||
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;
|
||||||
|
|
||||||
entries = builtins.filter (l: l != "") (map cleanLine rawLines);
|
entries = builtins.filter (l: l != "") (map cleanLine rawLines);
|
||||||
|
|
||||||
# --- Validatie: min 2 dots (reverse-DNS stijl) ---
|
# --- Validate reverse-DNS style ---
|
||||||
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;
|
||||||
|
|
||||||
@@ -34,10 +34,8 @@ let
|
|||||||
if isValidId id then true
|
if isValidId id then true
|
||||||
else throw ''
|
else throw ''
|
||||||
${moduleName}: invalid Flatpak ID in flatpaks.conf (needs reverse-DNS with at least 2 dots)
|
${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 or comment them out with '#'.
|
Fix: remove stray tokens or comment them out with '#'.
|
||||||
''
|
''
|
||||||
) entries
|
) entries
|
||||||
@@ -45,12 +43,7 @@ let
|
|||||||
|
|
||||||
flatpakApps = builtins.seq _validate entries;
|
flatpakApps = builtins.seq _validate entries;
|
||||||
|
|
||||||
in
|
# --- Script to install Flatpaks ---
|
||||||
{
|
|
||||||
# --- Export as NixOS module via flake.nixosModules ---
|
|
||||||
flake.nixosModules.flatpaks = { config, pkgs, lib, ... }:
|
|
||||||
|
|
||||||
let
|
|
||||||
syncFlatpaks = pkgs.writeShellScript "sync-flatpaks" ''
|
syncFlatpaks = pkgs.writeShellScript "sync-flatpaks" ''
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
@@ -75,18 +68,31 @@ in
|
|||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
'';
|
'';
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
options.mySystem.system.flatpaks.enable = lib.mkEnableOption "Enable automatic Flatpak installation";
|
# --- Top-level toggle ---
|
||||||
|
options.enableFlatpaks = lib.mkEnableOption "Enable automatic Flatpak installation";
|
||||||
|
|
||||||
config = lib.mkIf (config.mySystem.system.flatpaks.enable or false) {
|
# --- Configuration wrapped in mkIf ---
|
||||||
|
config = lib.mkIf (config.enableFlatpaks or false) {
|
||||||
|
myApps = {
|
||||||
|
flatpaks = {
|
||||||
|
enable = true;
|
||||||
|
assetsDir = flatpakConfPath;
|
||||||
|
files = entries;
|
||||||
|
user = config.defaultUser or "henrov";
|
||||||
|
script = syncFlatpaks;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
# Enable Flatpak service
|
||||||
services.flatpak.enable = true;
|
services.flatpak.enable = true;
|
||||||
xdg.portal.enable = true;
|
xdg.portal.enable = true;
|
||||||
|
|
||||||
# Deploy de conf voor runtime/debug
|
# Deploy flatpaks.conf to /etc
|
||||||
environment.etc."flatpak/flatpaks.conf".source = lib.mkForce flatpakConfPath;
|
environment.etc."flatpak/flatpaks.conf".source = lib.mkForce flatpakConfPath;
|
||||||
|
|
||||||
# Systemd service voor automatische installatie
|
# Systemd service for auto-install
|
||||||
systemd.services.flatpak-sync = {
|
systemd.services.flatpak-sync = {
|
||||||
description = "Install Flatpak apps listed in flatpaks.conf";
|
description = "Install Flatpak apps listed in flatpaks.conf";
|
||||||
wantedBy = [ "multi-user.target" ];
|
wantedBy = [ "multi-user.target" ];
|
||||||
@@ -108,5 +114,4 @@ in
|
|||||||
];
|
];
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user