1
0
Fork 0
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:
Robert Hensing 2022-11-11 05:39:28 +01:00 committed by GitHub
commit f3fa98168a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 96 additions and 221 deletions

View file

@ -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
View file

@ -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

View file

@ -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>.#&lt;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>.#&lt;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>.#&lt;name></literal>.
'';
example = lib.literalExpression or lib.literalExample ''
{
default.program = "''${config.packages.hello}/bin/hello";
}
'';
};
file = ./apps.nix;
}

View file

@ -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;
}

View file

@ -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 .#&lt;name></literal> will run <literal>devShells.&lt;system>.&lt;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 .#&lt;name></literal>.
<literal>nix build .#&lt;name></literal> will run <literal>devShells.&lt;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 .#&lt;name></literal>.
<literal>nix build .#&lt;name></literal> will run <literal>devShells.&lt;name></literal>.
'';
};
file = ./devShells.nix;
}

View file

@ -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;
}

View file

@ -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 .#&lt;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 .#&lt;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 .#&lt;attrpath></literal>.
'';
};
file = ./legacyPackages.nix;
}

View file

@ -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 .#&lt;name></literal> will build <literal>packages.&lt;system>.&lt;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 .#&lt;name></literal>.
<literal>nix build .#&lt;name></literal> will build <literal>packages.&lt;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 .#&lt;name></literal>.
<literal>nix build .#&lt;name></literal> will build <literal>packages.&lt;name></literal>.
'';
};
file = ./packages.nix;
}