Support attribute sets with string keys

This commit is contained in:
commiterate 2025-03-28 22:53:27 -04:00
parent 1027975497
commit 1b55512e1e
3 changed files with 33 additions and 1 deletions

View file

@ -21,6 +21,7 @@ let
./Cargo.toml ./Cargo.toml
./Cargo.lock ./Cargo.lock
./src ./src
./test/rust
]; ];
}; };
@ -32,10 +33,16 @@ let
nativeCheckInputs = [ nativeCheckInputs = [
clippy clippy
nix
]; ];
preCheck = '' preCheck = ''
${lib.getExe pkgs.cargo} clippy ${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(format!("{flake}#{FLAKE_ATTR}"))
.arg("--json") .arg("--json")
.arg("--apply") .arg("--apply")
.arg(format!("a: a ? \"{attr}\"")); .arg(format!("_: _ ? {attr}"));
log::debug!("Running nix command: {cmd:?}"); log::debug!("Running nix command: {cmd:?}");
@ -197,3 +197,19 @@ fn nix_cmd(nix_options: &NixOptions) -> process::Command {
}); });
cmd 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";
};
};
}