mirror of
https://github.com/nix-community/flakelight.git
synced 2024-11-21 23:13:09 +01:00
Apply misc code cleanup
This commit is contained in:
parent
cc2f42fbdf
commit
5215a657bf
@ -11,9 +11,7 @@ let
|
||||
isApp = x: (x ? type) && (x.type == "app") && (x ? program);
|
||||
|
||||
mkApp = pkgs: app:
|
||||
let
|
||||
app' = if isFunction app then app pkgs else app;
|
||||
in
|
||||
let app' = if isFunction app then app pkgs else app; in
|
||||
if isApp app' then app' else { type = "app"; program = "${app'}"; };
|
||||
in
|
||||
{
|
||||
|
@ -7,6 +7,7 @@ let
|
||||
inherit (lib) isList mkOption mkOrder mapAttrs optionalAttrs;
|
||||
inherit (lib.types) listOf nullOr oneOf str;
|
||||
inherit (builtins) pathExists;
|
||||
inherit (flakelight) selectAttr;
|
||||
in
|
||||
{
|
||||
options = {
|
||||
@ -25,13 +26,10 @@ in
|
||||
};
|
||||
|
||||
config.withOverlays = mkOrder 10 (final: prev:
|
||||
let
|
||||
inherit (prev.stdenv.hostPlatform) system;
|
||||
in
|
||||
{
|
||||
let inherit (prev.stdenv.hostPlatform) system; in {
|
||||
inherit system moduleArgs src inputs outputs flakelight;
|
||||
inputs' = mapAttrs (_: mapAttrs (_: v: v.${system} or { })) inputs;
|
||||
outputs' = mapAttrs (_: v: v.${system} or { }) outputs;
|
||||
inputs' = mapAttrs (_: selectAttr system) inputs;
|
||||
outputs' = selectAttr system outputs;
|
||||
|
||||
defaultMeta = {
|
||||
platforms = config.systems;
|
||||
|
@ -9,7 +9,9 @@ let
|
||||
inherit (flakelight.types) function optFunctionTo;
|
||||
|
||||
wrapBundler = pkgs: bundler: drv:
|
||||
if isFunction (bundler (pkgs // drv)) then bundler pkgs drv else bundler drv;
|
||||
if isFunction (bundler (pkgs // drv))
|
||||
then bundler pkgs drv
|
||||
else bundler drv;
|
||||
in
|
||||
{
|
||||
options = {
|
||||
|
@ -8,10 +8,8 @@ let
|
||||
inherit (lib.types) lazyAttrsOf nullOr raw;
|
||||
inherit (flakelight.types) optFunctionTo;
|
||||
|
||||
mkCheck = pkgs: src: name: cmd:
|
||||
let
|
||||
cmd' = if isFunction cmd then cmd pkgs else cmd;
|
||||
in
|
||||
mkCheck = pkgs: name: cmd:
|
||||
let cmd' = if isFunction cmd then cmd pkgs else cmd; in
|
||||
if isDerivation cmd' then cmd' else
|
||||
pkgs.runCommand "check-${name}" { } ''
|
||||
cp --no-preserve=mode -r ${src} src
|
||||
@ -28,6 +26,6 @@ in
|
||||
|
||||
config.outputs = mkIf (config.checks != null) {
|
||||
checks = genSystems (pkgs:
|
||||
mapAttrs (mkCheck pkgs src) (config.checks pkgs));
|
||||
mapAttrs (mkCheck pkgs) (config.checks pkgs));
|
||||
};
|
||||
}
|
||||
|
@ -18,7 +18,9 @@ let
|
||||
if (length defs) == 1 then (head defs).value
|
||||
else if all isAttrs (getValues defs) then
|
||||
(lazyAttrsOf outputs).merge loc defs
|
||||
else throw "The option `${showOption loc}' has conflicting definitions in ${showFiles (getFiles defs)}";
|
||||
else
|
||||
throw ("The option `${showOption loc}' has conflicting definitions" +
|
||||
" in ${showFiles (getFiles defs)}");
|
||||
};
|
||||
|
||||
pkgsFor = genAttrs config.systems (system: import inputs.nixpkgs {
|
||||
|
@ -4,41 +4,29 @@
|
||||
|
||||
{ config, lib, inputs, flakelight, moduleArgs, ... }:
|
||||
let
|
||||
inherit (builtins) concatLists head mapAttrs match;
|
||||
inherit (lib) foldl last mapAttrsToList mkOption mkIf recursiveUpdate
|
||||
zipAttrsWith;
|
||||
inherit (builtins) head mapAttrs match;
|
||||
inherit (lib) foldl mapAttrsToList mkOption mkIf recursiveUpdate;
|
||||
inherit (lib.types) attrs lazyAttrsOf;
|
||||
inherit (flakelight) selectAttr;
|
||||
inherit (flakelight.types) optFunctionTo;
|
||||
|
||||
isHome = x: x ? activationPackage;
|
||||
|
||||
mergeCfg = zipAttrsWith (n: vs:
|
||||
if n == "extraSpecialArgs" then
|
||||
foldl (a: b: a // b) { } vs
|
||||
else if n == "modules" then
|
||||
concatLists vs
|
||||
else last vs);
|
||||
|
||||
mkHome = name: cfg:
|
||||
let
|
||||
inherit (cfg) system;
|
||||
in
|
||||
inputs.home-manager.lib.homeManagerConfiguration (mergeCfg [
|
||||
{
|
||||
extraSpecialArgs = {
|
||||
inherit inputs;
|
||||
inputs' = mapAttrs (_: mapAttrs (_: v: v.${system} or { })) inputs;
|
||||
};
|
||||
modules = [
|
||||
({ lib, ... }: {
|
||||
home.username = lib.mkDefault (head (match "([^@]*)(@.*)?" name));
|
||||
})
|
||||
config.propagationModule
|
||||
];
|
||||
pkgs = inputs.nixpkgs.legacyPackages.${system};
|
||||
}
|
||||
(removeAttrs cfg [ "system" ])
|
||||
]);
|
||||
mkHome = name: cfg: inputs.home-manager.lib.homeManagerConfiguration (
|
||||
(removeAttrs cfg [ "system" ]) // {
|
||||
extraSpecialArgs = {
|
||||
inherit inputs;
|
||||
inputs' = mapAttrs (_: selectAttr cfg.system) inputs;
|
||||
} // cfg.extraSpecialArgs or { };
|
||||
modules = [
|
||||
({ lib, ... }: {
|
||||
home.username = lib.mkDefault (head (match "([^@]*)(@.*)?" name));
|
||||
})
|
||||
config.propagationModule
|
||||
] ++ cfg.modules or [ ];
|
||||
pkgs = inputs.nixpkgs.legacyPackages.${cfg.system};
|
||||
}
|
||||
);
|
||||
|
||||
configs = mapAttrs
|
||||
(name: f:
|
||||
|
@ -4,42 +4,28 @@
|
||||
|
||||
{ config, lib, inputs, flakelight, moduleArgs, ... }:
|
||||
let
|
||||
inherit (builtins) concatLists mapAttrs;
|
||||
inherit (lib) foldl last mapAttrsToList mkIf mkOption recursiveUpdate
|
||||
zipAttrsWith;
|
||||
inherit (builtins) mapAttrs;
|
||||
inherit (lib) foldl mapAttrsToList mkIf mkOption recursiveUpdate;
|
||||
inherit (lib.types) attrs lazyAttrsOf;
|
||||
inherit (flakelight) selectAttr;
|
||||
inherit (flakelight.types) optFunctionTo;
|
||||
|
||||
# Avoid checking if toplevel is a derivation as it causes the nixos modules
|
||||
# to be evaluated.
|
||||
isNixos = x: x ? config.system.build.toplevel;
|
||||
|
||||
mergeCfg = zipAttrsWith (n: vs:
|
||||
if n == "specialArgs" then
|
||||
foldl (a: b: a // b) { } vs
|
||||
else if n == "modules" then
|
||||
concatLists vs
|
||||
else last vs);
|
||||
mkNixos = hostname: cfg: inputs.nixpkgs.lib.nixosSystem (cfg // {
|
||||
specialArgs = {
|
||||
inherit inputs hostname;
|
||||
inputs' = mapAttrs (_: selectAttr cfg.system) inputs;
|
||||
} // cfg.specialArgs or { };
|
||||
modules = [ config.propagationModule ] ++ cfg.modules or [ ];
|
||||
});
|
||||
|
||||
mkSystem = hostname: cfg:
|
||||
let
|
||||
inherit (cfg) system;
|
||||
in
|
||||
inputs.nixpkgs.lib.nixosSystem (mergeCfg [
|
||||
{
|
||||
specialArgs = {
|
||||
inherit inputs hostname;
|
||||
inputs' = mapAttrs (_: mapAttrs (_: v: v.${system} or { })) inputs;
|
||||
};
|
||||
modules = [ config.propagationModule ];
|
||||
}
|
||||
cfg
|
||||
]);
|
||||
|
||||
systems = mapAttrs
|
||||
configs = mapAttrs
|
||||
(hostname: f:
|
||||
let val = f moduleArgs; in
|
||||
if isNixos val then val else mkSystem hostname val)
|
||||
if isNixos val then val else mkNixos hostname val)
|
||||
config.nixosConfigurations;
|
||||
in
|
||||
{
|
||||
@ -49,13 +35,15 @@ in
|
||||
};
|
||||
|
||||
config.outputs = mkIf (config.nixosConfigurations != { }) {
|
||||
nixosConfigurations = systems;
|
||||
nixosConfigurations = configs;
|
||||
checks = foldl recursiveUpdate { } (mapAttrsToList
|
||||
(n: v: {
|
||||
# Wrapping the drv is needed as computing its name is expensive
|
||||
# If not wrapped, it slows down `nix flake show` significantly
|
||||
${v.config.nixpkgs.system}."nixos-${n}" = v.pkgs.runCommand
|
||||
"check-nixos-${n}"
|
||||
{ } "echo ${v.config.system.build.toplevel} > $out";
|
||||
})
|
||||
systems);
|
||||
configs);
|
||||
};
|
||||
}
|
||||
|
@ -8,6 +8,7 @@
|
||||
{ lib, config, flakelight, moduleArgs, inputs, outputs, ... }:
|
||||
let
|
||||
inherit (lib) mapAttrs mkOption optionalAttrs;
|
||||
inherit (flakelight) selectAttr;
|
||||
inherit (flakelight.types) module;
|
||||
in
|
||||
{
|
||||
@ -15,10 +16,7 @@ in
|
||||
|
||||
config.propagationModule =
|
||||
{ lib, pkgs, options, ... }:
|
||||
let
|
||||
inherit (pkgs.stdenv.hostPlatform) system;
|
||||
in
|
||||
{
|
||||
let inherit (pkgs.stdenv.hostPlatform) system; in {
|
||||
config = (optionalAttrs (options ? nixpkgs.overlays) {
|
||||
# Apply flakelight overlays to NixOS/home-manager configurations
|
||||
nixpkgs.overlays = lib.mkOrder 10
|
||||
@ -32,8 +30,8 @@ in
|
||||
# Give access to flakelight module args under `flake` arg.
|
||||
# Also include inputs'/outputs' which depend on `pkgs`.
|
||||
_module.args.flake = {
|
||||
inputs' = mapAttrs (_: mapAttrs (_: v: v.${system} or { })) inputs;
|
||||
outputs' = mapAttrs (_: v: v.${system} or { }) outputs;
|
||||
inputs' = mapAttrs (_: selectAttr system) inputs;
|
||||
outputs' = selectAttr system outputs;
|
||||
} // moduleArgs;
|
||||
};
|
||||
};
|
||||
|
117
default.nix
117
default.nix
@ -6,10 +6,10 @@ inputs:
|
||||
let
|
||||
inherit (inputs) nixpkgs;
|
||||
inherit (builtins) isAttrs isPath readDir;
|
||||
inherit (nixpkgs.lib) attrNames composeManyExtensions
|
||||
filter findFirst fix genAttrs getValues hasSuffix isFunction isList
|
||||
mapAttrsToList pathExists pipe removePrefix removeSuffix evalModules
|
||||
mkDefault mkOptionType singleton;
|
||||
inherit (nixpkgs.lib) attrNames composeManyExtensions evalModules filter
|
||||
findFirst fix genAttrs getValues hasSuffix isFunction isList mapAttrs
|
||||
mapAttrsToList mkDefault mkOptionType pathExists pipe removePrefix
|
||||
removeSuffix singleton;
|
||||
inherit (nixpkgs.lib.types) coercedTo functionTo listOf;
|
||||
inherit (nixpkgs.lib.options) mergeEqualOption mergeOneOption;
|
||||
|
||||
@ -36,61 +36,62 @@ let
|
||||
};
|
||||
|
||||
flakelight = {
|
||||
inherit mkFlake supportedSystem autoImport autoImportArgs;
|
||||
inherit autoImport autoImportArgs mkFlake selectAttr supportedSystem
|
||||
types;
|
||||
};
|
||||
|
||||
types = {
|
||||
overlay = mkOptionType {
|
||||
name = "overlay";
|
||||
description = "nixpkgs overlay";
|
||||
descriptionClass = "noun";
|
||||
check = isFunction;
|
||||
merge = _: defs: composeManyExtensions (getValues defs);
|
||||
};
|
||||
|
||||
packageDef = mkOptionType {
|
||||
name = "packageDef";
|
||||
description = "package definition";
|
||||
descriptionClass = "noun";
|
||||
check = isFunction;
|
||||
merge = mergeOneOption;
|
||||
};
|
||||
|
||||
path = mkOptionType {
|
||||
name = "path";
|
||||
description = "path";
|
||||
descriptionClass = "noun";
|
||||
check = isPath;
|
||||
merge = mergeEqualOption;
|
||||
};
|
||||
|
||||
function = mkOptionType {
|
||||
name = "function";
|
||||
description = "function";
|
||||
descriptionClass = "noun";
|
||||
check = isFunction;
|
||||
merge = mergeOneOption;
|
||||
};
|
||||
|
||||
module = mkOptionType {
|
||||
name = "module";
|
||||
description = "module";
|
||||
descriptionClass = "noun";
|
||||
check = x: isPath x || isFunction x || isAttrs x;
|
||||
merge = _: defs: { imports = getValues defs; };
|
||||
};
|
||||
|
||||
fileset = mkOptionType {
|
||||
name = "fileset";
|
||||
description = "fileset";
|
||||
descriptionClass = "noun";
|
||||
check = x: isPath x || x._type or null == "fileset";
|
||||
};
|
||||
|
||||
optListOf = elemType: coercedTo elemType singleton (listOf elemType);
|
||||
|
||||
optFunctionTo = elemType: coercedTo elemType (x: _: x)
|
||||
(functionTo elemType);
|
||||
types = {
|
||||
overlay = mkOptionType {
|
||||
name = "overlay";
|
||||
description = "nixpkgs overlay";
|
||||
descriptionClass = "noun";
|
||||
check = isFunction;
|
||||
merge = _: defs: composeManyExtensions (getValues defs);
|
||||
};
|
||||
|
||||
packageDef = mkOptionType {
|
||||
name = "packageDef";
|
||||
description = "package definition";
|
||||
descriptionClass = "noun";
|
||||
check = isFunction;
|
||||
merge = mergeOneOption;
|
||||
};
|
||||
|
||||
path = mkOptionType {
|
||||
name = "path";
|
||||
description = "path";
|
||||
descriptionClass = "noun";
|
||||
check = isPath;
|
||||
merge = mergeEqualOption;
|
||||
};
|
||||
|
||||
function = mkOptionType {
|
||||
name = "function";
|
||||
description = "function";
|
||||
descriptionClass = "noun";
|
||||
check = isFunction;
|
||||
merge = mergeOneOption;
|
||||
};
|
||||
|
||||
module = mkOptionType {
|
||||
name = "module";
|
||||
description = "module";
|
||||
descriptionClass = "noun";
|
||||
check = x: isPath x || isFunction x || isAttrs x;
|
||||
merge = _: defs: { imports = getValues defs; };
|
||||
};
|
||||
|
||||
fileset = mkOptionType {
|
||||
name = "fileset";
|
||||
description = "fileset";
|
||||
descriptionClass = "noun";
|
||||
check = x: isPath x || x._type or null == "fileset";
|
||||
};
|
||||
|
||||
optListOf = elemType: coercedTo elemType singleton (listOf elemType);
|
||||
|
||||
optFunctionTo = elemType: coercedTo elemType (x: _: x)
|
||||
(functionTo elemType);
|
||||
};
|
||||
|
||||
supportedSystem = { lib, stdenv, ... }:
|
||||
@ -125,5 +126,7 @@ let
|
||||
autoImportArgs = dir: args: name:
|
||||
let v = autoImport dir name; in
|
||||
if isFunction v then v args else v;
|
||||
|
||||
selectAttr = attr: mapAttrs (_: v: v.${attr} or { });
|
||||
in
|
||||
flakelight
|
||||
|
Loading…
Reference in New Issue
Block a user