From e495c7d8bb8dc538598f893b5f1b76d680d1b156 Mon Sep 17 00:00:00 2001 From: Daylin Morgan Date: Mon, 6 Jan 2025 15:29:31 -0600 Subject: [PATCH] custom oizys settings files --- hosts/othalan/default.nix | 40 +++++----------------------------- hosts/othalan/pkgs.nix | 2 -- hosts/othalan/settings/modules | 11 ++++++++++ lib/extended.nix | 30 +++++++++++++++++++++++++ lib/generators.nix | 16 +++++++------- modules/oizys.nix | 3 ++- 6 files changed, 56 insertions(+), 46 deletions(-) create mode 100644 hosts/othalan/settings/modules diff --git a/hosts/othalan/default.nix b/hosts/othalan/default.nix index 248432c..24f6e67 100644 --- a/hosts/othalan/default.nix +++ b/hosts/othalan/default.nix @@ -1,44 +1,14 @@ { - lib, enabled, - enableAttrs, - listify, config, ... }: - -let - inherit (lib.strings) hasPrefix splitString; - inherit (builtins) readFile filter; - readLanguageSettings = f: f |> readFile |> splitString "\n" |> filter (line: !(hasPrefix "#" line)); -in { - - oizys = - { - nix-ld = enabled // { - overkill = enabled; - }; - languages = readLanguageSettings ./settings/languages; - # languages = "misc|nim|node|nushell|python|tex|typst" |> listify; - } - // ( - '' - desktop - hp-scanner - hyprland - chrome - vpn - backups - llm - vbox - podman - docker - utils - '' - |> listify - |> enableAttrs - ); + oizys = { + nix-ld = enabled // { + overkill = enabled; + }; + }; sops = { defaultSopsFile = ./secrets.yaml; diff --git a/hosts/othalan/pkgs.nix b/hosts/othalan/pkgs.nix index 34da100..e021405 100644 --- a/hosts/othalan/pkgs.nix +++ b/hosts/othalan/pkgs.nix @@ -10,7 +10,6 @@ attic-client distrobox - # cachix zk @@ -18,7 +17,6 @@ charm-freeze quarto - calibre ]); } diff --git a/hosts/othalan/settings/modules b/hosts/othalan/settings/modules new file mode 100644 index 0000000..ed49711 --- /dev/null +++ b/hosts/othalan/settings/modules @@ -0,0 +1,11 @@ +backups +chrome +desktop +docker +hp-scanner +hyprland +llm +podman +utils +vbox +vpn diff --git a/lib/extended.nix b/lib/extended.nix index 9b5d59a..8b48273 100644 --- a/lib/extended.nix +++ b/lib/extended.nix @@ -8,6 +8,9 @@ let filter attrNames readDir + readFile + pathExists + length ; inherit (final) concatStringsSep @@ -16,6 +19,7 @@ let mkIf mkOption types + hasPrefix splitString trim ; @@ -119,6 +123,30 @@ let |> filter (f: f != "default.nix") |> map (f: import (../overlays + "/${f}") { inherit inputs; }); + readLinesNoComment = + f: f |> readFile |> splitString "\n" |> filter (line: !(hasPrefix "#" line) && line != ""); + + pathFromHostName = host: ../. + "/hosts/${host}"; + hostFiles = host: host |> pathFromHostName |> listFilesRecursive |> filter isNixFile; + + # if the specified path doesn't exist returns an empty array + tryReadLinesNoComment = f: if pathExists f then (readLinesNoComment f) else [ ]; + + tryreadEnabledAttrsOrEmpty = + p: p |> tryReadLinesNoComment |> (lines: if (length lines) > 0 then lines |> enableAttrs else { }); + + oizysSettings = + hostName: + hostName + |> pathFromHostName + |> ( + p: + { + languages = tryReadLinesNoComment "${p}/settings/languages"; + } + // (tryreadEnabledAttrsOrEmpty "${p}/settings/modules") + ); + in { inherit @@ -139,5 +167,7 @@ in flakeFromSystem listify loadOverlays + hostFiles + oizysSettings ; } diff --git a/lib/generators.nix b/lib/generators.nix index 67a3a92..758b06a 100644 --- a/lib/generators.nix +++ b/lib/generators.nix @@ -12,19 +12,17 @@ let mkOizysModule enabled enableAttrs - isNixFile flakeFromSystem listify + readSettings + hostFiles ; - inherit (lib.filesystem) listFilesRecursive; flake = flakeFromSystem "x86_64-linux"; - hostPath = host: ../. + "/hosts/${host}"; - - hostFiles = host: host |> hostPath |> listFilesRecursive |> filter isNixFile; - nixosModules = names: names |> listify |> map (n: inputs.${n}.nixosModules.default); selfModules = names: names |> listify |> map (n: self.nixosModules.${n}); + # generate anonymous module to set oizys settings from existing plaintext files + commonSpecialArgs = { inherit self @@ -45,19 +43,21 @@ let nixosSystem { system = "x86_64-linux"; modules = - [] + [ + ] ++ (selfModules ''oizys'') ++ (nixosModules ''lix-module|sops-nix'') ++ (hostFiles hostName); specialArgs = commonSpecialArgs // { inherit + flake mkDefaultOizysModule mkOizysModule listify enableAttrs hostName - flake + readSettings ; }; }; diff --git a/modules/oizys.nix b/modules/oizys.nix index 9033f7b..e26750d 100644 --- a/modules/oizys.nix +++ b/modules/oizys.nix @@ -6,7 +6,7 @@ ... }: let - inherit (lib) mkEnableOption mkOption loadOverlays; + inherit (lib) mkEnableOption mkOption loadOverlays oizysSettings; in { imports = with self.nixosModules; [ @@ -60,5 +60,6 @@ in networking.hostName = hostName; time.timeZone = "US/Central"; nixpkgs.overlays = import ../overlays { inherit inputs loadOverlays; }; + oizys = oizysSettings hostName; }; }