diff --git a/dev/default.nix b/dev/default.nix
index 6af149b..d6d28a4 100644
--- a/dev/default.nix
+++ b/dev/default.nix
@@ -1,6 +1,6 @@
let
flake = builtins.getFlake (toString ./.);
- fmc-lib = import ../lib.nix { inherit (flake.inputs.nixpkgs) lib; };
+ fmc-lib = (builtins.getFlake (toString ../.)).lib;
self = {
inherit (flake) inputs;
outPath = ../.; # used by pre-commit module, etc
diff --git a/lib.nix b/lib.nix
index 0d728f3..2d38daa 100644
--- a/lib.nix
+++ b/lib.nix
@@ -98,6 +98,34 @@ let
type = flake-parts-lib.mkPerSystemType module;
};
+ # Helper function for defining a per-system option that
+ # gets transposed by the usual flake system logic to a
+ # top-level flake attribute.
+ mkTransposedPerSystemModule = { name, option, file }: {
+ _file = file;
+
+ options = {
+ flake = flake-parts-lib.mkSubmoduleOptions {
+ ${name} = mkOption {
+ type = types.lazyAttrsOf option.type;
+ default = { };
+ description = lib.mdDoc ''
+ See {option}`perSystem.${name}` for description and examples.
+ '';
+ };
+ };
+
+ perSystem = flake-parts-lib.mkPerSystemOption {
+ _file = file;
+
+ options.${name} = option;
+ };
+ };
+
+ config = {
+ transposition.${name} = { };
+ };
+ };
};
in
diff --git a/modules/apps.nix b/modules/apps.nix
index e411fd6..a3f8219 100644
--- a/modules/apps.nix
+++ b/modules/apps.nix
@@ -1,15 +1,11 @@
{ config, lib, flake-parts-lib, ... }:
let
inherit (lib)
- filterAttrs
- mapAttrs
mkOption
- optionalAttrs
types
;
inherit (flake-parts-lib)
- mkSubmoduleOptions
- mkPerSystemOption
+ mkTransposedPerSystemModule
;
programType = lib.types.coercedTo derivationType getExe lib.types.str;
@@ -44,43 +40,19 @@ let
};
};
in
-{
- options = {
- flake = mkSubmoduleOptions {
- apps = mkOption {
- type = types.lazyAttrsOf (types.lazyAttrsOf appType);
- default = { };
- description = ''
- Programs runnable with nix run .#<name>.
- '';
- example = lib.literalExpression or lib.literalExample ''
- {
- x86_64-linux.default.program = "''${config.packages.hello}/bin/hello";
- }
- '';
- };
- };
-
- perSystem = mkPerSystemOption
- ({ config, system, ... }: {
- options = {
- apps = mkOption {
- type = types.lazyAttrsOf appType;
- default = { };
- description = ''
- Programs runnable with nix run .#<name>.
- '';
- example = lib.literalExpression or lib.literalExample ''
- {
- default.program = "''${config.packages.hello}/bin/hello";
- }
- '';
- };
- };
- });
-
- };
- config = {
- transposition.apps = { };
+mkTransposedPerSystemModule {
+ name = "apps";
+ option = mkOption {
+ type = types.lazyAttrsOf appType;
+ default = { };
+ description = ''
+ Programs runnable with nix run .#<name>.
+ '';
+ example = lib.literalExpression or lib.literalExample ''
+ {
+ default.program = "''${config.packages.hello}/bin/hello";
+ }
+ '';
};
+ file = ./apps.nix;
}
diff --git a/modules/checks.nix b/modules/checks.nix
index 4fbb0af..12dde09 100644
--- a/modules/checks.nix
+++ b/modules/checks.nix
@@ -1,44 +1,21 @@
{ config, lib, flake-parts-lib, ... }:
let
inherit (lib)
- filterAttrs
- mapAttrs
mkOption
- optionalAttrs
types
;
inherit (flake-parts-lib)
- mkSubmoduleOptions
- mkPerSystemOption
+ mkTransposedPerSystemModule
;
in
-{
- options = {
- flake = mkSubmoduleOptions {
- checks = mkOption {
- type = types.lazyAttrsOf (types.lazyAttrsOf types.package);
- default = { };
- description = ''
- Derivations to be built by nix flake check.
- '';
- };
- };
-
- perSystem = mkPerSystemOption ({ config, system, ... }: {
- _file = ./checks.nix;
- options = {
- checks = mkOption {
- type = types.lazyAttrsOf types.package;
- default = { };
- description = ''
- Derivations to be built by nix flake check.
- '';
- };
- };
- });
-
- };
- config = {
- transposition.checks = { };
+mkTransposedPerSystemModule {
+ name = "checks";
+ option = mkOption {
+ type = types.lazyAttrsOf types.package;
+ default = { };
+ description = ''
+ Derivations to be built by nix flake check.
+ '';
};
+ file = ./checks.nix;
}
diff --git a/modules/devShells.nix b/modules/devShells.nix
index ecc53b3..7ebbeb6 100644
--- a/modules/devShells.nix
+++ b/modules/devShells.nix
@@ -1,45 +1,22 @@
{ config, lib, flake-parts-lib, ... }:
let
inherit (lib)
- filterAttrs
- mapAttrs
mkOption
- optionalAttrs
types
;
inherit (flake-parts-lib)
- mkSubmoduleOptions
- mkPerSystemOption
+ mkTransposedPerSystemModule
;
in
-{
- options = {
- flake = mkSubmoduleOptions {
- devShells = mkOption {
- type = types.lazyAttrsOf (types.lazyAttrsOf types.package);
- default = { };
- description = ''
- Per system an attribute set of packages used as shells.
- nix develop .#<name> will run devShells.<system>.<name>.
- '';
- };
- };
-
- perSystem = mkPerSystemOption
- ({ config, system, ... }: {
- options = {
- devShells = mkOption {
- type = types.lazyAttrsOf types.package;
- default = { };
- description = ''
- An attribute set of packages to be built by nix develop .#<name>.
- nix build .#<name> will run devShells.<name>.
- '';
- };
- };
- });
- };
- config = {
- transposition.devShells = { };
+mkTransposedPerSystemModule {
+ name = "devShells";
+ option = mkOption {
+ type = types.lazyAttrsOf types.package;
+ default = { };
+ description = ''
+ An attribute set of packages to be built by nix develop .#<name>.
+ nix build .#<name> will run devShells.<name>.
+ '';
};
+ file = ./devShells.nix;
}
diff --git a/modules/formatter.nix b/modules/formatter.nix
index a63a9ba..d5b0435 100644
--- a/modules/formatter.nix
+++ b/modules/formatter.nix
@@ -1,55 +1,21 @@
{ config, lib, flake-parts-lib, ... }:
let
inherit (lib)
- filterAttrs
- mapAttrs
mkOption
- optionalAttrs
types
;
inherit (flake-parts-lib)
- mkSubmoduleOptions
- mkPerSystemOption
+ mkTransposedPerSystemModule
;
in
-{
- options = {
- flake = mkSubmoduleOptions {
- formatter = mkOption {
- type = types.lazyAttrsOf types.package;
- default = { };
- description = ''
- Per system package used by nix fmt.
- '';
- };
- };
-
- perSystem = mkPerSystemOption ({ config, ... }: {
- _file = ./formatter.nix;
- options = {
- formatter = mkOption {
- type = types.nullOr types.package;
- default = null;
- description = ''
- A package used by nix fmt.
- '';
- };
- };
- });
- };
- config = {
- flake.formatter =
- mapAttrs
- (k: v: v.formatter)
- (filterAttrs
- (k: v: v.formatter != null)
- config.allSystems
- );
-
- perInput = system: flake:
- optionalAttrs (flake?formatter.${system}) {
- formatter = flake.formatter.${system};
- };
-
+mkTransposedPerSystemModule {
+ name = "formatter";
+ option = mkOption {
+ type = types.nullOr types.package;
+ default = null;
+ description = ''
+ A package used by nix fmt.
+ '';
};
+ file = ./formatter.nix;
}
diff --git a/modules/legacyPackages.nix b/modules/legacyPackages.nix
index eedc075..f07ab16 100644
--- a/modules/legacyPackages.nix
+++ b/modules/legacyPackages.nix
@@ -1,43 +1,21 @@
{ config, lib, flake-parts-lib, ... }:
let
inherit (lib)
- filterAttrs
- mapAttrs
mkOption
- optionalAttrs
types
;
inherit (flake-parts-lib)
- mkSubmoduleOptions
- mkPerSystemOption
+ mkTransposedPerSystemModule
;
in
-{
- options = {
- flake = mkSubmoduleOptions {
- legacyPackages = mkOption {
- type = types.lazyAttrsOf (types.lazyAttrsOf types.raw);
- default = { };
- description = ''
- Per system, an attribute set of unmergeable values. This is also used by nix build .#<attrpath>.
- '';
- };
- };
-
- perSystem = mkPerSystemOption ({ config, ... }: {
- options = {
- legacyPackages = mkOption {
- type = types.lazyAttrsOf types.raw;
- default = { };
- description = ''
- An attribute set of unmergeable values. This is also used by nix build .#<attrpath>.
- '';
- };
- };
- });
- };
-
- config = {
- transposition.legacyPackages = { };
+mkTransposedPerSystemModule {
+ name = "legacyPackages";
+ option = mkOption {
+ type = types.lazyAttrsOf types.raw;
+ default = { };
+ description = ''
+ An attribute set of unmergeable values. This is also used by nix build .#<attrpath>.
+ '';
};
+ file = ./legacyPackages.nix;
}
diff --git a/modules/packages.nix b/modules/packages.nix
index 05fea46..a6a22c5 100644
--- a/modules/packages.nix
+++ b/modules/packages.nix
@@ -1,45 +1,22 @@
{ config, lib, flake-parts-lib, ... }:
let
inherit (lib)
- filterAttrs
- mapAttrs
mkOption
- optionalAttrs
types
;
inherit (flake-parts-lib)
- mkSubmoduleOptions
- mkPerSystemOption
+ mkTransposedPerSystemModule
;
in
-{
- options = {
- flake = mkSubmoduleOptions {
- packages = mkOption {
- type = types.lazyAttrsOf (types.lazyAttrsOf types.package);
- default = { };
- description = ''
- Per system an attribute set of packages.
- nix build .#<name> will build packages.<system>.<name>.
- '';
- };
- };
-
- perSystem = mkPerSystemOption ({ config, ... }: {
- _file = ./packages.nix;
- options = {
- packages = mkOption {
- type = types.lazyAttrsOf types.package;
- default = { };
- description = ''
- An attribute set of packages to be built by nix build .#<name>.
- nix build .#<name> will build packages.<name>.
- '';
- };
- };
- });
- };
- config = {
- transposition.packages = { };
+mkTransposedPerSystemModule {
+ name = "packages";
+ option = mkOption {
+ type = types.lazyAttrsOf types.package;
+ default = { };
+ description = ''
+ An attribute set of packages to be built by nix build .#<name>.
+ nix build .#<name> will build packages.<name>.
+ '';
};
+ file = ./packages.nix;
}