Skip to content

Commit

Permalink
Golf the zephyr modules derivation some more
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisandreae committed Feb 10, 2024
1 parent aa6f052 commit b0121d7
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 15 deletions.
36 changes: 22 additions & 14 deletions nix/zephyr.nix
Original file line number Diff line number Diff line change
@@ -1,31 +1,39 @@
{ stdenv, lib, fetchgit, runCommand }:
{ stdenvNoCC, lib, fetchgit, runCommand }:
let
manifestJSON = builtins.fromJSON (builtins.readFile ./manifest.json);

projects = lib.listToAttrs (lib.forEach manifestJSON ({ name, revision, url, sha256, ... }@args: (
lib.nameValuePair name (let
mkModule = { name, revision, url, sha256, ... }:
stdenvNoCC.mkDerivation (finalAttrs: {
name = "zmk-module-${name}";

src = fetchgit {
inherit name url sha256;
rev = revision;
};
module = runCommand "zephyr-module-${name}" {
passthru = {
inherit name src;
modulePath = "${module}/${name}";
};
} ''

dontUnpack = true;
dontBuild = true;

installPhase = ''
mkdir $out
ln -s ${src} $out/${name}
ln -s ${finalAttrs.src} $out/${name}
'';
in module))));

passthru = {
modulePath = "${finalAttrs.finalPackage}/${name}";
};
});

modules = lib.listToAttrs (lib.forEach manifestJSON ({ name, ... }@args:
lib.nameValuePair name (mkModule args)));
in


# Zephyr with no modules, from the frozen manifest.
# For now the modules are passed through as passthru
stdenv.mkDerivation {
stdenvNoCC.mkDerivation {
name = "zephyr";
src = projects.zephyr.src;
src = modules.zephyr.src;

dontBuild = true;

Expand All @@ -39,6 +47,6 @@ stdenv.mkDerivation {
'';

passthru = {
modules = lib.attrValues (removeAttrs projects ["zephyr"]);
modules = removeAttrs modules ["zephyr"];
};
}
2 changes: 1 addition & 1 deletion nix/zmk.nix
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ let
];

zephyrModuleDeps =
let modules = builtins.filter (x: builtins.elem x.name requiredZephyrModules) zephyr.modules;
let modules = lib.attrVals requiredZephyrModules zephyr.modules;
in map (x: x.modulePath) modules;
in

Expand Down

0 comments on commit b0121d7

Please sign in to comment.