From 6b3e532c670e0a4b7cb0bf4707add1d088ea6884 Mon Sep 17 00:00:00 2001 From: Razvan-Daniel Mihai <84674+razvan@users.noreply.github.com> Date: Mon, 4 Mar 2024 15:53:50 +0100 Subject: [PATCH 1/4] Bump op-rs (#215) --- Cargo.lock | 8 ++++---- Cargo.toml | 22 +++++++++++++++++----- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2629edbb..4cad234e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2681,8 +2681,8 @@ dependencies = [ [[package]] name = "stackable-operator" -version = "0.61.0" -source = "git+https://github.com/stackabletech/operator-rs.git?tag=0.61.0#ddc57addbc741e3977b1589e553164505a59f639" +version = "0.64.0" +source = "git+https://github.com/stackabletech/operator-rs.git?tag=0.64.0#d988822e7af3d363d52fb35643f0c6ed933f340a" dependencies = [ "chrono", "clap", @@ -2720,8 +2720,8 @@ dependencies = [ [[package]] name = "stackable-operator-derive" -version = "0.61.0" -source = "git+https://github.com/stackabletech/operator-rs.git?tag=0.61.0#ddc57addbc741e3977b1589e553164505a59f639" +version = "0.64.0" +source = "git+https://github.com/stackabletech/operator-rs.git?tag=0.64.0#d988822e7af3d363d52fb35643f0c6ed933f340a" dependencies = [ "darling", "proc-macro2", diff --git a/Cargo.toml b/Cargo.toml index 39213904..8202cfe2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,15 +27,22 @@ directories = "5.0" dotenvy = "0.15" futures = "0.3" indexmap = { version = "2.0", features = ["serde"] } -k8s-openapi = { version = "0.20", default-features = false, features = ["v1_28"] } -kube = { version = "0.87", default-features = false, features = ["client", "rustls-tls"] } +k8s-openapi = { version = "0.20", default-features = false, features = [ + "v1_28", +] } +kube = { version = "0.87", default-features = false, features = [ + "client", + "rustls-tls", +] } lazy_static = "1.4" once_cell = "1.18" phf = "0.11" phf_codegen = "0.11" rand = "0.8" regex = "1.9" -reqwest = { version = "0.11", default-features = false, features = ["rustls-tls"] } +reqwest = { version = "0.11", default-features = false, features = [ + "rustls-tls", +] } rstest = "0.18" semver = { version = "1.0", features = ["serde"] } serde = { version = "1.0", features = ["derive"] } @@ -43,9 +50,14 @@ serde_json = "1.0" serde_yaml = "0.9" sha2 = "0.10" snafu = "0.7" -stackable-operator = { git = "https://github.com/stackabletech/operator-rs.git", tag = "0.61.0" } +stackable-operator = { git = "https://github.com/stackabletech/operator-rs.git", tag = "0.64.0" } tera = "1.18" -tokio = { version = "1.29.0", features = ["rt-multi-thread", "macros", "fs", "process"] } +tokio = { version = "1.29.0", features = [ + "rt-multi-thread", + "macros", + "fs", + "process", +] } tower-http = "0.4" tracing = "0.1" tracing-subscriber = "0.3" From 5837276d8c1e587faa73a43da62cbab67e072b8c Mon Sep 17 00:00:00 2001 From: Techassi Date: Wed, 6 Mar 2024 12:10:45 +0100 Subject: [PATCH 2/4] chore: Include README header (#217) --- .readme/static/borrowed/Icon_Stackable.svg | 20 ++++++++++++++++++++ README.md | 20 +++++++++++++------- 2 files changed, 33 insertions(+), 7 deletions(-) create mode 100644 .readme/static/borrowed/Icon_Stackable.svg diff --git a/.readme/static/borrowed/Icon_Stackable.svg b/.readme/static/borrowed/Icon_Stackable.svg new file mode 100644 index 00000000..35e132a9 --- /dev/null +++ b/.readme/static/borrowed/Icon_Stackable.svg @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/README.md b/README.md index 01058748..2e0c3c35 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,18 @@ -# Stackable Cockpit + -⚠️ Notice: This repository and all its components are currently WIP. At this point in time, no stable version is -released. Users of `stackablectl` should continue to use the current latest version. A switch can be made when the time -is appropriate. +

+ Stackable Logo +

-This repository contains the Stackable library `stackable-cockpit`, the Stackable CLI tool -`stackablectl`, the Stackable server `stackable-cockpitd`, and the web-based admin user -interface. +

Stackable Cockpit

+ +[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-green.svg)](https://docs.stackable.tech/home/stable/contributor/index.html) +[![Apache License 2.0](https://img.shields.io/badge/license-Apache--2.0-green)](./LICENSE) + +[Stackable Data Platform](https://stackable.tech/) | [Platform Docs](https://docs.stackable.tech/) | [Discussions](https://github.com/orgs/stackabletech/discussions) | [Discord](https://discord.gg/7kZ3BNnCAF) + +This repository contains the Stackable library `stackable-cockpit`, the Stackable CLI tool `stackablectl`, the Stackable +Cockpit server `stackable-cockpitd`, and the web-based admin user interface. ## Components From 5f7fd705cfad28c64c655a108432e7d78555c2cc Mon Sep 17 00:00:00 2001 From: Sebastian Bernauer Date: Mon, 11 Mar 2024 10:41:11 +0100 Subject: [PATCH 3/4] Support listing endpoints of Listeners in "stacklet list" command (#213) * Support listing endpoints of Listeners in "stacklet list" command * changelog * improve docs * doc comment * Move endpoints declaration down * Update rust/stackable-cockpit/src/platform/service.rs Co-authored-by: Techassi * Move stuff into display_name_for_listener_name function --------- Co-authored-by: Techassi --- .../stackable-cockpit/src/platform/service.rs | 74 ++++++++++++++++++- .../src/platform/stacklet/mod.rs | 2 +- .../stackable-cockpit/src/utils/k8s/client.rs | 26 ++++++- rust/stackablectl/CHANGELOG.md | 6 ++ 4 files changed, 101 insertions(+), 7 deletions(-) diff --git a/rust/stackable-cockpit/src/platform/service.rs b/rust/stackable-cockpit/src/platform/service.rs index cda0d481..491d20c9 100644 --- a/rust/stackable-cockpit/src/platform/service.rs +++ b/rust/stackable-cockpit/src/platform/service.rs @@ -45,15 +45,46 @@ pub async fn get_endpoints( object_name: &str, object_namespace: &str, ) -> Result, Error> { - let service_list_params = + let list_params = ListParams::from_product(product_name, Some(object_name), k8s::ProductLabel::Name); - let services = kube_client - .list_services(Some(object_namespace), &service_list_params) + let listeners = kube_client + .list_listeners(Some(object_namespace), &list_params) .await .context(KubeClientFetchSnafu)?; let mut endpoints = IndexMap::new(); + for listener in &listeners { + let Some(display_name) = display_name_for_listener_name(&listener.name_any(), object_name) + else { + continue; + }; + let Some(listener_status) = &listener.status else { + continue; + }; + + for address in listener_status.ingress_addresses.iter().flatten() { + for port in &address.ports { + let text = format!("{display_name}-{port_name}", port_name = port.0); + let endpoint_url = endpoint_url(&address.address, *port.1, port.0); + endpoints.insert(text, endpoint_url); + } + } + } + + // Ideally we use listener-operator everywhere, afterwards we can remove the whole k8s Services handling below. + // Currently the Services created by listener-op are missing the recommended labels, so this early exit in case we + // find Listeners is currently not required. However, once we add the recommended labels to the k8s Services, we + // would have duplicated entries (one from the Listener and one from the Service). Because of this we don't look at + // the Services in case we found Listeners! + if !listeners.items.is_empty() { + return Ok(endpoints); + } + + let services = kube_client + .list_services(Some(object_namespace), &list_params) + .await + .context(KubeClientFetchSnafu)?; for service in services { match get_endpoint_urls(kube_client, &service, object_name).await { @@ -268,7 +299,7 @@ async fn get_node_name_ip_mapping( } fn endpoint_url(endpoint_host: &str, endpoint_port: i32, port_name: &str) -> String { - // TODO: Consolidate web-ui port names in operators based on decision in arch meeting from 2022/08/10 + // TODO: Consolidate web-ui port names in operators based on decision in arch meeting from 2022-08-10 // For Superset: https://github.com/stackabletech/superset-operator/issues/248 // For Airflow: https://github.com/stackabletech/airflow-operator/issues/146 // As we still support older operator versions we need to also include the "old" way of naming @@ -285,3 +316,38 @@ fn endpoint_url(endpoint_host: &str, endpoint_port: i32, port_name: &str) -> Str format!("{endpoint_host}:{endpoint_port}") } } + +/// Listener names usually have the pattern `listener-simple-hdfs-namenode-default-0` or +/// `simple-hdfs-datanode-default-0-listener`, so we can strip everything before the first occurrence of +/// the stacklet name (`simple-hdfs` in this case). After that it actually get's pretty hard. +/// This truncation is *not* ideal, however we only have implemented listener-operator for HDFS so far, +/// so better to have support for that than nothing :) +fn display_name_for_listener_name(listener_name: &str, object_name: &str) -> Option { + let Some((_, display_name)) = listener_name.split_once(object_name) else { + return None; + }; + Some(display_name.trim_start_matches('-').to_owned()) +} + +#[cfg(test)] +mod tests { + use super::*; + use rstest::rstest; + + #[rstest] + // These are all the listener names implemented so far (only HDFS is using listener-operator). In the future more + // test-case should be added. + #[case("listener-simple-hdfs-namenode-default-0", "simple-hdfs", Some("namenode-default-0".to_string()))] + #[case("listener-simple-hdfs-namenode-default-1", "simple-hdfs", Some("namenode-default-1".to_string()))] + // FIXME: Come up with a more clever strategy to remove the `-listener` suffix. I would prefer to wait until we + // actually have more products using listener-op to not accidentally strip to much. + #[case("simple-hdfs-datanode-default-0-listener", "simple-hdfs", Some("datanode-default-0-listener".to_string()))] + fn test_display_name_for_listener_name( + #[case] listener_name: &str, + #[case] object_name: &str, + #[case] expected: Option, + ) { + let output = display_name_for_listener_name(listener_name, object_name); + assert_eq!(output, expected); + } +} diff --git a/rust/stackable-cockpit/src/platform/stacklet/mod.rs b/rust/stackable-cockpit/src/platform/stacklet/mod.rs index eaaacf98..fbd8dcb3 100644 --- a/rust/stackable-cockpit/src/platform/stacklet/mod.rs +++ b/rust/stackable-cockpit/src/platform/stacklet/mod.rs @@ -126,7 +126,7 @@ async fn list_stackable_stacklets( Some(obj) => obj, None => { info!( - "Failed to list services because the gvk {product_gvk:?} can not be resolved" + "Failed to list stacklets because the gvk {product_gvk:?} can not be resolved" ); continue; } diff --git a/rust/stackable-cockpit/src/utils/k8s/client.rs b/rust/stackable-cockpit/src/utils/k8s/client.rs index 32218843..12df47b6 100644 --- a/rust/stackable-cockpit/src/utils/k8s/client.rs +++ b/rust/stackable-cockpit/src/utils/k8s/client.rs @@ -12,7 +12,7 @@ use kube::{ }; use serde::Deserialize; use snafu::{OptionExt, ResultExt, Snafu}; -use stackable_operator::kvp::Labels; +use stackable_operator::{commons::listener::Listener, kvp::Labels}; use crate::{ platform::{cluster, credentials::Credentials}, @@ -188,7 +188,7 @@ impl Client { )) } - /// Lists [`Service`]s by matching labels. The services can be matched by + /// Lists [`Service`]s by matching labels. The Services can be matched by /// the product labels. [`ListParamsExt`] provides a utility function to /// create [`ListParams`] based on a product name and optional instance /// name. @@ -210,6 +210,28 @@ impl Client { Ok(services) } + /// Lists [`Listener`]s by matching labels. The Listeners can be matched by + /// the product labels. [`ListParamsExt`] provides a utility function to + /// create [`ListParams`] based on a product name and optional instance + /// name. + pub async fn list_listeners( + &self, + namespace: Option<&str>, + list_params: &ListParams, + ) -> ListResult { + let listener_api: Api = match namespace { + Some(namespace) => Api::namespaced(self.client.clone(), namespace), + None => Api::all(self.client.clone()), + }; + + let listeners = listener_api + .list(list_params) + .await + .context(KubeClientFetchSnafu)?; + + Ok(listeners) + } + /// Retrieves user credentials consisting of username and password from a /// secret identified by `secret_name` inside the `secret_namespace`. If /// either one of the values is missing, [`Ok(None)`] is returned. An error diff --git a/rust/stackablectl/CHANGELOG.md b/rust/stackablectl/CHANGELOG.md index fa744333..b50ab681 100644 --- a/rust/stackablectl/CHANGELOG.md +++ b/rust/stackablectl/CHANGELOG.md @@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file. ## [Unreleased] +### Added + +- Support listing endpoints of Listeners in `stackablectl stacklet list` command. + Currently only HDFS is using listener-op, so we can only test that so far ([#213]). + ### Changed - Operators are now installed in parallel when installing a release ([#202]). @@ -14,6 +19,7 @@ All notable changes to this project will be documented in this file. [#181]: https://github.com/stackabletech/stackable-cockpit/pull/181 [#202]: https://github.com/stackabletech/stackable-cockpit/pull/202 +[#213]: https://github.com/stackabletech/stackable-cockpit/pull/213 ## [23.11.3] - 2024-01-03 From 1e592862e27cd6eec3aa3d0549d7deff564cf209 Mon Sep 17 00:00:00 2001 From: Nick Date: Wed, 13 Mar 2024 10:45:44 +0100 Subject: [PATCH 4/4] fix: Update nix (#218) * niv init && niv update * make regenerate-nix * update gitattributes for generated nix files --- .gitattributes | 2 + Cargo.nix | 28 +++++++++--- crate-hashes.json | 4 +- nix/sources.json | 18 ++++---- nix/sources.nix | 114 ++++++++++++++++++++++++---------------------- 5 files changed, 93 insertions(+), 73 deletions(-) diff --git a/.gitattributes b/.gitattributes index 1d94f10d..591bb422 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,4 +1,6 @@ web/src/api/schema.d.ts linguist-generated extra/completions/* linguist-generated extra/man/* linguist-generated +nix/** linguist-generated Cargo.nix linguist-generated +crate-hashes.json linguist-generated diff --git a/Cargo.nix b/Cargo.nix index b66cda29..2104d627 100644 --- a/Cargo.nix +++ b/Cargo.nix @@ -1,5 +1,5 @@ -# This file was @generated by crate2nix 0.11.1 with the command: +# This file was @generated by crate2nix 0.13.0 with the command: # "generate" # See https://github.com/kolloch/crate2nix for more info. @@ -8094,6 +8094,10 @@ rec { name = "bcrypt"; packageId = "bcrypt"; } + { + name = "futures"; + packageId = "futures"; + } { name = "helm-sys"; packageId = "helm-sys"; @@ -8321,13 +8325,13 @@ rec { }; "stackable-operator" = rec { crateName = "stackable-operator"; - version = "0.61.0"; + version = "0.64.0"; edition = "2021"; workspace_member = null; src = pkgs.fetchgit { url = "https://github.com/stackabletech/operator-rs.git"; - rev = "ddc57addbc741e3977b1589e553164505a59f639"; - sha256 = "1scwkw9gjd1gaijz8nxdpps88r85mxkxn5l2805m9g6cm6zbgvc0"; + rev = "d988822e7af3d363d52fb35643f0c6ed933f340a"; + sha256 = "05a4aqb2lv3rkc049zsq5vxxbx4km8l1j6mbn984wjag5fsmrpfp"; }; authors = [ "Stackable GmbH " @@ -8480,13 +8484,13 @@ rec { }; "stackable-operator-derive" = rec { crateName = "stackable-operator-derive"; - version = "0.61.0"; + version = "0.64.0"; edition = "2021"; workspace_member = null; src = pkgs.fetchgit { url = "https://github.com/stackabletech/operator-rs.git"; - rev = "ddc57addbc741e3977b1589e553164505a59f639"; - sha256 = "1scwkw9gjd1gaijz8nxdpps88r85mxkxn5l2805m9g6cm6zbgvc0"; + rev = "d988822e7af3d363d52fb35643f0c6ed933f340a"; + sha256 = "05a4aqb2lv3rkc049zsq5vxxbx4km8l1j6mbn984wjag5fsmrpfp"; }; procMacro = true; authors = [ @@ -12580,6 +12584,16 @@ rec { # recreate a file hierarchy as when running tests with cargo # the source for test data + # It's necessary to locate the source in $NIX_BUILD_TOP/source/ + # instead of $NIX_BUILD_TOP/ + # because we compiled those test binaries in the former and not the latter. + # So all paths will expect source tree to be there and not in the build top directly. + # For example: $NIX_BUILD_TOP := /build in general, if you ask yourself. + # TODO(raitobezarius): I believe there could be more edge cases if `crate.sourceRoot` + # do exist but it's very hard to reason about them, so let's wait until the first bug report. + mkdir -p source/ + cd source/ + ${pkgs.buildPackages.xorg.lndir}/bin/lndir ${crate.src} # build outputs diff --git a/crate-hashes.json b/crate-hashes.json index 3852a6ae..8599de7a 100644 --- a/crate-hashes.json +++ b/crate-hashes.json @@ -1,5 +1,5 @@ { "product-config 0.6.0 (git+https://github.com/stackabletech/product-config.git?tag=0.6.0#ad2c3ea6a291e415d978eb4271fb309e75861ef0)": "1ixc2x7540sxdmc92hqdcwm24rj8i1ivjsvwk2d57pdsq03j2x41", - "stackable-operator 0.61.0 (git+https://github.com/stackabletech/operator-rs.git?tag=0.61.0#ddc57addbc741e3977b1589e553164505a59f639)": "1scwkw9gjd1gaijz8nxdpps88r85mxkxn5l2805m9g6cm6zbgvc0", - "stackable-operator-derive 0.61.0 (git+https://github.com/stackabletech/operator-rs.git?tag=0.61.0#ddc57addbc741e3977b1589e553164505a59f639)": "1scwkw9gjd1gaijz8nxdpps88r85mxkxn5l2805m9g6cm6zbgvc0" + "stackable-operator 0.64.0 (git+https://github.com/stackabletech/operator-rs.git?tag=0.64.0#d988822e7af3d363d52fb35643f0c6ed933f340a)": "05a4aqb2lv3rkc049zsq5vxxbx4km8l1j6mbn984wjag5fsmrpfp", + "stackable-operator-derive 0.64.0 (git+https://github.com/stackabletech/operator-rs.git?tag=0.64.0#d988822e7af3d363d52fb35643f0c6ed933f340a)": "05a4aqb2lv3rkc049zsq5vxxbx4km8l1j6mbn984wjag5fsmrpfp" } \ No newline at end of file diff --git a/nix/sources.json b/nix/sources.json index 18a58182..0b11b5a3 100644 --- a/nix/sources.json +++ b/nix/sources.json @@ -5,10 +5,10 @@ "homepage": "", "owner": "kolloch", "repo": "crate2nix", - "rev": "9a9f8b127c826fe03114b9549980745b496254da", - "sha256": "0lpx7nxvmy17p2ll5704x2x57y1pk66hy2qdzz2084dv1arz9b6w", + "rev": "7eb26c517fa5b4b2056cc5e2e288e0117306e600", + "sha256": "09j76yzr3rcjj1k4jc8wpfqbpvlr4qqldxc5ih4viw0iyg0n1h9v", "type": "tarball", - "url": "https://github.com/kolloch/crate2nix/archive/9a9f8b127c826fe03114b9549980745b496254da.tar.gz", + "url": "https://github.com/kolloch/crate2nix/archive/7eb26c517fa5b4b2056cc5e2e288e0117306e600.tar.gz", "url_template": "https://github.com///archive/.tar.gz" }, "gomod2nix": { @@ -17,10 +17,10 @@ "homepage": "", "owner": "nix-community", "repo": "gomod2nix", - "rev": "001bbfa22e2adeb87c34c6015e5694e88721cabe", - "sha256": "1nnfw9366az79skmfqfmxv3789wqgf2xmi9k734qjplnhb28r458", + "rev": "872b63ddd28f318489c929d25f1f0a3c6039c971", + "sha256": "1wh9rlhg2w42fsavh7wxvmw42l7m5wg290gnp571dq0qcr1z7kg1", "type": "tarball", - "url": "https://github.com/nix-community/gomod2nix/archive/001bbfa22e2adeb87c34c6015e5694e88721cabe.tar.gz", + "url": "https://github.com/nix-community/gomod2nix/archive/872b63ddd28f318489c929d25f1f0a3c6039c971.tar.gz", "url_template": "https://github.com///archive/.tar.gz", "version": "1.5.0" }, @@ -42,10 +42,10 @@ "homepage": "", "owner": "NixOS", "repo": "nixpkgs", - "rev": "79a13f1437e149dc7be2d1290c74d378dad60814", - "sha256": "10shz1jkjrzyhjc69vx50w86mk94w3b6cf00cqr7x016cf6jfll5", + "rev": "9a9a7552431c4f1a3b2eee9398641babf7c30d0e", + "sha256": "1f2jdbw507qprdrvs9jkrgxjw83vm7p9jj6nv7ybdky7yx4z5dca", "type": "tarball", - "url": "https://github.com/NixOS/nixpkgs/archive/79a13f1437e149dc7be2d1290c74d378dad60814.tar.gz", + "url": "https://github.com/NixOS/nixpkgs/archive/9a9a7552431c4f1a3b2eee9398641babf7c30d0e.tar.gz", "url_template": "https://github.com///archive/.tar.gz" } } diff --git a/nix/sources.nix b/nix/sources.nix index 9a01c8ac..fe3dadf7 100644 --- a/nix/sources.nix +++ b/nix/sources.nix @@ -10,33 +10,34 @@ let let name' = sanitizeName name + "-src"; in - if spec.builtin or true then - builtins_fetchurl { inherit (spec) url sha256; name = name'; } - else - pkgs.fetchurl { inherit (spec) url sha256; name = name'; }; + if spec.builtin or true then + builtins_fetchurl { inherit (spec) url sha256; name = name'; } + else + pkgs.fetchurl { inherit (spec) url sha256; name = name'; }; fetch_tarball = pkgs: name: spec: let name' = sanitizeName name + "-src"; in - if spec.builtin or true then - builtins_fetchTarball { name = name'; inherit (spec) url sha256; } - else - pkgs.fetchzip { name = name'; inherit (spec) url sha256; }; + if spec.builtin or true then + builtins_fetchTarball { name = name'; inherit (spec) url sha256; } + else + pkgs.fetchzip { name = name'; inherit (spec) url sha256; }; fetch_git = name: spec: let ref = - if spec ? ref then spec.ref else + spec.ref or ( if spec ? branch then "refs/heads/${spec.branch}" else - if spec ? tag then "refs/tags/${spec.tag}" else - abort "In git source '${name}': Please specify `ref`, `tag` or `branch`!"; - submodules = if spec ? submodules then spec.submodules else false; + if spec ? tag then "refs/tags/${spec.tag}" else + abort "In git source '${name}': Please specify `ref`, `tag` or `branch`!" + ); + submodules = spec.submodules or false; submoduleArg = let nixSupportsSubmodules = builtins.compareVersions builtins.nixVersion "2.4" >= 0; emptyArgWithWarning = - if submodules == true + if submodules then builtins.trace ( @@ -44,15 +45,15 @@ let + "but your nix's (${builtins.nixVersion}) builtins.fetchGit " + "does not support them" ) - {} - else {}; + { } + else { }; in - if nixSupportsSubmodules - then { inherit submodules; } - else emptyArgWithWarning; + if nixSupportsSubmodules + then { inherit submodules; } + else emptyArgWithWarning; in - builtins.fetchGit - ({ url = spec.repo; inherit (spec) rev; inherit ref; } // submoduleArg); + builtins.fetchGit + ({ url = spec.repo; inherit (spec) rev; inherit ref; } // submoduleArg); fetch_local = spec: spec.path; @@ -86,16 +87,16 @@ let hasNixpkgsPath = builtins.any (x: x.prefix == "nixpkgs") builtins.nixPath; hasThisAsNixpkgsPath = == ./.; in - if builtins.hasAttr "nixpkgs" sources - then sourcesNixpkgs - else if hasNixpkgsPath && ! hasThisAsNixpkgsPath then - import {} - else - abort - '' - Please specify either (through -I or NIX_PATH=nixpkgs=...) or - add a package called "nixpkgs" to your sources.json. - ''; + if builtins.hasAttr "nixpkgs" sources + then sourcesNixpkgs + else if hasNixpkgsPath && ! hasThisAsNixpkgsPath then + import { } + else + abort + '' + Please specify either (through -I or NIX_PATH=nixpkgs=...) or + add a package called "nixpkgs" to your sources.json. + ''; # The actual fetching function. fetch = pkgs: name: spec: @@ -115,13 +116,13 @@ let # the path directly as opposed to the fetched source. replace = name: drv: let - saneName = stringAsChars (c: if isNull (builtins.match "[a-zA-Z0-9]" c) then "_" else c) name; + saneName = stringAsChars (c: if (builtins.match "[a-zA-Z0-9]" c) == null then "_" else c) name; ersatz = builtins.getEnv "NIV_OVERRIDE_${saneName}"; in - if ersatz == "" then drv else - # this turns the string into an actual Nix path (for both absolute and - # relative paths) - if builtins.substring 0 1 ersatz == "/" then /. + ersatz else /. + builtins.getEnv "PWD" + "/${ersatz}"; + if ersatz == "" then drv else + # this turns the string into an actual Nix path (for both absolute and + # relative paths) + if builtins.substring 0 1 ersatz == "/" then /. + ersatz else /. + builtins.getEnv "PWD" + "/${ersatz}"; # Ports of functions for older nix versions @@ -132,7 +133,7 @@ let ); # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/lists.nix#L295 - range = first: last: if first > last then [] else builtins.genList (n: first + n) (last - first + 1); + range = first: last: if first > last then [ ] else builtins.genList (n: first + n) (last - first + 1); # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/strings.nix#L257 stringToCharacters = s: map (p: builtins.substring p 1 s) (range 0 (builtins.stringLength s - 1)); @@ -143,43 +144,46 @@ let concatStrings = builtins.concatStringsSep ""; # https://github.com/NixOS/nixpkgs/blob/8a9f58a375c401b96da862d969f66429def1d118/lib/attrsets.nix#L331 - optionalAttrs = cond: as: if cond then as else {}; + optionalAttrs = cond: as: if cond then as else { }; # fetchTarball version that is compatible between all the versions of Nix builtins_fetchTarball = { url, name ? null, sha256 }@attrs: let inherit (builtins) lessThan nixVersion fetchTarball; in - if lessThan nixVersion "1.12" then - fetchTarball ({ inherit url; } // (optionalAttrs (!isNull name) { inherit name; })) - else - fetchTarball attrs; + if lessThan nixVersion "1.12" then + fetchTarball ({ inherit url; } // (optionalAttrs (name != null) { inherit name; })) + else + fetchTarball attrs; # fetchurl version that is compatible between all the versions of Nix builtins_fetchurl = { url, name ? null, sha256 }@attrs: let inherit (builtins) lessThan nixVersion fetchurl; in - if lessThan nixVersion "1.12" then - fetchurl ({ inherit url; } // (optionalAttrs (!isNull name) { inherit name; })) - else - fetchurl attrs; + if lessThan nixVersion "1.12" then + fetchurl ({ inherit url; } // (optionalAttrs (name != null) { inherit name; })) + else + fetchurl attrs; # Create the final "sources" from the config mkSources = config: - mapAttrs ( - name: spec: - if builtins.hasAttr "outPath" spec - then abort - "The values in sources.json should not have an 'outPath' attribute" - else - spec // { outPath = replace name (fetch config.pkgs name spec); } - ) config.sources; + mapAttrs + ( + name: spec: + if builtins.hasAttr "outPath" spec + then + abort + "The values in sources.json should not have an 'outPath' attribute" + else + spec // { outPath = replace name (fetch config.pkgs name spec); } + ) + config.sources; # The "config" used by the fetchers mkConfig = { sourcesFile ? if builtins.pathExists ./sources.json then ./sources.json else null - , sources ? if isNull sourcesFile then {} else builtins.fromJSON (builtins.readFile sourcesFile) + , sources ? if sourcesFile == null then { } else builtins.fromJSON (builtins.readFile sourcesFile) , system ? builtins.currentSystem , pkgs ? mkPkgs sources system }: rec { @@ -191,4 +195,4 @@ let }; in -mkSources (mkConfig {}) // { __functor = _: settings: mkSources (mkConfig settings); } +mkSources (mkConfig { }) // { __functor = _: settings: mkSources (mkConfig settings); }