From c7c41fbfc390dfefc85292596b05826988029b42 Mon Sep 17 00:00:00 2001 From: Avimitin Date: Sun, 27 Oct 2024 00:55:25 +0800 Subject: [PATCH] [nix] clean up some nix dirty code See https://github.com/chipsalliance/t1/pull/817. Signed-off-by: Avimitin --- templates/chisel/nix/overlay.nix | 28 ++++++++--------------- templates/chisel/nix/pkgs/cds-fhs-env.nix | 21 +++++++++++------ templates/chisel/nix/pkgs/vcs-fhs-env.nix | 21 +++++++++++------ 3 files changed, 37 insertions(+), 33 deletions(-) diff --git a/templates/chisel/nix/overlay.nix b/templates/chisel/nix/overlay.nix index c5f2512..123e4ff 100644 --- a/templates/chisel/nix/overlay.nix +++ b/templates/chisel/nix/overlay.nix @@ -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 { }; diff --git a/templates/chisel/nix/pkgs/cds-fhs-env.nix b/templates/chisel/nix/pkgs/cds-fhs-env.nix index af95332..fa53b82 100644 --- a/templates/chisel/nix/pkgs/cds-fhs-env.nix +++ b/templates/chisel/nix/pkgs/cds-fhs-env.nix @@ -1,27 +1,34 @@ # SPDX-License-Identifier: Apache-2.0 # SPDX-FileCopyrightText: 2024 Jiuyang Liu -{ 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 diff --git a/templates/chisel/nix/pkgs/vcs-fhs-env.nix b/templates/chisel/nix/pkgs/vcs-fhs-env.nix index 3a86c5f..40c0e9b 100644 --- a/templates/chisel/nix/pkgs/vcs-fhs-env.nix +++ b/templates/chisel/nix/pkgs/vcs-fhs-env.nix @@ -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