mirror of
https://github.com/hercules-ci/flake-parts.git
synced 2024-12-14 11:47:31 +00:00
Merge pull request #64 from shlevy/perSystem-module
Add mkTransposedPerSystemModule for simple per-system exposed attrs
This commit is contained in:
commit
f3fa98168a
8 changed files with 96 additions and 221 deletions
|
@ -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
|
||||
|
|
28
lib.nix
28
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
|
||||
|
|
|
@ -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 <literal>.#<name></literal>.
|
||||
'';
|
||||
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 <literal>.#<name></literal>.
|
||||
'';
|
||||
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 <literal>.#<name></literal>.
|
||||
'';
|
||||
example = lib.literalExpression or lib.literalExample ''
|
||||
{
|
||||
default.program = "''${config.packages.hello}/bin/hello";
|
||||
}
|
||||
'';
|
||||
};
|
||||
file = ./apps.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;
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
<literal>nix develop .#<name></literal> will run <literal>devShells.<system>.<name></literal>.
|
||||
'';
|
||||
};
|
||||
};
|
||||
|
||||
perSystem = mkPerSystemOption
|
||||
({ config, system, ... }: {
|
||||
options = {
|
||||
devShells = mkOption {
|
||||
type = types.lazyAttrsOf types.package;
|
||||
default = { };
|
||||
description = ''
|
||||
An attribute set of packages to be built by <literal>nix develop .#<name></literal>.
|
||||
<literal>nix build .#<name></literal> will run <literal>devShells.<name></literal>.
|
||||
'';
|
||||
};
|
||||
};
|
||||
});
|
||||
};
|
||||
config = {
|
||||
transposition.devShells = { };
|
||||
mkTransposedPerSystemModule {
|
||||
name = "devShells";
|
||||
option = mkOption {
|
||||
type = types.lazyAttrsOf types.package;
|
||||
default = { };
|
||||
description = ''
|
||||
An attribute set of packages to be built by <literal>nix develop .#<name></literal>.
|
||||
<literal>nix build .#<name></literal> will run <literal>devShells.<name></literal>.
|
||||
'';
|
||||
};
|
||||
file = ./devShells.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 <literal>nix fmt</literal>.
|
||||
'';
|
||||
};
|
||||
};
|
||||
|
||||
perSystem = mkPerSystemOption ({ config, ... }: {
|
||||
_file = ./formatter.nix;
|
||||
options = {
|
||||
formatter = mkOption {
|
||||
type = types.nullOr types.package;
|
||||
default = null;
|
||||
description = ''
|
||||
A package used by <literal>nix fmt</literal>.
|
||||
'';
|
||||
};
|
||||
};
|
||||
});
|
||||
};
|
||||
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 <literal>nix fmt</literal>.
|
||||
'';
|
||||
};
|
||||
file = ./formatter.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 <literal>nix build .#<attrpath></literal>.
|
||||
'';
|
||||
};
|
||||
};
|
||||
|
||||
perSystem = mkPerSystemOption ({ config, ... }: {
|
||||
options = {
|
||||
legacyPackages = mkOption {
|
||||
type = types.lazyAttrsOf types.raw;
|
||||
default = { };
|
||||
description = ''
|
||||
An attribute set of unmergeable values. This is also used by <literal>nix build .#<attrpath></literal>.
|
||||
'';
|
||||
};
|
||||
};
|
||||
});
|
||||
};
|
||||
|
||||
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 <literal>nix build .#<attrpath></literal>.
|
||||
'';
|
||||
};
|
||||
file = ./legacyPackages.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.
|
||||
<literal>nix build .#<name></literal> will build <literal>packages.<system>.<name></literal>.
|
||||
'';
|
||||
};
|
||||
};
|
||||
|
||||
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 <literal>nix build .#<name></literal>.
|
||||
<literal>nix build .#<name></literal> will build <literal>packages.<name></literal>.
|
||||
'';
|
||||
};
|
||||
};
|
||||
});
|
||||
};
|
||||
config = {
|
||||
transposition.packages = { };
|
||||
mkTransposedPerSystemModule {
|
||||
name = "packages";
|
||||
option = mkOption {
|
||||
type = types.lazyAttrsOf types.package;
|
||||
default = { };
|
||||
description = ''
|
||||
An attribute set of packages to be built by <literal>nix build .#<name></literal>.
|
||||
<literal>nix build .#<name></literal> will build <literal>packages.<name></literal>.
|
||||
'';
|
||||
};
|
||||
file = ./packages.nix;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue