From eaf1c3ff300ab0b38ede67ac44aa95ec7c46ef45 Mon Sep 17 00:00:00 2001 From: Avimitin Date: Sun, 27 Oct 2024 00:44:15 +0800 Subject: [PATCH] [nix] clean up impure env Yesterday I reviewed my nix code and found that this ugly part can be immediately improved. These env should not have top level binding and evaluate with empty value everytime if "--impure" does not supply. There should be value bind to them when they get evaluated, or they should never exist in our nixpkgs namespace. Signed-off-by: Avimitin --- nix/overlay.nix | 8 ++------ nix/pkgs/vcs-fhs-env.nix | 27 ++++++++++++++++++--------- 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/nix/overlay.nix b/nix/overlay.nix index d6c81428b..522cb87db 100644 --- a/nix/overlay.nix +++ b/nix/overlay.nix @@ -27,12 +27,8 @@ rec { circt-full = final.callPackage ./pkgs/circt-full.nix { }; rvv-codegen = final.callPackage ./pkgs/rvv-codegen.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 - vcStaticHome = builtins.getEnv "VC_STATIC_HOME"; - snpslmdLicenseFile = builtins.getEnv "SNPSLMD_LICENSE_FILE"; - vcs-fhs-env = assert final.lib.assertMsg (final.vcStaticHome != "") "No $VC_STATIC_HOME or '--impure' applied"; - assert final.lib.assertMsg (final.snpslmdLicenseFile != "") "No $SNPSLMD_LICENSE_FILE or '--impure' applied"; - final.callPackage ./pkgs/vcs-fhs-env.nix { }; + + vcs-fhs-env = final.callPackage ./pkgs/vcs-fhs-env.nix { }; mill = let jre = final.jdk21; in (prev.mill.override { inherit jre; }).overrideAttrs (_: { diff --git a/nix/pkgs/vcs-fhs-env.nix b/nix/pkgs/vcs-fhs-env.nix index a9becb664..cf6329192 100644 --- a/nix/pkgs/vcs-fhs-env.nix +++ b/nix/pkgs/vcs-fhs-env.nix @@ -4,28 +4,37 @@ # # 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 -}: +{ lib, fetchFromGitHub }: let nixpkgsSrcs = fetchFromGitHub { owner = "NixOS"; repo = "nixpkgs"; - "rev" = "574d1eac1c200690e27b8eb4e24887f8df7ac27c"; - "hash" = "sha256-v3rIhsJBOMLR8e/RNWxr828tB+WywYIoajrZKFM+0Gg="; + rev = "574d1eac1c200690e27b8eb4e24887f8df7ac27c"; + hash = "sha256-v3rIhsJBOMLR8e/RNWxr828tB+WywYIoajrZKFM+0Gg="; }; # The vcs we have only support x86-64_linux lockedPkgs = import nixpkgsSrcs { system = "x86_64-linux"; }; + + getEnv' = key: + let + val = builtins.getEnv key; + in + if val == "" then + builtins.throw "${key} not set or '--impure' not applied" + else val; + + # Using VCS need to set VC_STATIC_HOME and SNPSLMD_LICENSE_FILE to impure env, and add sandbox dir to VC_STATIC_HOME + 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