Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Darwin support #23

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 9 additions & 9 deletions nix/sources.json
Original file line number Diff line number Diff line change
Expand Up @@ -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/<owner>/<repo>/archive/<rev>.tar.gz"
},
"niv": {
Expand All @@ -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/<owner>/<repo>/archive/<rev>.tar.gz"
},
"nixpkgs": {
Expand All @@ -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/<owner>/<repo>/archive/<rev>.tar.gz"
}
}
26 changes: 26 additions & 0 deletions src/bin/manix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ arg_enum! {
enum Source {
nixos_options,
hm_options,
nd_options,
nixpkgs_doc,
nixpkgs_tree,
nixpkgs_comments,
Expand Down Expand Up @@ -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")?;
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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)),
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
Expand Down
13 changes: 13 additions & 0 deletions src/nix/darwin-options.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
let
inherit (import <nixpkgs> {}) runCommandLocal;

nix-darwin = let
inherit (builtins.tryEval <darwin>) 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
''
10 changes: 10 additions & 0 deletions src/nix/nixos-options.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
with import <nixpkgs> {}; 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
''
20 changes: 19 additions & 1 deletion src/options_docsource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ impl OptionDocumentation {

#[derive(Debug, Copy, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub enum OptionsDatabaseType {
NixDarwin,
NixOS,
HomeManager,
}
Expand Down Expand Up @@ -88,6 +89,7 @@ impl DocSource for OptionsDatabase {
}
fn update(&mut self) -> Result<bool, Errors> {
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()?)?,
};
Expand All @@ -100,6 +102,21 @@ impl DocSource for OptionsDatabase {

impl Cache for OptionsDatabase {}

pub fn get_nd_json_doc_path() -> Result<PathBuf, std::io::Error> {
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<PathBuf, std::io::Error> {
let base_path_output = Command::new("nix-build")
.arg("-E")
Expand All @@ -122,9 +139,10 @@ pub fn get_nixos_json_doc_path() -> Result<PathBuf, std::io::Error> {
.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 <nixpkgs> {}; 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())?;

Expand Down