Skip to content

Commit

Permalink
Move all flake creation logic to lib as mkDevos and use evalDevosArgs
Browse files Browse the repository at this point in the history
  • Loading branch information
Pacman99 committed Mar 24, 2021
1 parent 5e8ebea commit 01d4eb2
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 63 deletions.
69 changes: 6 additions & 63 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -28,68 +28,11 @@
pkgs.inputs.nixpkgs.follows = "nixos";
};

outputs = inputs@{ deploy, nixos, nur, self, utils, ... }:
let
inherit (self) lib;
inherit (lib) os;

extern = import ./extern { inherit inputs; };

multiPkgs = os.mkPkgs;

outputs = {
nixosConfigurations =
import ./hosts (nixos.lib.recursiveUpdate inputs {
inherit multiPkgs extern;
defaultSystem = "x86_64-linux";
lib = nixos.lib.extend (final: prev: {
dev = self.lib;
});
});

homeConfigurations = os.mkHomeConfigurations;

nixosModules =
let moduleList = import ./modules/module-list.nix;
in lib.pathsToImportedAttrs moduleList;

homeModules =
let moduleList = import ./users/modules/module-list.nix;
in lib.pathsToImportedAttrs moduleList;

overlay = import ./pkgs;
overlays = lib.pathsToImportedAttrs (lib.pathsIn ./overlays);

lib = import ./lib { inherit nixos self inputs; };

templates.flk.path = ./.;
templates.flk.description = "flk template";
defaultTemplate = self.templates.flk;

deploy.nodes = os.mkNodes deploy self.nixosConfigurations;
outputs = inputs@{ deploy, nixos, nur, self, utils, ... }:
let
lib = import ./lib { inherit self nixos inputs; };
in
lib.mkDevos {
inherit self;
};

systemOutputs = utils.lib.eachDefaultSystem (system:
let pkgs = multiPkgs.${system}; in
{
checks =
let
tests = nixos.lib.optionalAttrs (system == "x86_64-linux")
(import ./tests { inherit self pkgs; });
deployHosts = nixos.lib.filterAttrs
(n: _: self.nixosConfigurations.${n}.config.nixpkgs.system == system) self.deploy.nodes;
deployChecks = deploy.lib.${system}.deployChecks { nodes = deployHosts; };
in
nixos.lib.recursiveUpdate tests deployChecks;

packages = utils.lib.flattenTreeSystem system
(os.mkPackages { inherit pkgs; });

devShell = import ./shell {
inherit self system;
};
}
);
in
nixos.lib.recursiveUpdate outputs systemOutputs;
}
1 change: 1 addition & 0 deletions lib/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ lib.makeExtensible (final:
lists = callLibs ./lists.nix;
strings = callLibs ./strings.nix;

inherit (os) mkDevos;
inherit (attrs) mapFilterAttrs genAttrs' pathsToImportedAttrs concatAttrs;
inherit (lists) pathsIn;
inherit (strings) rgxToString;
Expand Down
2 changes: 2 additions & 0 deletions lib/devos/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

evalDevosArgs = dev.callLibs ./evalDevosArgs.nix;

mkDevos = dev.callLibs ./mkDevos.nix;

mkNodes = dev.callLibs ./mkNodes.nix;

mkHosts = dev.callLibs ./mkHosts.nix;
Expand Down
64 changes: 64 additions & 0 deletions lib/devos/mkDevos.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
{ self, nixos, inputs, ... }:
let
devos = self;
in

{ ... } @ args:
let
inherit (self) lib;
inherit (lib) os;

inherit (inputs) utils deploy;

cfg = os.evalDevosArgs { inherit args; };

multiPkgs = os.mkPkgs { inherit (cfg) extern overrides; };

outputs = {
nixosConfigurations = os.mkHosts {
inherit multiPkgs;
inherit (cfg) extern suites overrides;
dir = cfg.hosts;
};

homeConfigurations = os.mkHomeConfigurations;

nixosModules = cfg.modules;

homeModules = cfg.userModules;

overlay = cfg.packages;
inherit (cfg) overlays;

lib = import "${devos}/lib" { inherit self nixos inputs; };

templates.flk.path = builtins.toPath self;
templates.flk.description = "flk template";
defaultTemplate = self.templates.flk;

deploy.nodes = os.mkNodes deploy self.nixosConfigurations;
};

systemOutputs = utils.lib.eachDefaultSystem (system:
let pkgs = multiPkgs.${system}; in
{
checks =
let
tests = nixos.lib.optionalAttrs (system == "x86_64-linux")
(import "${devos}/tests" { inherit self pkgs; });
deployHosts = nixos.lib.filterAttrs
(n: _: self.nixosConfigurations.${n}.config.nixpkgs.system == system) self.deploy.nodes;
deployChecks = deploy.lib.${system}.deployChecks { nodes = deployHosts; };
in
nixos.lib.recursiveUpdate tests deployChecks;

packages = utils.lib.flattenTreeSystem system
(os.mkPackages { inherit pkgs; });

devShell = import "${devos}/shell" {
inherit self pkgs system;
};
});
in
nixos.lib.recursiveUpdate outputs systemOutputs

0 comments on commit 01d4eb2

Please sign in to comment.