Rely on upstream for extracting nixpkgs options (#460)

* flake-info: rely on upstream for extracting nixpkgs options

Use the `options.json` generated in nixpkgs to be more in sync with the
manual.

Also fixes usage of `nixpkgs-archive` with local paths.

* Bump VERSION
This commit is contained in:
Naïm Camille Favier 2022-05-19 12:57:42 +02:00 committed by GitHub
parent 3b41f2dcfd
commit d0ea61ad4e
Failed to generate hash of commit
4 changed files with 12 additions and 12 deletions

View file

@ -1 +1 @@
30 31

View file

@ -1,6 +1,6 @@
{ flake }: { flake ? null }:
let let
resolved = builtins.getFlake (toString flake); resolved = builtins.getFlake "input-flake";
nixpkgs = (import <nixpkgs> {}); nixpkgs = (import <nixpkgs> {});
lib = nixpkgs.lib; lib = nixpkgs.lib;
@ -93,7 +93,7 @@ let
flake = modulePath; flake = modulePath;
}; };
in in
map (cleanUpOption extraAttrs) (lib.filter (x: !x.internal) opts); map (cleanUpOption extraAttrs) (lib.filter (x: x.visible && !x.internal) opts);
readFlakeOptions = let readFlakeOptions = let
nixosModulesOpts = builtins.concatLists (lib.mapAttrsToList (moduleName: module: nixosModulesOpts = builtins.concatLists (lib.mapAttrsToList (moduleName: module:
@ -144,8 +144,10 @@ rec {
packages = lib.attrValues (collectSystems packages'); packages = lib.attrValues (collectSystems packages');
apps = lib.attrValues (collectSystems apps'); apps = lib.attrValues (collectSystems apps');
options = readFlakeOptions; options = readFlakeOptions;
nixos-options = readOptions {
module = import "${builtins.fetchTarball { url = flake; }}/nixos/modules/module-list.nix";
};
all = packages ++ apps ++ options; all = packages ++ apps ++ options;
# nixpkgs-specific, doesn't use the flake argument
nixos-options = lib.mapAttrsToList (name: option: option // { inherit name; })
(builtins.fromJSON (builtins.unsafeDiscardStringContext (builtins.readFile
"${(import <nixpkgs/nixos/release.nix> {}).options}/share/doc/nixos/options.json")));
} }

View file

@ -25,7 +25,8 @@ pub fn get_derivation_info<T: AsRef<str> + Display>(
let mut command = Command::with_args("nix", ARGS.iter()); let mut command = Command::with_args("nix", ARGS.iter());
command.add_arg_pair("-f", script_path.as_os_str()); command.add_arg_pair("-f", script_path.as_os_str());
command.add_args(["--arg", "flake", flake_ref.as_ref()].iter()); command.add_args(["--override-flake", "input-flake", flake_ref.as_ref()].iter());
command.add_args(["--argstr", "flake", flake_ref.as_ref()].iter());
command.add_arg(kind.as_ref()); command.add_arg(kind.as_ref());
if temp_store { if temp_store {
let temp_store_path = PathBuf::from("/tmp/flake-info-store"); let temp_store_path = PathBuf::from("/tmp/flake-info-store");

View file

@ -13,6 +13,7 @@ const FLAKE_INFO_SCRIPT: &str = include_str!("flake_info.nix");
pub fn get_nixpkgs_info<T: AsRef<str> + Display>(nixpkgs_channel: T) -> Result<Vec<NixpkgsEntry>> { pub fn get_nixpkgs_info<T: AsRef<str> + Display>(nixpkgs_channel: T) -> Result<Vec<NixpkgsEntry>> {
let mut command = Command::new("nix-env"); let mut command = Command::new("nix-env");
command.add_args(&[ command.add_args(&[
"--json",
"-f", "-f",
"<nixpkgs>", "<nixpkgs>",
"-I", "-I",
@ -22,7 +23,6 @@ pub fn get_nixpkgs_info<T: AsRef<str> + Display>(nixpkgs_channel: T) -> Result<V
"import <nixpkgs/pkgs/top-level/packages-config.nix>", "import <nixpkgs/pkgs/top-level/packages-config.nix>",
"-qa", "-qa",
"--meta", "--meta",
"--json",
]); ]);
command.enable_capture(); command.enable_capture();
@ -66,9 +66,6 @@ pub fn get_nixpkgs_options<T: AsRef<str> + Display>(
script_path.to_str().unwrap(), script_path.to_str().unwrap(),
"-I", "-I",
format!("nixpkgs={}", nixpkgs_channel.as_ref()).as_str(), format!("nixpkgs={}", nixpkgs_channel.as_ref()).as_str(),
"--arg",
"flake",
nixpkgs_channel.as_ref(),
"nixos-options", "nixos-options",
]); ]);