diff --git a/README.md b/README.md index 6476d7c..6a5a05a 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,7 @@ A fast CLI documentation searcher for Nix. - Nixpkgs Comments - Nixpkgs Tree (pkgs., pkgs.lib.) - NixOS Options +- Nix-Darwin Options - Home-Manager Options ## Usage diff --git a/flake.lock b/flake.lock index e5aa10f..37c3819 100644 --- a/flake.lock +++ b/flake.lock @@ -17,11 +17,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1599050737, - "narHash": "sha256-jxUhBQ49DYMnL17SrPNGTEp+Wb5Pj89CxW8OLwnXl1g=", + "lastModified": 1627480871, + "narHash": "sha256-6h8HZyfXFQB8LYDwQU5SEcabM2whu47COSUcOf5O1dg=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "18348c7829ae93ebe436497ca7ad96cdb8d39935", + "rev": "65584b6a0bbc82df63789b48570bb9e84d58dd29", "type": "github" }, "original": { diff --git a/nix/sources.json b/nix/sources.json index 5d36456..7283f4e 100644 --- a/nix/sources.json +++ b/nix/sources.json @@ -5,10 +5,10 @@ "homepage": "", "owner": "nmattia", "repo": "naersk", - "rev": "529e910a3f423a8211f8739290014b754b2555b6", - "sha256": "0bcy9nmyaan5jvp0wg80wkizc9j166ns685rdr1kbhkvdpywv46y", + "rev": "e09c320446c5c2516d430803f7b19f5833781337", + "sha256": "0k1pk2ixnxl6njjrgy750gm6m1nkkdsah383n3wp4ybrzacnav5h", "type": "tarball", - "url": "https://github.com/nmattia/naersk/archive/529e910a3f423a8211f8739290014b754b2555b6.tar.gz", + "url": "https://github.com/nmattia/naersk/archive/e09c320446c5c2516d430803f7b19f5833781337.tar.gz", "url_template": "https://github.com///archive/.tar.gz" }, "niv": { @@ -17,10 +17,10 @@ "homepage": "https://github.com/nmattia/niv", "owner": "nmattia", "repo": "niv", - "rev": "e82eb322ea32a747a51c431d7787221bcc6d9038", - "sha256": "1fy4dcr05d80diwlxmh42xnjm5ki1pkbky38smvlqjaky2y2f71f", + "rev": "e0ca65c81a2d7a4d82a189f1e23a48d59ad42070", + "sha256": "1pq9nh1d8nn3xvbdny8fafzw87mj7gsmp6pxkdl65w2g18rmcmzx", "type": "tarball", - "url": "https://github.com/nmattia/niv/archive/e82eb322ea32a747a51c431d7787221bcc6d9038.tar.gz", + "url": "https://github.com/nmattia/niv/archive/e0ca65c81a2d7a4d82a189f1e23a48d59ad42070.tar.gz", "url_template": "https://github.com///archive/.tar.gz" }, "nixpkgs": { @@ -29,10 +29,10 @@ "homepage": "https://github.com/NixOS/nixpkgs", "owner": "NixOS", "repo": "nixpkgs-channels", - "rev": "289466dd6a11c65a7de4a954d6ebf66c1ad07652", - "sha256": "0r5ja052s86fr54fm1zlhld3fwawz2w1d1gd6vbvpjrpjfyajibn", + "rev": "75f4ba05c63be3f147bcc2f7bd4ba1f029cedcb1", + "sha256": "157c64220lf825ll4c0cxsdwg7cxqdx4z559fdp7kpz0g6p8fhhr", "type": "tarball", - "url": "https://github.com/NixOS/nixpkgs-channels/archive/289466dd6a11c65a7de4a954d6ebf66c1ad07652.tar.gz", + "url": "https://github.com/NixOS/nixpkgs-channels/archive/75f4ba05c63be3f147bcc2f7bd4ba1f029cedcb1.tar.gz", "url_template": "https://github.com///archive/.tar.gz" } } diff --git a/src/bin/manix.rs b/src/bin/manix.rs index e5b18fd..7986e3f 100644 --- a/src/bin/manix.rs +++ b/src/bin/manix.rs @@ -14,6 +14,7 @@ arg_enum! { enum Source { nixos_options, hm_options, + nd_options, nixpkgs_doc, nixpkgs_tree, nixpkgs_comments, @@ -122,6 +123,9 @@ fn main() -> Result<()> { let options_hm_cache_path = cache_dir .place_cache_file("options_hm_database.bin") .context("Failed to place home-manager options cache file")?; + let options_nd_cache_path = cache_dir + .place_cache_file("options_nd_database.bin") + .context("Failed to place nix-darwin options cache file")?; let options_nixos_cache_path = cache_dir .place_cache_file("options_nixos_database.bin") .context("Failed to place NixOS options cache file")?; @@ -170,6 +174,19 @@ fn main() -> Result<()> { eprintln!("Tip: If you installed your home-manager through configuration.nix you can fix this error by adding the home-manager channel with this command: {}", "nix-channel --add https://github.com/rycee/home-manager/archive/master.tar.gz home-manager && nix-channel --update".bold()); } + if let None = build_source_and_add( + OptionsDatabase::new(OptionsDatabaseType::NixDarwin), + "Nix-Darwin Options", + &options_nd_cache_path, + if opt.source.contains(&Source::nd_options) { + Some(&mut aggregate_source) + } else { + None + }, + ) { + eprintln!("Tip: Ensure darwin is set in your NIX_PATH"); + } + build_source_and_add( OptionsDatabase::new(OptionsDatabaseType::NixOS), "NixOS Options", @@ -205,6 +222,15 @@ fn main() -> Result<()> { std::fs::write(&last_version_path, version)?; } else { + if opt.source.contains(&Source::nd_options) { + load_source_and_add( + std::fs::read(&options_nd_cache_path).map(|c| OptionsDatabase::load(&c)), + "Nix Darwin Options", + &mut aggregate_source, + true, + ); + } + if opt.source.contains(&Source::hm_options) { load_source_and_add( std::fs::read(&options_hm_cache_path).map(|c| OptionsDatabase::load(&c)), diff --git a/src/lib.rs b/src/lib.rs index b5a444a..29277ca 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -77,6 +77,7 @@ impl DocEntry { pub fn source(&self) -> &str { match self { DocEntry::OptionDoc(typ, _) => match typ { + OptionsDatabaseType::NixDarwin => "NixDarwin Options", OptionsDatabaseType::NixOS => "NixOS Options", OptionsDatabaseType::HomeManager => "HomeManager Options", }, diff --git a/src/nix/darwin-options.nix b/src/nix/darwin-options.nix new file mode 100644 index 0000000..cc83ab9 --- /dev/null +++ b/src/nix/darwin-options.nix @@ -0,0 +1,13 @@ +let + inherit (import {}) runCommandLocal; + + nix-darwin = let + inherit (builtins.tryEval ) success value; + in if success then value else fetchTarball https://github.com/LnL7/nix-darwin/archive/refs/heads/master.tar.gz; + + eval = import nix-darwin { configuration = ({ ... }: { }); }; + opts = eval.config.system.build.manual.optionsJSON; +in +runCommandLocal "options.json" { inherit opts; } '' + cp $opts/share/doc/darwin/options.json $out +'' diff --git a/src/nix/nixos-options.nix b/src/nix/nixos-options.nix new file mode 100644 index 0000000..c978735 --- /dev/null +++ b/src/nix/nixos-options.nix @@ -0,0 +1,10 @@ +with import {}; let + eval = import (pkgs.path + "/nixos/lib/eval-config.nix") { + system = "x86_64-linux"; + modules = [ ]; + }; + opts = (nixosOptionsDoc { options = eval.options; }).optionsJSON; +in +runCommandLocal "options.json" { inherit opts; } '' + cp $opts/share/doc/nixos/options.json $out +'' diff --git a/src/options_docsource.rs b/src/options_docsource.rs index 56a363a..3d020fd 100644 --- a/src/options_docsource.rs +++ b/src/options_docsource.rs @@ -43,6 +43,7 @@ impl OptionDocumentation { #[derive(Debug, Copy, Clone, PartialEq, Eq, Serialize, Deserialize)] pub enum OptionsDatabaseType { + NixDarwin, NixOS, HomeManager, } @@ -88,6 +89,7 @@ impl DocSource for OptionsDatabase { } fn update(&mut self) -> Result { let opts = match self.typ { + OptionsDatabaseType::NixDarwin => try_from_file(&get_nd_json_doc_path()?)?, OptionsDatabaseType::NixOS => try_from_file(&get_nixos_json_doc_path()?)?, OptionsDatabaseType::HomeManager => try_from_file(&get_hm_json_doc_path()?)?, }; @@ -100,6 +102,21 @@ impl DocSource for OptionsDatabase { impl Cache for OptionsDatabase {} +pub fn get_nd_json_doc_path() -> Result { + let base_path_output = Command::new("nix-build") + .env("NIXPKGS_ALLOW_UNFREE", "1") + .env("NIXPKGS_ALLOW_BROKEN", "1") + .env("NIXPKGS_ALLOW_INSECURE", "1") + .env("NIXPKGS_ALLOW_UNSUPPORTED_SYSTEM", "1") + .arg("--no-out-link") + .arg("-E") + .arg(include_str!("nix/darwin-options.nix")) + .output() + .map(|o| String::from_utf8(o.stdout).unwrap())?; + + Ok(PathBuf::from(base_path_output.trim_end_matches("\n"))) +} + pub fn get_hm_json_doc_path() -> Result { let base_path_output = Command::new("nix-build") .arg("-E") @@ -122,9 +139,10 @@ pub fn get_nixos_json_doc_path() -> Result { .env("NIXPKGS_ALLOW_UNFREE", "1") .env("NIXPKGS_ALLOW_BROKEN", "1") .env("NIXPKGS_ALLOW_INSECURE", "1") + .env("NIXPKGS_ALLOW_UNSUPPORTED_SYSTEM", "1") .arg("--no-out-link") .arg("-E") - .arg(r#"with import {}; let eval = import (pkgs.path + "/nixos/lib/eval-config.nix") { modules = []; }; opts = (nixosOptionsDoc { options = eval.options; }).optionsJSON; in runCommandLocal "options.json" { inherit opts; } "cp $opts/share/doc/nixos/options.json $out""#) + .arg(include_str!("nix/nixos-options.nix")) .output() .map(|o| String::from_utf8(o.stdout).unwrap())?;