From 26d6feea3d430a483da6e59fb2b1bf22abac3a51 Mon Sep 17 00:00:00 2001 From: David Arnold Date: Mon, 21 Nov 2022 17:31:30 -0500 Subject: [PATCH] wip: first attempt --- desys.nix | 29 +++++++++++++++++++---- flake.lock | 7 ++++++ flake.nix | 44 ++++++++++++++++++++++++++--------- tmpl/flake.lock | 52 ++++++++++++++++++++++++++++++++++++++++++ tmpl/flake.nix | 6 ++--- tmpl/flake/outputs.nix | 3 ++- 6 files changed, 121 insertions(+), 20 deletions(-) create mode 100644 flake.lock create mode 100644 tmpl/flake.lock diff --git a/desys.nix b/desys.nix index dd906e0..eda321c 100644 --- a/desys.nix +++ b/desys.nix @@ -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 diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..5999137 --- /dev/null +++ b/flake.lock @@ -0,0 +1,7 @@ +{ + "nodes": { + "root": {} + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix index f174a2b..4b013f3 100644 --- a/flake.nix +++ b/flake.nix @@ -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; diff --git a/tmpl/flake.lock b/tmpl/flake.lock new file mode 100644 index 0000000..0523ad7 --- /dev/null +++ b/tmpl/flake.lock @@ -0,0 +1,52 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1658644204, + "narHash": "sha256-MWyfCH9K3eVTXJUxBi67OQSAh9jJAnvWklM6qm4j8w8=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "2f0c3be57c348f4cfd8820f2d189e29a685d9c41", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "type": "indirect" + } + }, + "nosys": { + "locked": { + "lastModified": 0, + "narHash": "sha256-BknMF5c0D0XghBIyFpqJ12VX2FzVrGtTe0+HLrB36E4=", + "path": "../.", + "type": "path" + }, + "original": { + "path": "../.", + "type": "path" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs", + "nosys": "nosys", + "systems": "systems" + } + }, + "systems": { + "flake": false, + "locked": { + "lastModified": 1, + "narHash": "sha256-4UCfLMxAeGNJiUoJIdMQRx+I5ivP/b8N5FFJ1xlK3Hg=", + "path": "./flake/systems.nix", + "type": "path" + }, + "original": { + "path": "./flake/systems.nix", + "type": "path" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/tmpl/flake.nix b/tmpl/flake.nix index 10b3beb..35b06f4 100644 --- a/tmpl/flake.nix +++ b/tmpl/flake.nix @@ -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; } diff --git a/tmpl/flake/outputs.nix b/tmpl/flake/outputs.nix index dcb1e81..256b25b 100644 --- a/tmpl/flake/outputs.nix +++ b/tmpl/flake/outputs.nix @@ -1,2 +1,3 @@ -{self, ...}: { +{self, nixpkgs, ...}: { + packages = {inherit (nixpkgs.legacyPackages) hello;}; }