From a5e0fea1ea43715d906f8f128fd65b07ce60063f Mon Sep 17 00:00:00 2001 From: Daylin Morgan Date: Mon, 6 Jan 2025 16:46:07 -0600 Subject: [PATCH] add package helper --- hosts/othalan/pkgs.nix | 22 ---------------------- hosts/othalan/settings/pkgs | 10 ++++++++++ lib/extended.nix | 31 +++++++++++++++++++++++++++++++ modules/oizys.nix | 4 +++- 4 files changed, 44 insertions(+), 23 deletions(-) delete mode 100644 hosts/othalan/pkgs.nix create mode 100644 hosts/othalan/settings/pkgs diff --git a/hosts/othalan/pkgs.nix b/hosts/othalan/pkgs.nix deleted file mode 100644 index e021405..0000000 --- a/hosts/othalan/pkgs.nix +++ /dev/null @@ -1,22 +0,0 @@ -{ pkgs, flake, ... }: -{ - environment.systemPackages = - [ - (flake.pkg "utils") - (flake.pkg "ghostty") - ] - ++ (with pkgs; [ - sops - attic-client - - distrobox - # cachix - zk - - graphviz - charm-freeze - - quarto - calibre - ]); -} diff --git a/hosts/othalan/settings/pkgs b/hosts/othalan/settings/pkgs new file mode 100644 index 0000000..00555e4 --- /dev/null +++ b/hosts/othalan/settings/pkgs @@ -0,0 +1,10 @@ +flake:utils +flake:ghostty +sops +attic-client +distrobox +zk +graphviz +charm-freeze +quarto +calibre diff --git a/lib/extended.nix b/lib/extended.nix index 8b48273..a700edc 100644 --- a/lib/extended.nix +++ b/lib/extended.nix @@ -21,6 +21,7 @@ let types hasPrefix splitString + removePrefix trim ; inherit (final.filesystem) listFilesRecursive; @@ -147,6 +148,35 @@ let // (tryreadEnabledAttrsOrEmpty "${p}/settings/modules") ); + # convert the following: + # ```txt + # flake:utils + # sops + # graphviz + # ``` + # to + # ```nix + # [ + # (flake.pkg "utils") + # pkgs.sops + # pkgs.graphviz + # ] + # ``` + tryPkgsFromFile = + { + hostName, + pkgs, + flake ? flakeFromSystem "x86_64-linux", + }: + hostName + |> pathFromHostName + |> (p: "${p}/settings/pkgs") + |> tryReadLinesNoComment + |> map ( + line: + if hasPrefix "flake:" line then (line |> removePrefix "flake:" |> flake.pkgs) else pkgs.${line} + ); + in { inherit @@ -169,5 +199,6 @@ in loadOverlays hostFiles oizysSettings + tryPkgsFromFile ; } diff --git a/modules/oizys.nix b/modules/oizys.nix index e26750d..63616f5 100644 --- a/modules/oizys.nix +++ b/modules/oizys.nix @@ -3,10 +3,11 @@ lib, self, hostName, + pkgs, ... }: let - inherit (lib) mkEnableOption mkOption loadOverlays oizysSettings; + inherit (lib) mkEnableOption mkOption loadOverlays oizysSettings tryPkgsFromFile; in { imports = with self.nixosModules; [ @@ -61,5 +62,6 @@ in time.timeZone = "US/Central"; nixpkgs.overlays = import ../overlays { inherit inputs loadOverlays; }; oizys = oizysSettings hostName; + environment.systemPackages = tryPkgsFromFile {inherit hostName pkgs;}; }; }