Skip to content

Commit

Permalink
[nix] clean up impure env
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
Avimitin committed Oct 26, 2024
1 parent 9d62afd commit eaf1c3f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 15 deletions.
8 changes: 2 additions & 6 deletions nix/overlay.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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 (_: {
Expand Down
27 changes: 18 additions & 9 deletions nix/pkgs/vcs-fhs-env.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit eaf1c3f

Please sign in to comment.