Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wip: first attempt #12

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
29 changes: 24 additions & 5 deletions desys.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,45 @@
#
# SPDX-License-Identifier: Unlicense
let
l = builtins;
l = builtins // {
# taken from `nixpkgs.lib.debug`
traceIf =
# Predicate to check
pred:
# Message that should be traced
msg:
# Value to return
x: if pred then l.trace msg x else x;
};


cutat = 3;
pad = n: l.concatStringsSep "" (l.genList (_: "\t") n);
/*
A helper function which hides the complexities of dealing
with 'system' properly from you, while still providing
escape hatches when dealing with cross-compilation.
*/
deSystemize = let
iteration = cutoff: system: fragment:
deSystemize = debug: let
iteration = name: cutoff: system: fragment:
if ! (l.isAttrs fragment) || cutoff == 0
then fragment
else let
recursed = l.mapAttrs (_: iteration (cutoff - 1) system) fragment;
recursed = l.mapAttrs (n:
l.traceIf debug "deSys:${pad (cutat - cutoff)} visit ${n}"
iteration n (cutoff - 1) system
) fragment;
in
if l.hasAttr "${system}" fragment
then
l.traceIf debug "deSys:${pad (cutat - cutoff)} hoist '${system}' onto '${name}' for direct access"
(
if l.isFunction fragment.${system}
then recursed // {__functor = _: fragment.${system};}
else recursed // fragment.${system}
)
else recursed;
in
iteration 3;
iteration "." cutat;
in
deSystemize
7 changes: 7 additions & 0 deletions flake.lock

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

44 changes: 33 additions & 11 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,50 @@
# SPDX-License-Identifier: Unlicense
{
description = "Nix flakes with `systems` à la carte.";
outputs = {self}: {
__functor = self: self.lib.noSys;
outputs = {self}: let
l = builtins // {
# taken from `nixpkgs.lib.debug`
traceIf =
# Predicate to check
pred:
# Message that should be traced
msg:
# Value to return
x: if pred then l.trace msg x else x;
};

lib.noSys = inputs @ {systems ? import ./systems.nix, ...}: f: let
deSys = import ./desys.nix;
eachSys = import ./eachSys.nix;
noSys = debug: inputs @ {systems ? import ./systems.nix, ...}: f: let
systems' =
if builtins.isPath systems || systems ? outPath
if l.isPath systems || systems ? outPath
then import systems
else systems;
in
self.lib.eachSys systems' (sys: let
l.traceIf debug "systems ${l.concatStringsSep ", " systems'}"
eachSys systems' (sys: let
f' = inputs: let
# mapAttrs to deSys up to the same depths as in `self`
inputs' = builtins.mapAttrs (_: self.lib.deSys sys) (builtins.removeAttrs inputs ["self"]);
self' = self.lib.deSys sys (builtins.removeAttrs inputs.self ["inputs"]);
in
inputs' = l.mapAttrs (_: deSys debug sys) (l.removeAttrs inputs ["self"]);
self' = deSys debug sys (l.removeAttrs inputs.self ["inputs"]);
# must be recombined after `deSys` to avoid infinite recursion
f (inputs' // {self = self';});
args = inputs' // {self = self';};
in
f args;
in
f' inputs);

lib.deSys = import ./desys.nix;
lib.eachSys = import ./eachSys.nix;
in {

debug = false;
__functor = {debug, ... }: noSys debug;

lib = {
inherit eachSys;
# no debug
deSys = deSys false;
noSys = noSys false;
};

templates.default = {
path = ./tmpl;
Expand Down
52 changes: 52 additions & 0 deletions tmpl/flake.lock

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

6 changes: 3 additions & 3 deletions tmpl/flake.nix
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
inputs.nosys.url = "github:divnix/nosys";
inputs.nosys.url = "path:../.";

inputs.systems.url = "path:./flake/systems.nix";
inputs.systems.flake = false;

outputs = inputs @ {nosys, ...}: let
outputs = inputs @ {nosys, nixpkgs, ...}: let
outputs = import ./flake/outputs.nix;
in
nosys inputs outputs;
(nosys // {debug = true;}) inputs outputs;
}
3 changes: 2 additions & 1 deletion tmpl/flake/outputs.nix
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
{self, ...}: {
{self, nixpkgs, ...}: {
packages = {inherit (nixpkgs.legacyPackages) hello;};
}