From 5261a65ecc7da3ce588a4102eec220c9d6aaa35c Mon Sep 17 00:00:00 2001 From: ahuston-0 Date: Thu, 16 May 2024 11:39:01 -0400 Subject: [PATCH] migrate lib functions to lib/, remove extra overlays Signed-off-by: ahuston-0 --- flake.nix | 56 +++++++++++++------------------------------ lib/default.nix | 61 +++++++++++++++++++++++++++++++++++++++++++++++ utils/default.nix | 21 ---------------- 3 files changed, 78 insertions(+), 60 deletions(-) create mode 100644 lib/default.nix delete mode 100644 utils/default.nix diff --git a/flake.nix b/flake.nix index 955ef2f..4c0a4d0 100644 --- a/flake.nix +++ b/flake.nix @@ -125,7 +125,6 @@ }@inputs: let - inherit (nixpkgs) lib; inherit (self) outputs; systems = [ "x86_64-linux" @@ -133,35 +132,14 @@ ]; forEachSystem = lib.genAttrs systems; - overlayList = [ - #self.overlays.default - nix.overlays.default - ]; - pkgsBySystem = forEachSystem ( - system: - import nixpkgs { - inherit system; - overlays = overlayList; - config = { - allowUnfree = true; - isHydra = true; - }; - } - ); + # filter out all non-nix files and returns the nix-store path + # (ie. git configs, git refs, etc) + # + # used for module imports and system search src = builtins.filterSource ( path: type: type == "directory" || lib.hasSuffix ".nix" (baseNameOf path) ) ./.; - ls = dir: lib.attrNames (builtins.readDir (src + "/${dir}")); - lsdir = - dir: - if (builtins.pathExists (src + "/${dir}")) then - (lib.attrNames ( - lib.filterAttrs (path: type: type == "directory") (builtins.readDir (src + "/${dir}")) - )) - else - [ ]; - fileList = dir: map (file: ./. + "/${dir}/${file}") (ls dir); config = { repos = [ @@ -179,22 +157,21 @@ } ]; }; - in - { - inherit (self) outputs; - hydraJobs = import ./hydra/jobs.nix { inherit inputs outputs; }; - - formatter = forEachSystem (system: nixpkgs.legacyPackages.${system}.nixfmt-rfc-style); # adds our lib functions to lib namespace lib = nixpkgs.lib.extend ( - self: super: { - my = import ./lib { - inherit nixpkgs inputs; - lib = self; - }; + self: super: + import ./lib { + inherit nixpkgs inputs; + lib = self; } ); + in + { + inherit (self) outputs; + + hydraJobs = import ./hydra/jobs.nix { inherit inputs outputs; }; + formatter = forEachSystem (system: nixpkgs.legacyPackages.${system}.nixfmt-rfc-style); nixosConfigurations = let @@ -220,7 +197,7 @@ ./systems/${hostname}/hardware.nix ./systems/${hostname}/configuration.nix ] - ++ fileList "modules" + ++ (lib.rad-dev.fileList src "modules") ++ modules ++ lib.optional home home-manager.nixosModules.home-manager ++ ( @@ -271,7 +248,8 @@ "home" ] ); - }) (lsdir "systems") + }) (lib.rad-dev.lsdir src "systems") + )); devShell = lib.mapAttrs ( diff --git a/lib/default.nix b/lib/default.nix new file mode 100644 index 0000000..62d5158 --- /dev/null +++ b/lib/default.nix @@ -0,0 +1,61 @@ +{ lib, ... }: +{ + # create rad-dev namespace for lib + rad-dev = rec { + # any(), but checks if any value in the list is true + # + # args: + # n: list of booleans + # + # type: + # anyBool:: [bool] -> bool + anyBool = lib.any (n: n); + + # pulls a value out of an attrset and converts it to a list + # + # args: + # attr: attribute to search for in an attrset + # set: attrset to search + # + # type: + # mapGetAttr :: String -> Attrset -> [Any] + mapGetAttr = (attr: set: lib.mapAttrsToList (_: attrset: lib.getAttr attr attrset) set); + + # gets list of files and directories inside of a directory + # + # args: + # base: base path to search + # dir: directory to get files from + # + # type: + # ls :: Path -> String -> [String] + ls = base: dir: lib.attrNames (builtins.readDir (base + "/${dir}")); + + # gets list of directories inside of a given directory + # + # args: + # base: base path to search + # dir: directory to get files from + # + # type: + # lsdir :: Path -> String -> [String] + lsdir = + base: dir: + if (builtins.pathExists (base + "/${dir}")) then + (lib.attrNames ( + lib.filterAttrs (path: type: type == "directory") (builtins.readDir (base + "/${dir}")) + )) + else + [ ]; + + # return full paths of all files in a directory + # + # args: + # base: base path to search + # dir: path to get files from + # + # type: + # fileList :: Path -> String -> [Path] + fileList = base: dir: map (file: base + "/${dir}/${file}") (ls base dir); + }; +} diff --git a/utils/default.nix b/utils/default.nix deleted file mode 100644 index 819d6d5..0000000 --- a/utils/default.nix +++ /dev/null @@ -1,21 +0,0 @@ -{ - config, - lib, - pkgs, - ... -}: - -{ - # create rad-dev namespace for lib - rad-dev = { - # any(), but checks if any value in the list is true - # type: - # anyBool:: [bool] -> bool - anyBool = lib.any (n: n); - - # pulls a value out of an attrset and converts it to a list - # type: - # mapGetAttr :: String -> Attrset -> [Any] - mapGetAttr = (attr: set: lib.mapAttrsToList (_: attrset: lib.getAttr attr attrset) set); - }; -}