From afab4671b8e2a30d23cecf3df12c298e1ef8efef Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Sun, 6 Jun 2021 17:20:11 -0700 Subject: [PATCH] flake: export formats as nixosModules --- flake.nix | 8 ++++++++ format-module.nix | 14 ++++++++++++++ nixos-generate.nix | 14 +------------- 3 files changed, 23 insertions(+), 13 deletions(-) create mode 100644 format-module.nix diff --git a/flake.nix b/flake.nix index 027328b..aa03ee3 100644 --- a/flake.nix +++ b/flake.nix @@ -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}"; diff --git a/format-module.nix b/format-module.nix new file mode 100644 index 0000000..083be16 --- /dev/null +++ b/format-module.nix @@ -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"; + }; + }; +} + diff --git a/nixos-generate.nix b/nixos-generate.nix index 43856cc..44bb2eb 100644 --- a/nixos-generate.nix +++ b/nixos-generate.nix @@ -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;