1
0
Fork 0
mirror of https://github.com/hercules-ci/flake-parts.git synced 2024-12-14 11:47:31 +00:00

Small beginnings

This commit is contained in:
Robert Hensing 2021-10-27 11:05:52 +02:00
parent cc9c738244
commit 8c3f71965e
10 changed files with 280 additions and 0 deletions

6
README.md Normal file
View file

@ -0,0 +1,6 @@
# Flake Module Core
_Foundational flake attributes represented using the module system._
`flake-modules-core` provides common options for an ecosystem of modules to extend.

10
all-modules.nix Normal file
View file

@ -0,0 +1,10 @@
{ lib, ... }:
{
imports = [
./modules/checks.nix
./modules/devShell.nix
./modules/legacyPackages.nix
./modules/packages.nix
./modules/perSystem.nix
];
}

15
flake.nix Normal file
View file

@ -0,0 +1,15 @@
{
description = "Flake basics described using the module system";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
};
outputs = { self, nixpkgs, ... }: {
lib = import ./lib.nix { inherit (nixpkgs) lib; };
flakeModules = {
core = ./all-modules.nix;
};
};
}

21
lib.nix Normal file
View file

@ -0,0 +1,21 @@
{ lib }:
let
inherit (lib)
mkOption
types
;
flake-modules-core-lib = {
evalFlakeModule =
{ self
, specialArgs ? { }
}:
module:
lib.evalModules {
specialArgs = { inherit self flake-modules-core-lib; } // specialArgs;
modules = [ ./all-modules.nix module ];
};
};
in
flake-modules-core-lib

45
modules/checks.nix Normal file
View file

@ -0,0 +1,45 @@
{ config, lib, flake-modules-core-lib, ... }:
let
inherit (lib)
filterAttrs
genAttrs
mapAttrs
mkOption
optionalAttrs
types
;
in
{
options = {
flake = {
checks = mkOption {
type = types.lazyAttrsOf (types.lazyAttrsOf types.package);
default = { };
};
};
};
config = {
flake.checks =
mapAttrs
(k: v: v.checks)
(filterAttrs
(k: v: v.checks != null)
(genAttrs config.systems config.perSystem)
);
perInput = system: flake:
optionalAttrs (flake?checks.${system}) {
checks = flake.checks.${system};
};
perSystem = system: { config, ... }: {
_file = ./checks.nix;
options = {
checks = mkOption {
type = types.lazyAttrsOf types.package;
default = { };
};
};
};
};
}

44
modules/devShell.nix Normal file
View file

@ -0,0 +1,44 @@
{ config, lib, flake-modules-core-lib, ... }:
let
inherit (lib)
filterAttrs
genAttrs
mapAttrs
mkOption
optionalAttrs
types
;
in
{
options = {
flake = {
devShell = mkOption {
type = types.lazyAttrsOf types.package;
default = { };
};
};
};
config = {
flake.devShell =
mapAttrs
(k: v: v.devShell)
(filterAttrs
(k: v: v.devShell != null)
(genAttrs config.systems config.perSystem)
);
perInput = system: flake:
optionalAttrs (flake?devShell.${system}) {
devShell = flake.devShell.${system};
};
perSystem = system: { config, ... }: {
_file = ./devShell.nix;
options = {
devShell = mkOption {
type = types.nullOr types.package;
};
};
};
};
}

View file

@ -0,0 +1,45 @@
{ config, lib, flake-modules-core-lib, ... }:
let
inherit (lib)
filterAttrs
genAttrs
mapAttrs
mkOption
optionalAttrs
types
;
in
{
options = {
flake = {
legacyPackages = mkOption {
type = types.lazyAttrsOf (types.lazyAttrsOf types.anything);
default = { };
};
};
};
config = {
flake.legacyPackages =
mapAttrs
(k: v: v.legacyPackages)
(filterAttrs
(k: v: v.legacyPackages != null)
(genAttrs config.systems config.perSystem)
);
perInput = system: flake:
optionalAttrs (flake?legacyPackages.${system}) {
legacyPackages = flake.legacyPackages.${system};
};
perSystem = system: { config, ... }: {
_file = ./legacyPackages.nix;
options = {
legacyPackages = mkOption {
type = types.lazyAttrsOf types.anything;
default = { };
};
};
};
};
}

45
modules/packages.nix Normal file
View file

@ -0,0 +1,45 @@
{ config, lib, flake-modules-core-lib, ... }:
let
inherit (lib)
filterAttrs
genAttrs
mapAttrs
mkOption
optionalAttrs
types
;
in
{
options = {
flake = {
packages = mkOption {
type = types.lazyAttrsOf (types.lazyAttrsOf types.package);
default = { };
};
};
};
config = {
flake.packages =
mapAttrs
(k: v: v.packages)
(filterAttrs
(k: v: v.packages != null)
(genAttrs config.systems config.perSystem)
);
perInput = system: flake:
optionalAttrs (flake?packages.${system}) {
packages = flake.packages.${system};
};
perSystem = system: { config, ... }: {
_file = ./packages.nix;
options = {
packages = mkOption {
type = types.lazyAttrsOf types.package;
default = { };
};
};
};
};
}

43
modules/perSystem.nix Normal file
View file

@ -0,0 +1,43 @@
{ config, lib, self, ... }:
let
inherit (lib)
mapAttrs
mkOption
types
;
rootConfig = config;
in
{
options = {
systems = mkOption {
description = "All the system types to enumerate in the flake.";
type = types.listOf types.str;
default = [ ];
};
perInput = mkOption {
description = "Function from system to function from flake to system-specific attributes.";
type = types.functionTo (types.functionTo (types.lazyAttrsOf types.unspecified));
};
perSystem = mkOption {
description = "A function from system to flake-like attributes omitting the <system> attribute.";
type = types.functionTo (types.submoduleWith {
modules = [
({ config, system, ... }: {
_file = ./perSystem.nix;
config = {
_module.args.inputs' = mapAttrs (k: rootConfig.perInput system) self.inputs;
_module.args.self' = rootConfig.perInput system self;
};
})
];
shorthandOnlyDefinesConfig = false;
});
};
};
config.perSystem = system: { _module.args.system = system; };
}

6
modules/self.nix Normal file
View file

@ -0,0 +1,6 @@
{ lib, ... }: {
options.self = lib.mkOption {
description = "The current flake.";
type = type.lazyAttrsOf type.unspecified;
};
}