aboutsummaryrefslogtreecommitdiff
path: root/src/lib.rs
diff options
context:
space:
mode:
authorstuebinm2025-05-04 16:04:07 +0200
committerstuebinm2025-05-04 17:05:05 +0200
commit98b947c731f4f74119e208cfe16df90181991a48 (patch)
treebf50d87ef79e1251d2f7384e078f06341af804c0 /src/lib.rs
parentaa07eb05537d4cd025e2310397a6adcedfe72c76 (diff)
allow non-flake builds with flake-enabled nixnonflake-build-flag
This adds a --file option, which causes deploy-rs to always use its non-flake logic. Before this change, we would ask nix if it understood flakes, and only if not fall back to the non-flake logic. This has utility assuming one has a nix flake repository with flake-compat set up, but prevents use with alternative source-managing tools such as niv or npins if nix has the "flakes" experimental feature enabled.
Diffstat (limited to '')
-rw-r--r--src/lib.rs59
1 files changed, 59 insertions, 0 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 61fac6a..0ff9576 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -315,6 +315,65 @@ fn test_parse_flake() {
);
}
+pub fn parse_file<'a>(file: &'a str, attribute: &'a str) -> Result<DeployFlake<'a>, ParseFlakeError> {
+ let repo = file; //format!("./{file}");
+
+ let mut node: Option<String> = None;
+ let mut profile: Option<String> = None;
+
+ let ast = rnix::parse(attribute);
+
+ let first_child = match ast.root().node().first_child() {
+ Some(x) => x,
+ None => {
+ return Ok(DeployFlake {
+ repo: &repo,
+ node: None,
+ profile: None,
+ })
+ }
+ };
+
+ let mut node_over = false;
+
+ for entry in first_child.children_with_tokens() {
+ let x: Option<String> = match (entry.kind(), node_over) {
+ (TOKEN_DOT, false) => {
+ node_over = true;
+ None
+ }
+ (TOKEN_DOT, true) => {
+ return Err(ParseFlakeError::PathTooLong);
+ }
+ (NODE_IDENT, _) => Some(entry.into_node().unwrap().text().to_string()),
+ (TOKEN_IDENT, _) => Some(entry.into_token().unwrap().text().to_string()),
+ (NODE_STRING, _) => {
+ let c = entry
+ .into_node()
+ .unwrap()
+ .children_with_tokens()
+ .nth(1)
+ .unwrap();
+
+ Some(c.into_token().unwrap().text().to_string())
+ }
+ _ => return Err(ParseFlakeError::Unrecognized),
+ };
+
+ if !node_over {
+ node = x;
+ } else {
+ profile = x;
+ }
+ }
+
+ Ok(DeployFlake {
+ repo: &repo,
+ node,
+ profile,
+ })
+}
+
#[derive(Debug, Clone)]
pub struct DeployData<'a> {
pub node_name: &'a str,