diff --git a/flake.nix b/flake.nix index fa19ecb..fb3111c 100644 --- a/flake.nix +++ b/flake.nix @@ -70,7 +70,17 @@ ); }; devShells.default = pkgs.mkShell { - packages = [ (fusesoc.lib.wrapFusesoc fusesoc.lib.cores) ]; + packages = [ + fusesoc + pkgs.iverilog + pkgs.verilator + pkgs.icestorm + pkgs.yosys + pkgs.nextpnr + ]; + shellHook = '' + export FUSESOC_CONFIG=${fusesoc.lib.mkConf fusesoc.lib.cores} + ''; }; checks = let diff --git a/lib/fusesocLib.nix b/lib/fusesocLib.nix index c7bc9d2..69735e9 100644 --- a/lib/fusesocLib.nix +++ b/lib/fusesocLib.nix @@ -11,6 +11,7 @@ runCommand, stdenv, stdenvNoCC, + writableTmpDirAsHomeHook, writeScriptBin, writeText, }: @@ -48,8 +49,7 @@ rec { else let dropIfMatch = - regex: list: - if (isNull (builtins.match regex (lib.last list))) then list else (lib.dropEnd 1 list); + regex: list: if (isNull (builtins.match regex (lib.last list))) then list else (lib.dropEnd 1 list); dropRevision = dropIfMatch "^r[[:digit:]]+$"; dropVersion = list: if (builtins.length list > 1) then (dropIfMatch ''^[\.0-9]+$'' list) else list; trimmed = dropVersion (dropRevision legacySplit); @@ -259,49 +259,39 @@ rec { coreSet: builtins.concatMap (x: x.value.list or [ x.value ]) (unwrap (unwrap (lib.attrsToList coreSet))); - wrapFusesoc = + mkConf = + cores: let - sanitize = - regex: str: - lib.concatStrings ( - map (x: if (builtins.match regex x) != null then x else "_") (lib.stringToCharacters str) - ); - mkLib = name: path: '' - [library.${sanitize "([a-zA-Z0-9])" name}] - location = ${path} - sync-uri = ${path} - sync-type = local - auto-sync = false - ''; - mkConf = - sources: - writeText "fusesoc.conf" ( - lib.concatLines ( - builtins.foldl' (acc: elem: acc ++ [ (mkLib "${baseNameOf "${elem}"}" elem) ]) [ ] sources - ) - ); + libPath = dumpCores cores; in - sources: - writeScriptBin "fusesoc" '' - export FUSESOC_CONFIG=${mkConf (if builtins.isList sources then sources else (toCoreList sources))} - exec ${fusesoc}/bin/fusesoc $@ + writeText "fusesoc.conf" '' + [library.fusesoc-flake] + location = ${libPath} + sync-url = ${libPath} + sync-type = local + auto-sync = false ''; dumpCores = - coreSet: + cores: + let + coreList = if builtins.isList cores then cores else (toCoreList cores); + in linkFarm "fusesocCores" ( map (x: { inherit (x) name; path = x; - }) (toCoreList coreSet) + }) coreList ); runCore = import ./runCore.nix { inherit + dumpCores + fusesoc lib - stdenv parseVlnv - wrapFusesoc + stdenv + writableTmpDirAsHomeHook ; }; @@ -355,4 +345,13 @@ rec { inherit core coreRoot; coreName = "${(parseVlnv core.name).name}.core"; }; + + wrapFusesoc = + sources: + lib.warn "wrapFusesoc is deprecated, add `export FUSESOC_CONFIG=\${fusesoc.lib.dumpCores coreSet}` to your shellHook instead." ( + writeScriptBin "fusesoc" '' + export FUSESOC_CONFIG=${mkConf sources} + exec ${fusesoc}/bin/fusesoc $@ + '' + ); } diff --git a/lib/runCore.nix b/lib/runCore.nix index d35d634..7a64d70 100644 --- a/lib/runCore.nix +++ b/lib/runCore.nix @@ -1,8 +1,10 @@ { + dumpCores, + fusesoc, lib, - stdenv, parseVlnv, - wrapFusesoc, + stdenv, + writableTmpDirAsHomeHook, }: lib.extendMkDerivation { constructDrv = stdenv.mkDerivation; @@ -29,7 +31,6 @@ lib.extendMkDerivation { opt = str: lib.optional (str != "") str; mapOpts = strs: builtins.concatLists (map opt strs); parsed = parseVlnv finalAttrs.passthru.core.name; - fusesocWrapped = wrapFusesoc finalAttrs.passthru.dependencies; in { pname = @@ -59,14 +60,13 @@ lib.extendMkDerivation { tools ; }; - nativeBuildInputs = finalAttrs.passthru.tools ++ [ fusesocWrapped ]; - phases = [ - "buildPhase" - "installPhase" + nativeBuildInputs = finalAttrs.passthru.tools ++ [ + writableTmpDirAsHomeHook + fusesoc ]; + src = dumpCores finalAttrs.passthru.dependencies; buildPhase = lib.concatStringsSep " " [ - "HOME=$TEMP" - "${fusesocWrapped}/bin/fusesoc" + "fusesoc --cores-root $src" "run --target ${finalAttrs.passthru.target}" finalAttrs.passthru.extraArgs finalAttrs.passthru.core.name