Merge pull request #220 from commiterate/support_attrset_string_key

Support attribute sets with string keys
This commit is contained in:
[eureka@nixos] 2025-04-08 12:12:08 -07:00 committed by GitHub
commit 803322102e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 33 additions and 1 deletions

View file

@ -21,6 +21,7 @@ let
./Cargo.toml
./Cargo.lock
./src
./test/rust
];
};
@ -32,10 +33,16 @@ let
nativeCheckInputs = [
clippy
nix
];
preCheck = ''
${lib.getExe pkgs.cargo} clippy
# Stop the Nix command from trying to create /nix/var/nix/profiles.
#
# https://nix.dev/manual/nix/2.24/command-ref/new-cli/nix3-profile#profiles
export NIX_STATE_DIR=$TMPDIR
'';
}
) { };

View file

@ -173,7 +173,7 @@ fn try_nix_eval(flake: &str, attr: &str, nix_options: &NixOptions) -> Result<boo
.arg(format!("{flake}#{FLAKE_ATTR}"))
.arg("--json")
.arg("--apply")
.arg(format!("a: a ? \"{attr}\""));
.arg(format!("_: _ ? {attr}"));
log::debug!("Running nix command: {cmd:?}");
@ -197,3 +197,19 @@ fn nix_cmd(nix_options: &NixOptions) -> process::Command {
});
cmd
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_try_nix_eval() {
let flake = "./test/rust/register";
let nix_options = &NixOptions::new(vec![]);
assert!(try_nix_eval(flake, "identifier-key", nix_options).unwrap());
assert!(try_nix_eval(flake, "\"string.literal/key\"", nix_options).unwrap());
assert!(!try_nix_eval(flake, "_identifier-key", nix_options).unwrap());
assert!(!try_nix_eval(flake, "\"_string.literal/key\"", nix_options).unwrap());
}
}

View file

@ -0,0 +1,9 @@
{
inputs = { };
outputs = inputs: {
systemConfigs = {
identifier-key = "value";
"string.literal/key" = "value";
};
};
}