Skip to content

Commit

Permalink
[nix] use mill flow overlay
Browse files Browse the repository at this point in the history
Signed-off-by: unlsycn <unlsycn@unlsycn.com>
  • Loading branch information
unlsycn committed Feb 9, 2025
1 parent 2d3573a commit 4f3469d
Show file tree
Hide file tree
Showing 9 changed files with 74 additions and 181 deletions.
22 changes: 19 additions & 3 deletions templates/chisel/flake.lock

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

5 changes: 3 additions & 2 deletions templates/chisel/flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
chisel-nix.url = "github:chipsalliance/chisel-nix";
};

outputs = inputs@{ self, nixpkgs, flake-utils }:
outputs = inputs@{ self, nixpkgs, flake-utils, chisel-nix }:
let overlay = import ./nix/overlay.nix;
in {
# System-independent attr
Expand All @@ -17,7 +18,7 @@
} // flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs {
overlays = [ overlay ];
overlays = [ overlay chisel-nix.overlays.mill-flows ];
inherit system;
};
in
Expand Down
38 changes: 6 additions & 32 deletions templates/chisel/nix/gcd/gcd.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
{ lib
, stdenv
, fetchMillDeps
, publishMillModule
, makeWrapper
, jdk21
, git

# chisel deps
, mill-dependencies
, mill
, espresso
, circt-full
Expand All @@ -20,19 +20,6 @@
}:

let
chisel =
publishMillModule {
name = "chisel";
version = "9999";
outputHash =
if stdenv.hostPlatform.isDarwin then
"sha256-wXDmafSEoJxg1mv6uleKtRDCuFuTdEt+FmiH6NO7anc="
else
"sha256-vmuJyLQrgAe2ffMNxzKKUygk4WGoxHjq0cR1o+wZ0u8=";
publishPhase = "mill -i unipublish.publishLocal";
nativeBuildInputs = [ git ];
};

self = stdenv.mkDerivation rec {
name = "gcd";

Expand All @@ -57,39 +44,26 @@ let
root = ./../..;
fileset = unions [ ./../../build.mill ./../../common.mill ];
};
millDepModules = [ chisel ];
millDepsHash =
if stdenv.hostPlatform.isDarwin then
"sha256-saHZcLBulNESco16mqwgiPndFA/V+4uexnqgLCinuWs="
else
"sha256-MA8Yx99ItVRhNPB/LigwCaTMywrJF3JEYv3fSeWdeNk=";
buildInputs = with mill-dependencies; [ chisel.setupHook ];
millDepsHash = "sha256-NybS2AXRQtXkgHd5nH4Ltq3sxZr5aZ4VepiT79o1AWo=";
};

editable = self.overrideAttrs (_: {
shellHook = ''
setupSubmodulesEditable
mill mill.bsp.BSP/install 0
'';
});

inherit target;
inherit env;
};

shellHook = ''
setupSubmodules
'';
nativeBuildInputs = with mill-dependencies; [
makeWrapper

nativeBuildInputs = [
mill
circt-full
jextract-21
add-determinism
espresso
git

makeWrapper
passthru.millDeps.setupHook
chisel.setupHook
];

env = {
Expand Down
4 changes: 1 addition & 3 deletions templates/chisel/nix/overlay.nix
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ final: prev: {
in (prev.mill.override { inherit jre; }).overrideAttrs
(_: { passthru = { inherit jre; }; });

fetchMillDeps = final.callPackage ./pkgs/mill-builder.nix { };

publishMillModule = final.callPackage ./pkgs/dependencies { };
mill-dependencies = final.callPackage ./pkgs/dependencies { };

circt-full = final.callPackage ./pkgs/circt-full.nix { };

Expand Down
11 changes: 6 additions & 5 deletions templates/chisel/nix/pkgs/dependencies/_sources/generated.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"chisel": {
"cargoLocks": null,
"date": "2025-01-09",
"date": "2025-02-10",
"extract": null,
"name": "chisel",
"passthru": null,
Expand All @@ -11,12 +11,13 @@
"fetchSubmodules": false,
"leaveDotGit": false,
"name": null,
"owner": "unlsycn",
"owner": "chipsalliance",
"repo": "chisel",
"rev": "ea01f89d39c138bc4c260baf5e8e088e120f4265",
"sha256": "sha256-KNcAgOA/YBt+1QOVXGpK/33BZ8PpDcHDdAnIBDLfSqI=",
"rev": "840c95e2bb8321346da4d832c8d9dd43bf997be7",
"sha256": "sha256-YWmqj7YxqyiLjijFVZ28PrAuaOac9j/XRhF01zGQKBk=",
"sparseCheckout": [],
"type": "github"
},
"version": "ea01f89d39c138bc4c260baf5e8e088e120f4265"
"version": "840c95e2bb8321346da4d832c8d9dd43bf997be7"
}
}
10 changes: 5 additions & 5 deletions templates/chisel/nix/pkgs/dependencies/_sources/generated.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
{
chisel = {
pname = "chisel";
version = "ea01f89d39c138bc4c260baf5e8e088e120f4265";
version = "840c95e2bb8321346da4d832c8d9dd43bf997be7";
src = fetchFromGitHub {
owner = "unlsycn";
owner = "chipsalliance";
repo = "chisel";
rev = "ea01f89d39c138bc4c260baf5e8e088e120f4265";
rev = "840c95e2bb8321346da4d832c8d9dd43bf997be7";
fetchSubmodules = false;
sha256 = "sha256-KNcAgOA/YBt+1QOVXGpK/33BZ8PpDcHDdAnIBDLfSqI=";
sha256 = "sha256-YWmqj7YxqyiLjijFVZ28PrAuaOac9j/XRhF01zGQKBk=";
};
date = "2025-01-09";
date = "2025-02-10";
};
}
77 changes: 31 additions & 46 deletions templates/chisel/nix/pkgs/dependencies/default.nix
Original file line number Diff line number Diff line change
@@ -1,52 +1,37 @@
{ pkgs
, stdenv
, mill
, add-determinism
, lib
, newScope
, fetchMillDeps
, publishMillJar
, git
, ...
}:
{ name
, version
, outputHash
, publishPhase
, ...
}@args:
let
dependencies = pkgs.callPackage ./_sources/generated.nix { };
in
stdenv.mkDerivation {
pname = name;
src = dependencies.${name}.src;

inherit version outputHash;

outputHashAlgo = "sha256";
outputHashMode = "recursive";

nativeBuildInputs = [ mill ] ++ (args.nativeBuildInputs or [ ]);

impureEnvVars = [ "JAVA_OPTS" ];

buildPhase = ''
runHook preBuild
echo "-Duser.home=$TMPDIR -Divy.home=$TMPDIR/ivy $JAVA_OPTS" | tr ' ' '\n' > mill-java-opts
export MILL_JVM_OPTS_PATH=$PWD/mill-java-opts
# Use "https://repo1.maven.org/maven2/" only to keep dependencies integrity
export COURSIER_REPOSITORIES="ivy2Local|central"
${publishPhase}
runHook postBuild
'';

installPhase = ''
runHook preInstall
mkdir -p $out/.ivy2
mv $TMPDIR/ivy/local $out/.ivy2/local
export SOURCE_DATE_EPOCH=1669810380
find $out -type f -name '*.jar' -exec '${add-determinism}/bin/add-determinism' -j "$NIX_BUILD_CORES" '{}' ';'
runHook postInstall
'';
}
lib.makeScope newScope (scope: {
chisel =
let
chiselDeps = fetchMillDeps {
name = "chisel";
src = dependencies.chisel.src;
fetchTargets = [ "unipublish" ];
nativeBuildInputs = [
git
];
millDepsHash = "sha256-alJbV8DhbocsFdC+qlUJeNrkq2/y5Vml7fIkCabEmT8=";
};
in
publishMillJar {
name = "chisel";
src = dependencies.chisel.src;
publishTargets = [ "unipublish" ];
buildInputs = [ chiselDeps.setupHook ];
nativeBuildInputs = [
git
];
passthru = {
inherit chiselDeps;
};
};
})
6 changes: 3 additions & 3 deletions templates/chisel/nix/pkgs/dependencies/nvfetcher.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[chisel]
src.git = "https://github.com/unlsycn/chisel"
src.branch = "mill-bump"
fetch.github = "unlsycn/chisel"
src.git = "https://github.com/chipsalliance/chisel"
src.branch = "main"
fetch.github = "chipsalliance/chisel"
82 changes: 0 additions & 82 deletions templates/chisel/nix/pkgs/mill-builder.nix

This file was deleted.

0 comments on commit 4f3469d

Please sign in to comment.