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
|
let
|
||||||
flake = builtins.getFlake (toString ./.);
|
flake = builtins.getFlake (toString ./.);
|
||||||
fmc-lib = import ../lib.nix { inherit (flake.inputs.nixpkgs) lib; };
|
fmc-lib = (builtins.getFlake (toString ../.)).lib;
|
||||||
self = {
|
self = {
|
||||||
inherit (flake) inputs;
|
inherit (flake) inputs;
|
||||||
outPath = ../.; # used by pre-commit module, etc
|
outPath = ../.; # used by pre-commit module, etc
|
||||||
|
|
28
lib.nix
28
lib.nix
|
@ -98,6 +98,34 @@ let
|
||||||
type = flake-parts-lib.mkPerSystemType module;
|
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
|
in
|
||||||
|
|
|
@ -1,15 +1,11 @@
|
||||||
{ config, lib, flake-parts-lib, ... }:
|
{ config, lib, flake-parts-lib, ... }:
|
||||||
let
|
let
|
||||||
inherit (lib)
|
inherit (lib)
|
||||||
filterAttrs
|
|
||||||
mapAttrs
|
|
||||||
mkOption
|
mkOption
|
||||||
optionalAttrs
|
|
||||||
types
|
types
|
||||||
;
|
;
|
||||||
inherit (flake-parts-lib)
|
inherit (flake-parts-lib)
|
||||||
mkSubmoduleOptions
|
mkTransposedPerSystemModule
|
||||||
mkPerSystemOption
|
|
||||||
;
|
;
|
||||||
|
|
||||||
programType = lib.types.coercedTo derivationType getExe lib.types.str;
|
programType = lib.types.coercedTo derivationType getExe lib.types.str;
|
||||||
|
@ -44,43 +40,19 @@ let
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
in
|
in
|
||||||
{
|
mkTransposedPerSystemModule {
|
||||||
options = {
|
name = "apps";
|
||||||
flake = mkSubmoduleOptions {
|
option = mkOption {
|
||||||
apps = mkOption {
|
type = types.lazyAttrsOf appType;
|
||||||
type = types.lazyAttrsOf (types.lazyAttrsOf appType);
|
default = { };
|
||||||
default = { };
|
description = ''
|
||||||
description = ''
|
Programs runnable with nix run <literal>.#<name></literal>.
|
||||||
Programs runnable with nix run <literal>.#<name></literal>.
|
'';
|
||||||
'';
|
example = lib.literalExpression or lib.literalExample ''
|
||||||
example = lib.literalExpression or lib.literalExample ''
|
{
|
||||||
{
|
default.program = "''${config.packages.hello}/bin/hello";
|
||||||
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 = { };
|
|
||||||
};
|
};
|
||||||
|
file = ./apps.nix;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,44 +1,21 @@
|
||||||
{ config, lib, flake-parts-lib, ... }:
|
{ config, lib, flake-parts-lib, ... }:
|
||||||
let
|
let
|
||||||
inherit (lib)
|
inherit (lib)
|
||||||
filterAttrs
|
|
||||||
mapAttrs
|
|
||||||
mkOption
|
mkOption
|
||||||
optionalAttrs
|
|
||||||
types
|
types
|
||||||
;
|
;
|
||||||
inherit (flake-parts-lib)
|
inherit (flake-parts-lib)
|
||||||
mkSubmoduleOptions
|
mkTransposedPerSystemModule
|
||||||
mkPerSystemOption
|
|
||||||
;
|
;
|
||||||
in
|
in
|
||||||
{
|
mkTransposedPerSystemModule {
|
||||||
options = {
|
name = "checks";
|
||||||
flake = mkSubmoduleOptions {
|
option = mkOption {
|
||||||
checks = mkOption {
|
type = types.lazyAttrsOf types.package;
|
||||||
type = types.lazyAttrsOf (types.lazyAttrsOf types.package);
|
default = { };
|
||||||
default = { };
|
description = ''
|
||||||
description = ''
|
Derivations to be built by nix flake check.
|
||||||
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 = { };
|
|
||||||
};
|
};
|
||||||
|
file = ./checks.nix;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,45 +1,22 @@
|
||||||
{ config, lib, flake-parts-lib, ... }:
|
{ config, lib, flake-parts-lib, ... }:
|
||||||
let
|
let
|
||||||
inherit (lib)
|
inherit (lib)
|
||||||
filterAttrs
|
|
||||||
mapAttrs
|
|
||||||
mkOption
|
mkOption
|
||||||
optionalAttrs
|
|
||||||
types
|
types
|
||||||
;
|
;
|
||||||
inherit (flake-parts-lib)
|
inherit (flake-parts-lib)
|
||||||
mkSubmoduleOptions
|
mkTransposedPerSystemModule
|
||||||
mkPerSystemOption
|
|
||||||
;
|
;
|
||||||
in
|
in
|
||||||
{
|
mkTransposedPerSystemModule {
|
||||||
options = {
|
name = "devShells";
|
||||||
flake = mkSubmoduleOptions {
|
option = mkOption {
|
||||||
devShells = mkOption {
|
type = types.lazyAttrsOf types.package;
|
||||||
type = types.lazyAttrsOf (types.lazyAttrsOf types.package);
|
default = { };
|
||||||
default = { };
|
description = ''
|
||||||
description = ''
|
An attribute set of packages to be built by <literal>nix develop .#<name></literal>.
|
||||||
Per system an attribute set of packages used as shells.
|
<literal>nix build .#<name></literal> will run <literal>devShells.<name></literal>.
|
||||||
<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 = { };
|
|
||||||
};
|
};
|
||||||
|
file = ./devShells.nix;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,55 +1,21 @@
|
||||||
{ config, lib, flake-parts-lib, ... }:
|
{ config, lib, flake-parts-lib, ... }:
|
||||||
let
|
let
|
||||||
inherit (lib)
|
inherit (lib)
|
||||||
filterAttrs
|
|
||||||
mapAttrs
|
|
||||||
mkOption
|
mkOption
|
||||||
optionalAttrs
|
|
||||||
types
|
types
|
||||||
;
|
;
|
||||||
inherit (flake-parts-lib)
|
inherit (flake-parts-lib)
|
||||||
mkSubmoduleOptions
|
mkTransposedPerSystemModule
|
||||||
mkPerSystemOption
|
|
||||||
;
|
;
|
||||||
in
|
in
|
||||||
{
|
mkTransposedPerSystemModule {
|
||||||
options = {
|
name = "formatter";
|
||||||
flake = mkSubmoduleOptions {
|
option = mkOption {
|
||||||
formatter = mkOption {
|
type = types.nullOr types.package;
|
||||||
type = types.lazyAttrsOf types.package;
|
default = null;
|
||||||
default = { };
|
description = ''
|
||||||
description = ''
|
A package used by <literal>nix fmt</literal>.
|
||||||
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};
|
|
||||||
};
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
file = ./formatter.nix;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,43 +1,21 @@
|
||||||
{ config, lib, flake-parts-lib, ... }:
|
{ config, lib, flake-parts-lib, ... }:
|
||||||
let
|
let
|
||||||
inherit (lib)
|
inherit (lib)
|
||||||
filterAttrs
|
|
||||||
mapAttrs
|
|
||||||
mkOption
|
mkOption
|
||||||
optionalAttrs
|
|
||||||
types
|
types
|
||||||
;
|
;
|
||||||
inherit (flake-parts-lib)
|
inherit (flake-parts-lib)
|
||||||
mkSubmoduleOptions
|
mkTransposedPerSystemModule
|
||||||
mkPerSystemOption
|
|
||||||
;
|
;
|
||||||
in
|
in
|
||||||
{
|
mkTransposedPerSystemModule {
|
||||||
options = {
|
name = "legacyPackages";
|
||||||
flake = mkSubmoduleOptions {
|
option = mkOption {
|
||||||
legacyPackages = mkOption {
|
type = types.lazyAttrsOf types.raw;
|
||||||
type = types.lazyAttrsOf (types.lazyAttrsOf types.raw);
|
default = { };
|
||||||
default = { };
|
description = ''
|
||||||
description = ''
|
An attribute set of unmergeable values. This is also used by <literal>nix build .#<attrpath></literal>.
|
||||||
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 = { };
|
|
||||||
};
|
};
|
||||||
|
file = ./legacyPackages.nix;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,45 +1,22 @@
|
||||||
{ config, lib, flake-parts-lib, ... }:
|
{ config, lib, flake-parts-lib, ... }:
|
||||||
let
|
let
|
||||||
inherit (lib)
|
inherit (lib)
|
||||||
filterAttrs
|
|
||||||
mapAttrs
|
|
||||||
mkOption
|
mkOption
|
||||||
optionalAttrs
|
|
||||||
types
|
types
|
||||||
;
|
;
|
||||||
inherit (flake-parts-lib)
|
inherit (flake-parts-lib)
|
||||||
mkSubmoduleOptions
|
mkTransposedPerSystemModule
|
||||||
mkPerSystemOption
|
|
||||||
;
|
;
|
||||||
in
|
in
|
||||||
{
|
mkTransposedPerSystemModule {
|
||||||
options = {
|
name = "packages";
|
||||||
flake = mkSubmoduleOptions {
|
option = mkOption {
|
||||||
packages = mkOption {
|
type = types.lazyAttrsOf types.package;
|
||||||
type = types.lazyAttrsOf (types.lazyAttrsOf types.package);
|
default = { };
|
||||||
default = { };
|
description = ''
|
||||||
description = ''
|
An attribute set of packages to be built by <literal>nix build .#<name></literal>.
|
||||||
Per system an attribute set of packages.
|
<literal>nix build .#<name></literal> will build <literal>packages.<name></literal>.
|
||||||
<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 = { };
|
|
||||||
};
|
};
|
||||||
|
file = ./packages.nix;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue