about summary refs log tree commit diff
path: root/tvix/nix-compat/src/store_path/mod.rs
diff options
context:
space:
mode:
authoredef <edef@edef.eu>2023-10-04T17·04+0000
committerclbot <clbot@tvl.fyi>2023-10-04T17·18+0000
commit155f53b264436c012efc272b45f6fb4532c09338 (patch)
treee337cc95b682e5f74856f13369bd2b22a165ebab /tvix/nix-compat/src/store_path/mod.rs
parent9a7c078a69bd73af0d03eb37d3b168cbec64fff2 (diff)
fix(tvix/nix-compat): reject dotfiles r/6690
Nix has historically rejected these. The current behaviour was
accidentally introduced in Nix 2.4, and is considered a bug.

Link: https://github.com/NixOS/nix/pull/9095
Change-Id: I38ffa911f0a413086479bd972de09671dbe85121
Reviewed-on: https://cl.tvl.fyi/c/depot/+/9507
Reviewed-by: flokli <flokli@flokli.de>
Tested-by: BuildkiteCI
Autosubmit: edef <edef@edef.eu>
Diffstat (limited to 'tvix/nix-compat/src/store_path/mod.rs')
-rw-r--r--tvix/nix-compat/src/store_path/mod.rs12
1 files changed, 7 insertions, 5 deletions
diff --git a/tvix/nix-compat/src/store_path/mod.rs b/tvix/nix-compat/src/store_path/mod.rs
index b68a4f317189..d3317b67f62e 100644
--- a/tvix/nix-compat/src/store_path/mod.rs
+++ b/tvix/nix-compat/src/store_path/mod.rs
@@ -163,9 +163,9 @@ pub(crate) fn validate_name(s: &[u8]) -> Result<String, Error> {
 
     for (i, c) in s.iter().enumerate() {
         if c.is_ascii_alphanumeric()
+            || (*c == b'.' && i != 0) // can't start with a dot
             || *c == b'-'
             || *c == b'_'
-            || *c == b'.'
             || *c == b'+'
             || *c == b'?'
             || *c == b'='
@@ -221,13 +221,15 @@ mod tests {
         assert_eq!(example_nix_path_str, nixpath.to_string())
     }
 
-    /// This is the store path produced after `nix-store --add`'ing an
+    /// This is the store path rejected when `nix-store --add`'ing an
     /// empty `.gitignore` file.
+    ///
+    /// Nix 2.4 accidentally dropped this behaviour, but this is considered a bug.
+    /// See https://github.com/NixOS/nix/pull/9095.
     #[test]
     fn starts_with_dot() {
-        let nix_path_str = "fli4bwscgna7lpm7v5xgnjxrxh0yc7ra-.gitignore";
-        let nixpath = StorePath::from_bytes(nix_path_str.as_bytes()).expect("must succeed");
-        assert_eq!(".gitignore", nixpath.name);
+        StorePath::from_bytes(b"fli4bwscgna7lpm7v5xgnjxrxh0yc7ra-.gitignore")
+            .expect_err("must fail");
     }
 
     #[test]