Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 0 additions & 37 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

140 changes: 71 additions & 69 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -1,82 +1,84 @@
{
inputs = {
flake-parts.url = "github:hercules-ci/flake-parts";
# The systems to build for. If empty, build for current system.
systems.url = "github:srid/empty";
flake = { };
};
outputs = inputs:
inputs.flake-parts.lib.mkFlake { inherit inputs; } {
systems = [ "x86_64-linux" "aarch64-linux" "aarch64-darwin" "x86_64-darwin" ];
perSystem = { self', pkgs, lib, system, ... }: {
_module.args.pkgs = import inputs.flake.inputs.nixpkgs { inherit system; };
packages =
let
build-systems =
let systems = import inputs.systems;
in if systems == [ ] then [ system ] else systems;
shouldBuildOn = s: lib.elem s build-systems;
getSystem = cfg:
cfg.pkgs.stdenv.hostPlatform.system;
configForCurrentSystem = cfg:
shouldBuildOn (getSystem cfg);
# Given a flake output key, how to get the buildable derivation for
# any of its attr values?
flakeSchema = {
perSystem = {
# -> [ path ]
lookupFlake = k: flake:
lib.flip builtins.map build-systems (sys:
lib.attrByPath [ k sys ] { } flake
);
getDrv = {
packages = _: x: [ x ];
checks = _: x: [ x ];
devShells = _: x: [ x ];
apps = _: app: [ app.program ];
legacyPackages = k: v:
if k == "homeConfigurations"
then
lib.mapAttrsToList (_: cfg: cfg.activationPackage) v
else [ ];
};
};
flake = {
lookupFlake = k: flake: [ (lib.attrByPath [ k ] { } flake) ];
getDrv = {
nixosConfigurations = _: cfg:
lib.optional (configForCurrentSystem cfg) cfg.config.system.build.toplevel;
darwinConfigurations = _: cfg:
lib.optional (configForCurrentSystem cfg) cfg.config.system.build.toplevel;
};
let
allSystems = [ "x86_64-linux" "aarch64-linux" "aarch64-darwin" "x86_64-darwin" ];
forAllSystems = f: builtins.listToAttrs (map (system: { name = system; value = f system; }) allSystems);
in
{
packages = forAllSystems (system:
let
pkgs = import inputs.flake.inputs.nixpkgs { inherit system; };
lib = pkgs.lib;
build-systems =
let systems = import inputs.systems;
in if systems == [ ] then [ system ] else systems;
shouldBuildOn = s: lib.elem s build-systems;
getSystem = cfg:
cfg.pkgs.stdenv.hostPlatform.system;
configForCurrentSystem = cfg:
shouldBuildOn (getSystem cfg);
# Given a flake output key, how to get the buildable derivation for
# any of its attr values?
flakeSchema = {
perSystem = {
# -> [ path ]
lookupFlake = k: flake:
lib.flip builtins.map build-systems (sys:
lib.attrByPath [ k sys ] { } flake
);
getDrv = {
packages = _: x: [ x ];
checks = _: x: [ x ];
devShells = _: x: [ x ];
apps = _: app: [ app.program ];
legacyPackages = k: v:
if k == "homeConfigurations"
then
lib.mapAttrsToList (_: cfg: cfg.activationPackage) v
else [ ];
};
};
paths =
lib.flip lib.mapAttrsToList flakeSchema (_: lvlSchema:
lib.flip lib.mapAttrsToList lvlSchema.getDrv (kind: getDrv:
builtins.concatMap
(attr: lib.mapAttrsToList getDrv attr)
(lvlSchema.lookupFlake kind inputs.flake)
)
);
nameForStorePath = path:
if builtins.typeOf path == "set"
then path.pname or path.name or null
else null;
result = rec {
outPaths = lib.lists.flatten paths;
# Indexed by the path's unique name
# Paths without such a name will be ignored. Hence, you must rely on `out_paths` for comprehensive list of outputs.
byName = lib.foldl' (acc: path:
let name = nameForStorePath path;
in if name == null then acc else acc // { "${name}" = path; }
) { } outPaths;
flake = {
lookupFlake = k: flake: [ (lib.attrByPath [ k ] { } flake) ];
getDrv = {
nixosConfigurations = _: cfg:
lib.optional (configForCurrentSystem cfg) cfg.config.system.build.toplevel;
darwinConfigurations = _: cfg:
lib.optional (configForCurrentSystem cfg) cfg.config.system.build.toplevel;
};
};
in
rec {
json = pkgs.writeText "devour-output.json" (builtins.toJSON result);
default = pkgs.writeText "devour-output" (lib.strings.concatLines result.outPaths);
};
};
paths =
lib.flip lib.mapAttrsToList flakeSchema (_: lvlSchema:
lib.flip lib.mapAttrsToList lvlSchema.getDrv (kind: getDrv:
builtins.concatMap
(attr: lib.mapAttrsToList getDrv attr)
(lvlSchema.lookupFlake kind inputs.flake)
)
);
nameForStorePath = path:
if builtins.typeOf path == "set"
then path.pname or path.name or null
else null;
result = rec {
outPaths = lib.lists.flatten paths;
# Indexed by the path's unique name
# Paths without such a name will be ignored. Hence, you must rely on `out_paths` for comprehensive list of outputs.
byName = lib.foldl' (acc: path:
let name = nameForStorePath path;
in if name == null then acc else acc // { "${name}" = path; }
) { } outPaths;
};
in
rec {
json = pkgs.writeText "devour-output.json" (builtins.toJSON result);
default = pkgs.writeText "devour-output" (lib.strings.concatLines result.outPaths);
}
);
};
}