Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[nix] clean up some nix dirty code #53

Merged
merged 1 commit into from
Oct 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 18 additions & 19 deletions templates/chisel/nix/overlay.nix
Original file line number Diff line number Diff line change
@@ -1,34 +1,33 @@
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: 2024 Jiuyang Liu <[email protected]>

let
getEnv' = key:
let
val = builtins.getEnv key;
in
if val == "" then
builtins.throw "${key} not set or '--impure' not applied"
else val;
in
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 { inherit getEnv'; };

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

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

Expand Down
16 changes: 9 additions & 7 deletions templates/chisel/nix/pkgs/cds-fhs-env.nix
Original file line number Diff line number Diff line change
@@ -1,27 +1,29 @@
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: 2024 Jiuyang Liu <[email protected]>
{ jasperHome
, cdsLicenseFile
{ getEnv'
, 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 = getEnv' "JASPER_HOME";
cdsLicenseFile = getEnv' "CDS_LIC_FILE";
in
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
18 changes: 9 additions & 9 deletions templates/chisel/nix/pkgs/vcs-fhs-env.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,28 @@
#
# 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
, fetchFromGitHub
}:
{ getEnv', 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 = getEnv' "VC_STATIC_HOME";
snpslmdLicenseFile = getEnv' "SNPSLMD_LICENSE_FILE";
in
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