Skip to content

Commit

Permalink
[nix] clean up some nix dirty code
Browse files Browse the repository at this point in the history
See chipsalliance/t1#817.

Signed-off-by: Avimitin <dev@avimit.in>
  • Loading branch information
Avimitin committed Oct 26, 2024
1 parent 61b6985 commit c7c41fb
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 33 deletions.
28 changes: 9 additions & 19 deletions templates/chisel/nix/overlay.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,22 @@

final: prev: {
espresso = final.callPackage ./pkgs/espresso.nix { };

mill =
let jre = final.jdk21;
in (prev.mill.override { inherit jre; }).overrideAttrs
(_: { passthru = { inherit jre; }; });

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

circt-full = final.callPackage ./pkgs/circt-full.nix { };
add-determinism =
final.callPackage ./pkgs/add-determinism { }; # faster strip-undetereminism

# Using VCS need to set VC_STATIC_HOME and SNPSLMD_LICENSE_FILE to impure env, and add sandbox dir to VC_STATIC_HOME
# Remember to add "--impure" flag for nix to read this value from environment
vcStaticHome = builtins.getEnv "VC_STATIC_HOME";
snpslmdLicenseFile = builtins.getEnv "SNPSLMD_LICENSE_FILE";
vcs-fhs-env = assert final.lib.assertMsg (final.vcStaticHome != "")
"You forget to set VC_STATIC_HOME or the '--impure' flag";
assert final.lib.assertMsg (final.snpslmdLicenseFile != "")
"You forget to set SNPSLMD_LICENSE_FILE or the '--impure' flag";
final.callPackage ./pkgs/vcs-fhs-env.nix { };
jasperHome = builtins.getEnv "JASPER_HOME";
cdsLicenseFile = builtins.getEnv "CDS_LIC_FILE";
cds-fhs-env = assert final.lib.assertMsg (final.jasperHome != "")
"You forget to set JASPER_HOME or the '--impure' flag";
assert final.lib.assertMsg (final.cdsLicenseFile != "")
"You forget to set CDS_LIC_FILE or the '--impure' flag";
final.callPackage ./pkgs/cds-fhs-env.nix { };

# faster strip-undetereminism
add-determinism = final.callPackage ./pkgs/add-determinism { };

vcs-fhs-env = final.callPackage ./pkgs/vcs-fhs-env.nix { };

cds-fhs-env = final.callPackage ./pkgs/cds-fhs-env.nix { };

projectDependencies = final.callPackage ./pkgs/project-dependencies.nix { };

Expand Down
21 changes: 14 additions & 7 deletions templates/chisel/nix/pkgs/cds-fhs-env.nix
Original file line number Diff line number Diff line change
@@ -1,27 +1,34 @@
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: 2024 Jiuyang Liu <liu@jiuyang.me>
{ jasperHome
, cdsLicenseFile
{ lib
, fetchFromGitHub
}:
let
nixpkgsSrcs = fetchFromGitHub {
owner = "NixOS";
repo = "nixpkgs";
"rev" = "c374d94f1536013ca8e92341b540eba4c22f9c62";
"hash" = "sha256-Z/ELQhrSd7bMzTO8r7NZgi9g5emh+aRKoCdaAv5fiO0=";
rev = "c374d94f1536013ca8e92341b540eba4c22f9c62";
hash = "sha256-Z/ELQhrSd7bMzTO8r7NZgi9g5emh+aRKoCdaAv5fiO0=";
};

# The cds we have only support x86-64_linux
lockedPkgs = import nixpkgsSrcs { system = "x86_64-linux"; };

jasperHome = builtins.getEnv "JASPER_HOME";
cdsLicenseFile = builtins.getEnv "CDS_LIC_FILE";
in
assert lib.assertMsg (jasperHome != "")
"You forget to set JASPER_HOME or the '--impure' flag";
assert lib.assertMsg (cdsLicenseFile != "")
"You forget to set CDS_LIC_FILE or the '--impure' flag";

lockedPkgs.buildFHSEnv {
name = "cds-fhs-env";

profile = ''
[ ! -e "${jasperHome}" ] && echo "env JASPER_HOME not set" && exit 1
[ ! -d "${jasperHome}" ] && echo "JASPER_HOME not accessible" && exit 1
[ -z "${cdsLicenseFile}" ] && echo "env CDS_LIC_FILE not set" && exit 1
[ ! -e "${jasperHome}" ] && echo "env JASPER_HOME='${jasperHome}' points to unknown location" && exit 1
[ ! -d "${jasperHome}" ] && echo "env JASPER_HOME='${jasperHome}' not accessible" && exit 1
export JASPER_HOME=${jasperHome}
export CDS_LIC_FILE=${cdsLicenseFile}
export PATH=$JASPER_HOME/bin:$PATH
Expand Down
21 changes: 14 additions & 7 deletions templates/chisel/nix/pkgs/vcs-fhs-env.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,35 @@
#
# For convenience, we still use the nixpkgs defined in flake to "callPackage" this derivation.
# But the buildFHSEnv, targetPkgs is still from the locked nixpkgs.
{ vcStaticHome
, snpslmdLicenseFile
{ lib
, fetchFromGitHub
}:
let
nixpkgsSrcs = fetchFromGitHub {
owner = "NixOS";
repo = "nixpkgs";
"rev" = "c374d94f1536013ca8e92341b540eba4c22f9c62";
"hash" = "sha256-Z/ELQhrSd7bMzTO8r7NZgi9g5emh+aRKoCdaAv5fiO0=";
rev = "c374d94f1536013ca8e92341b540eba4c22f9c62";
hash = "sha256-Z/ELQhrSd7bMzTO8r7NZgi9g5emh+aRKoCdaAv5fiO0=";
};

# The vcs we have only support x86-64_linux
lockedPkgs = import nixpkgsSrcs { system = "x86_64-linux"; };

vcStaticHome = builtins.getEnv "VC_STATIC_HOME";
snpslmdLicenseFile = builtins.getEnv "SNPSLMD_LICENSE_FILE";
in
assert lib.assertMsg (vcStaticHome != "")
"You forget to set VC_STATIC_HOME or the '--impure' flag";
assert lib.assertMsg (snpslmdLicenseFile != "")
"You forget to set SNPSLMD_LICENSE_FILE or the '--impure' flag";

lockedPkgs.buildFHSEnv {
name = "vcs-fhs-env";

profile = ''
[ ! -e "${vcStaticHome}" ] && echo "env VC_STATIC_HOME not set" && exit 1
[ ! -d "${vcStaticHome}" ] && echo "VC_STATIC_HOME not accessible" && exit 1
[ -z "${snpslmdLicenseFile}" ] && echo "env SNPS LICENSE not set" && exit 1
[ ! -e "${vcStaticHome}" ] && echo "env VC_STATIC_HOME='${vcStaticHome}' points to unknown location" && exit 1
[ ! -d "${vcStaticHome}" ] && echo "VC_STATIC_HOME='${vcStaticHome}' not accessible" && exit 1
export VC_STATIC_HOME=${vcStaticHome}
export TCL_TZ=UTC
Expand Down

0 comments on commit c7c41fb

Please sign in to comment.