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

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

View file

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

View file

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

View file

@ -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 .#&lt;name></literal>.
Per system an attribute set of packages used as shells. <literal>nix build .#&lt;name></literal> will run <literal>devShells.&lt;name></literal>.
<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 = { };
}; };
file = ./devShells.nix;
} }

View file

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

View file

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

View file

@ -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 .#&lt;name></literal>.
Per system an attribute set of packages. <literal>nix build .#&lt;name></literal> will build <literal>packages.&lt;name></literal>.
<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 = { };
}; };
file = ./packages.nix;
} }