summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--flake.nix9
-rw-r--r--modules/flake/githubWorkflow.nix114
-rw-r--r--modules/flake/workflowLib.nix95
3 files changed, 2 insertions, 216 deletions
diff --git a/flake.nix b/flake.nix
index 4975ea5..c7d48f9 100644
--- a/flake.nix
+++ b/flake.nix
@@ -43,14 +43,9 @@
overlays.default = final: prev: (import ./pkgs final prev);
- flakeModules = {
- githubWorkflowGenerator = import ./modules/flake/githubWorkflow.nix self.flakeModules.workflowLib;
- workflowLib = import ./modules/flake/workflowLib.nix lib;
- };
-
templates = let
# string -> string -> {}
- mkTemplate = name: description: {
+ toTemplate = name: description: {
path = builtins.path {
path = ./templates/${name};
name = "${name}-template";
@@ -59,7 +54,7 @@
inherit description;
};
in
- lib.mapAttrs mkTemplate {
+ lib.mapAttrs toTemplate {
basic = "minimal boilerplate for my flakes";
full = "big template for complex flakes (using flake-parts)";
nixos = "minimal boilerplate for flake-based nixos configuration";
diff --git a/modules/flake/githubWorkflow.nix b/modules/flake/githubWorkflow.nix
deleted file mode 100644
index 923682d..0000000
--- a/modules/flake/githubWorkflow.nix
+++ /dev/null
@@ -1,114 +0,0 @@
-workflowLib': {
- config,
- lib,
- self,
- ...
-}: let
- cfg = config.githubWorkflowGenerator;
-
- inherit
- (builtins)
- attrNames
- filter
- ;
-
- inherit
- (lib)
- elem
- getAttrs
- literalExpression
- mapAttrsToList
- mdDoc
- mkIf
- mkOption
- types
- ;
-
- workflowLib = workflowLib' (
- {inherit self;}
- // mkIf (cfg.platforms != {}) {
- inherit (cfg) platforms;
- }
- );
-
- supportedOutputs = [
- "apps"
- "checks"
- "devShells"
- "darwinConfigurations"
- "homeConfigurations"
- "nixosConfigurations"
- "packages"
- ];
-
- platformMap = {
- options = {
- arch = mkOption {
- description = mdDoc "the architecture of a system";
- type = types.str;
- default = null;
- example = literalExpression "x86_64";
- };
-
- os = mkOption {
- description = mdDoc "the name of an os supported by github runners";
- type = types.str;
- default = null;
- example = literalExpression "ubuntu-latest";
- };
- };
- };
-
- overrides = {
- options = {
- systems = mkOption {
- description = mdDoc "list of systems to build an output for";
- type = types.listOf types.str;
- default = builtins.attrNames cfg.platforms;
- };
- };
- };
-in {
- options = {
- githubWorkflowGenerator = {
- outputs = mkOption {
- description = mdDoc "outputs to include in workflow";
- type = types.listOf types.str;
- default = filter (output: elem output supportedOutputs) (attrNames self);
- };
-
- platforms = mkOption {
- description = mdDoc ''
- an attrset that can map a nix system to an architecture and os supported by github
- '';
- type = types.attrsOf (types.submodule platformMap);
- default = {};
- };
-
- overrides = mkOption {
- description = mdDoc "overrides for mkMatrix args";
- type = types.attrsOf (types.submodule overrides);
- default = {};
- example = literalExpression ''
- {
- githubWorkflowGenerator.overrides = {
- checks.systems = [ "x86_64-linux" ];
- };
- }
- '';
- };
- };
- };
-
- config.flake = {
- githubWorkflow = {
- matrix.include = lib.concatLists (
- mapAttrsToList (
- output: _:
- workflowLib.mkMatrix ({inherit output;} // cfg.overrides.${output} or {})
- )
- (getAttrs cfg.outputs self)
- );
- };
- };
-}
diff --git a/modules/flake/workflowLib.nix b/modules/flake/workflowLib.nix
deleted file mode 100644
index d8cc4c4..0000000
--- a/modules/flake/workflowLib.nix
+++ /dev/null
@@ -1,95 +0,0 @@
-lib: {
- self,
- platforms ? {
- "x86_64-linux" = {
- os = "ubuntu-latest";
- arch = "x64";
- };
-
- "aarch64-linux" = {
- os = "ubuntu-latest";
- arch = "aarch64";
- };
-
- "x86_64-darwin" = {
- os = "macos-latest";
- arch = "x64";
- };
- },
- ...
-}: let
- inherit
- (lib)
- flatten
- getAttrs
- mapAttrsToList
- warn
- ;
-
- platforms' =
- platforms
- // {
- fallback = warn "an output in the job matrix is not supported!" {
- os = null;
- arch = null;
- };
- };
-
- mkMatrixMulti = systems: output:
- flatten (
- mapAttrsToList (
- system:
- mapAttrsToList (
- attr: _: {
- inherit (platforms'.${system} or platforms'.fallback) arch os;
- attr = "${output}.${system}.${attr}";
- }
- )
- )
- (getAttrs systems self.${output})
- );
-
- mkMatrixFlat = {
- output,
- suffix ? "",
- }:
- mapAttrsToList (
- attr: deriv: {
- inherit (platforms'.${deriv.pkgs.system} or platforms'.fallback) os arch;
- attr = "${output}.${attr}${suffix}";
- }
- )
- self.${output};
-
- mkMatrixSystem = output:
- mkMatrixFlat {
- inherit output;
- suffix = ".config.system.build.toplevel";
- };
-
- mkMatrixUser = mkMatrixFlat {
- output = "homeConfigurations";
- suffix = ".activationPackage";
- };
-in {
- inherit
- mkMatrixMulti
- mkMatrixFlat
- mkMatrixSystem
- mkMatrixUser
- ;
-
- platforms = platforms';
-
- mkMatrix = {
- output,
- systems ? (builtins.attrNames platforms),
- }:
- {
- "nixosConfigurations" = mkMatrixSystem output;
- "darwinConfigurations" = mkMatrixSystem output;
- "homeConfigurations" = mkMatrixUser;
- }
- .${output}
- or (mkMatrixMulti systems output);
-}