flake: export formats as nixosModules

This commit is contained in:
Pacman99 2021-06-06 17:20:11 -07:00
parent 23143c87be
commit afab4671b8
3 changed files with 23 additions and 13 deletions

View File

@ -6,6 +6,14 @@
outputs = { self, nixpkgs }: let
forAllSystems = nixpkgs.lib.genAttrs [ "x86_64-linux" "x86_64-darwin" "i686-linux" "aarch64-linux" ];
in {
# export all generator formats in ./formats
nixosModules = nixpkgs.lib.mapAttrs' (file: _: {
name = nixpkgs.lib.removeSuffix ".nix" file;
# The exported module should include the internal format* options
value.imports = [ (./formats + "/${file}") ./format-module.nix ];
}) (builtins.readDir ./formats);
# Packages
packages = forAllSystems (system: let
pkgs = nixpkgs.legacyPackages."${system}";

14
format-module.nix Normal file
View File

@ -0,0 +1,14 @@
{ lib, ... }: {
options = {
filename = lib.mkOption {
type = lib.types.str;
description = "Declare the path of the wanted file in the output directory";
default = "*";
};
formatAttr = lib.mkOption {
type = lib.types.str;
description = "Declare the default attribute to build";
};
};
}

View File

@ -8,19 +8,7 @@
, flakeAttr ? null
}:
let
module = { lib, ... }: {
options = {
filename = lib.mkOption {
type = lib.types.str;
description = "Declare the path of the wanted file in the output directory";
default = "*";
};
formatAttr = lib.mkOption {
type = lib.types.str;
description = "Declare the default attribute to build";
};
};
};
module = import ./format-module.nix;
# Will only get evaluated when used, so no worries
flake = builtins.getFlake flakeUri;