diff --git a/flake.nix b/flake.nix index 4f175e7..675460d 100644 --- a/flake.nix +++ b/flake.nix @@ -166,32 +166,17 @@ ); in { - inherit (self) outputs; + inherit (self) outputs; # for hydra + inherit lib; # for allowing use of custom functions in nix repl hydraJobs = import ./hydra/jobs.nix { inherit inputs outputs; }; formatter = forEachSystem (system: nixpkgs.legacyPackages.${system}.nixfmt-rfc-style); nixosConfigurations = let - constructSystem = lib.rad-dev.systems.constructSystem; + genSystems = lib.rad-dev.systems.genSystems; in - (builtins.listToAttrs ( - map (system: { - name = system; - value = constructSystem ( - { - inherit inputs src; - hostname = system; - } - // builtins.removeAttrs (import ./systems/${system} { inherit inputs; }) [ - "hostname" - "server" - "home" - ] - ); - }) (lib.rad-dev.lsdir src "systems") - - )); + genSystems inputs src (src + "/systems"); devShell = lib.mapAttrs ( system: sopsPkgs: diff --git a/lib/default.nix b/lib/default.nix index 484fb03..43e9790 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -31,7 +31,7 @@ # # type: # ls :: Path -> String -> [String] - ls = base: dir: lib.attrNames (builtins.readDir (base + "/${dir}")); + ls = dir: lib.attrNames (builtins.readDir dir); # gets list of directories inside of a given directory # @@ -42,11 +42,9 @@ # 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}")) - )) + dir: + if (builtins.pathExists (dir)) then + (lib.attrNames (lib.filterAttrs (path: type: type == "directory") (builtins.readDir (dir)))) else [ ]; @@ -58,6 +56,6 @@ # # type: # fileList :: Path -> String -> [Path] - fileList = base: dir: map (file: base + "/${dir}/${file}") (ls base dir); + fileList = dir: map (file: dir + "/${file}") (ls dir); }; } diff --git a/lib/systems.nix b/lib/systems.nix index de73c11..e38fd9e 100644 --- a/lib/systems.nix +++ b/lib/systems.nix @@ -28,32 +28,33 @@ rec { }; }) users); - genUsers = - { users, src, ... }: - (map ( - user: - { - config, - lib, - pkgs, - ... - }@args: - { - users.users.${user} = import (src + "/users/${user}") (args // { name = user; }); - } - ) users); + importUser = + user: src: + { + config, + lib, + pkgs, + ... + }@args: + { + users.users.${user} = import (src + "/users/${user}") (args // { name = user; }); + }; + + genUsers = { users, src, ... }: (map (user: importUser user src) users); + + genNonX86 = + { ... }: + { + config.nixpkgs = { + config.allowUnsupportedSystem = true; + buildPlatform = "x86_64-linux"; + }; + }; genWrapper = var: func: args: lib.optionals var (func args); - nonX86 = { - config.nixpkgs = { - config.allowUnsupportedSystem = true; - buildPlatform = "x86_64-linux"; - }; - }; - constructSystem = { hostname, @@ -80,9 +81,25 @@ rec { (src + "/systems/${hostname}/configuration.nix") ] ++ modules - ++ (lib.rad-dev.fileList src "modules") + ++ (lib.rad-dev.fileList (src + "/modules")) ++ genWrapper sops genSops args ++ genWrapper home genHome args - ++ genWrapper true genUsers args; + ++ genWrapper true genUsers args + ++ genWrapper (system != "x86_64-linux") genNonX86 args; }; + + genSystems = + inputs: src: path: + builtins.listToAttrs ( + map (name: { + inherit name; + value = constructSystem ( + { + inherit inputs src; + hostname = name; + } + // import (path + "/${name}") { inherit inputs; } + ); + }) (lib.rad-dev.lsdir path) + ); }