From f3b7a6a33588ad425de02c4b841df19f30733e44 Mon Sep 17 00:00:00 2001 From: Collin Williams <96917990+bluedragon1221@users.noreply.github.com> Date: Mon, 9 Jun 2025 19:43:34 +0000 Subject: reorganize programs, move functions to library, and remove the rest of hyprland (all sway now) --- lib/cfgWrapper.nix | 63 --------------------------------------------- lib/lib.nix | 52 +++++++++++++++++++++++++++++++++++++ lib/nix-furnace/default.nix | 31 +++++----------------- 3 files changed, 58 insertions(+), 88 deletions(-) delete mode 100644 lib/cfgWrapper.nix create mode 100644 lib/lib.nix (limited to 'lib') diff --git a/lib/cfgWrapper.nix b/lib/cfgWrapper.nix deleted file mode 100644 index 2e57656..0000000 --- a/lib/cfgWrapper.nix +++ /dev/null @@ -1,63 +0,0 @@ -{pkgs}: { - pkg, - binName ? pkg.meta.mainProgram, - extraFlags ? [], - extraWrapperFlags ? [], - extraPkgs ? [], - extraEnv ? {}, - postBuild ? "", - hidePkgs ? false, - reducePath ? false, -}: let - extraFlagsArgs = pkgs.lib.pipe extraFlags [ - (builtins.map (x: ''--add-flags "${x}" '')) - (builtins.concatStringsSep " ") - ]; - - extraWrapperFlagsArgs = builtins.concatStringsSep " " extraWrapperFlags; - - pathArg = - if (extraPkgs != []) - then ''--prefix PATH : "${pkgs.lib.makeBinPath extraPkgs}"'' - else ""; - - # Looks like { - # VAR = "value"; - # VAR2 = "value_again"; - # } - envArgs = pkgs.lib.pipe extraEnv [ - (builtins.mapAttrs (k: v: ''--set ${k} "${v}"'')) - builtins.attrValues - (builtins.concatStringsSep " ") - ]; - - extraPkgs2 = - if reducePath - then - (pkgs.symlinkJoin { - name = "${binName}-extra-pkgs"; - paths = extraPkgs; - }) - else extraPkgs; - - wrapped-program = pkgs.symlinkJoin { - name = "${binName}-wrapped-program"; - paths = [pkg] ++ extraPkgs2; - - buildInputs = [pkgs.makeWrapper]; - postBuild = '' - ${postBuild} - - wrapProgram $out/bin/${binName} ${extraFlagsArgs} ${pathArg} ${envArgs} ${extraWrapperFlagsArgs} - ''; - }; -in - if hidePkgs - then - (pkgs.linkFarm "${binName}-only-bin" [ - { - name = "bin/${binName}"; - path = "${wrapped-program}/bin/${binName}"; - } - ]) - else wrapped-program diff --git a/lib/lib.nix b/lib/lib.nix new file mode 100644 index 0000000..5310a6d --- /dev/null +++ b/lib/lib.nix @@ -0,0 +1,52 @@ +let + optionalAttrs = cond: as: + if cond + then as + else {}; + + mkIfNull = cond: as: + if cond + then as + else null; + + globimport = { + lazyImport = path: optionalAttrs (builtins.pathExists path) (import path); + + getSubdirs = dir: + builtins.filter (x: x != null) + (builtins.attrValues + (builtins.mapAttrs + (name: value: mkIfNull (value == "directory") name) + (builtins.readDir dir))); + + getSubfiles = dir: + builtins.filter (x: x != null) + (builtins.attrValues + (builtins.mapAttrs + (name: value: mkIfNull (value == "file") name) + (builtins.readDir dir))); + }; + + options = { + lib, + config, + }: let + inherit (lib) mkOption mkEnableOption; + mkProgramOption' = name: extraOpts: + { + enable = mkEnableOption "whether to enable ${name}"; + theme = mkOption { + type = lib.types.enum ["catppuccin" "adwaita"]; + default = config.collinux.terminal.theme; + }; + } + // extraOpts; + + mkProgramOption = name: mkProgramOption' name {}; + in { + inherit mkProgramOption' mkProgramOption; + }; +in { + inherit globimport; + inherit options; +} diff --git a/lib/nix-furnace/default.nix b/lib/nix-furnace/default.nix index 7c18ae9..303730e 100644 --- a/lib/nix-furnace/default.nix +++ b/lib/nix-furnace/default.nix @@ -1,27 +1,6 @@ let - lazyImport = path: - if (builtins.pathExists path) - then import path - else {}; - - mkIfNull = cond: onTrue: - if cond - then onTrue - else null; - - getSubdirs = dir: - builtins.filter (x: x != null) - (builtins.attrValues - (builtins.mapAttrs - (name: value: mkIfNull (value == "directory") name) - (builtins.readDir dir))); - - getSubfiles = dir: - builtins.filter (x: x != null) - (builtins.attrValues - (builtins.mapAttrs - (name: value: mkIfNull (value == "file") name) - (builtins.readDir dir))); + my-lib = import ../lib.nix; + inherit (my-lib.globimport) lazyImport getSubdirs getSubfiles; mkHomeImports = modName: [ (lazyImport ../../modules/${modName}/options.nix) @@ -65,9 +44,11 @@ let }; }; }; + + specialArgs = {inherit inputs my-lib;}; in inputs.nixpkgs.lib.nixosSystem { - specialArgs = {inherit inputs;}; + inherit specialArgs; modules = [ {networking.hostName = hostname;} @@ -85,7 +66,7 @@ let backupFileExtension = "bak"; useGlobalPkgs = true; useUserPackages = true; - extraSpecialArgs = {inherit inputs;}; + extraSpecialArgs = specialArgs; users."${username}" = { imports = [ -- cgit v1.3.1