Bladeren bron

nixpkgs/elvish: rework direlv env filtering

The NIX_ environment variables are significant when compiling things
with rust for example. But there are a lot and it's super noisy so
include them but don't print out the names when applying.
Thomas Dy 9 maanden geleden
bovenliggende
commit
ca5e350fbc
1 gewijzigde bestanden met toevoegingen van 58 en 19 verwijderingen
  1. 58 19
      .config/nixpkgs/elvish/lib/direlv.elv

+ 58 - 19
.config/nixpkgs/elvish/lib/direlv.elv

@@ -37,34 +37,55 @@ fn state-type {|@a|
 
 var state-dir = (get-env XDG_STATE_HOME &default=~/.local/state)/direlv
 var dir-stack = []
-var ignore = [
+var quiet = [
   AR
+  AR_FOR_TARGET
   AS
+  AS_FOR_TARGET
   CC
-  CONFIG_SHELL
+  CC_FOR_TARGET
   CXX
-  HOME
-  HOST_PATH
+  CXX_FOR_TARGET
   LD
-  LD_DYLD_PATH
-  MACOSX_DEPLOYMENT_TARGET
+  LD_FOR_TARGET
   NM
-  OBJCOPY
-  OBJDUMP
-  OLDPWD
+  NM_FOR_TARGET
   RANLIB
-  READELF
-  SHELL
+  RANLIB_FOR_TARGET
   SIZE
-  SOURCE_DATE_EPOCH
+  SIZE_FOR_TARGET
   STRINGS
+  STRINGS_FOR_TARGET
   STRIP
+  STRIP_FOR_TARGET
+
+  READELF
+  OBJCOPY
+  OBJDUMP
+
+  MACOSX_DEPLOYMENT_TARGET
+
+  CONFIG_SHELL
+  HOST_PATH
+]
+var ignore = [
+  # keep user variables
+  HOME
+  OLDPWD
+  SHELL
   TEMP
   TEMPDIR
   TERM
   TMP
   TMPDIR
   TZ
+
+  # purity-related envs
+  NIX_ENFORCE_PURITY
+  SOURCE_DATE_EPOCH
+  ZERO_AR_DATE
+
+  # nix build variables
   buildInputs
   buildPhase
   builder
@@ -88,6 +109,7 @@ var ignore = [
   outputs
   patches
   phases
+  preferLocalBuild
   propagatedBuildInputs
   propagatedNativeBuildInputs
   shell
@@ -109,17 +131,33 @@ fn diff-env {|env|
   } $env
 }
 
+fn print-change {|key new|
+  if (has-value $quiet $key) {
+    return
+  }
+
+  if (str:has-prefix $key "NIX_") {
+    return
+  }
+
+  if $new {
+    put +$key
+  } else {
+    put -$key
+  }
+}
+
 fn apply-env {|env|
   each {|row|
     var key value = (all $row)
     if (eq $value $nil) {
-      put -$key
+      print-change $key $false
       unset-env $key
     } else {
-      put +$key
+      print-change $key $true
       set-env $key $value
     }
-  } $env
+  } $env | compact
 }
 
 fn env-from-nix-flake {|state-file|
@@ -127,15 +165,16 @@ fn env-from-nix-flake {|state-file|
   keys $data[variables] | each {|key|
     var v = $data[variables][$key]
     if (eq $v[type] "exported") {
-      if (str:has-prefix $key "NIX_") {
-        continue
-      } elif (str:has-prefix $key "__") {
+      if (str:has-prefix $key "__") {
         continue
       } elif (has-value $ignore $key) {
         continue
       } elif (has-value $extend $key) {
-        var existing = (get-env $key)
         var extended = $v[value]
+        if (eq $extended "") {
+          continue
+        }
+        var existing = (get-env $key)
         if (not-eq $existing $nil) {
           set extended = $extended":"$existing
         }