Skip to content

Commit

Permalink
flake-info: rely on upstream for extracting nixpkgs options
Browse files Browse the repository at this point in the history
  • Loading branch information
ncfavier committed Mar 31, 2022
1 parent 8cb880a commit 77eeb30
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
14 changes: 8 additions & 6 deletions flake-info/src/commands/flake_info.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{ flake }:
{ flake ? null }:
let
resolved = builtins.getFlake (toString flake);
resolved = builtins.getFlake flake;

nixpkgs = (import <nixpkgs> {});
lib = nixpkgs.lib;
Expand Down Expand Up @@ -93,7 +93,7 @@ let
flake = modulePath;
};
in
map (cleanUpOption extraAttrs) (lib.filter (x: !x.internal) opts);
map (cleanUpOption extraAttrs) (lib.filter (x: x.visible && !x.internal) opts);

readFlakeOptions = let
nixosModulesOpts = builtins.concatLists (lib.mapAttrsToList (moduleName: module:
Expand Down Expand Up @@ -144,8 +144,10 @@ rec {
packages = lib.attrValues (collectSystems packages');
apps = lib.attrValues (collectSystems apps');
options = readFlakeOptions;
nixos-options = readOptions {
module = import "${builtins.fetchTarball { url = flake; }}/nixos/modules/module-list.nix";
};
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")));
}
2 changes: 1 addition & 1 deletion flake-info/src/commands/nix_flake_attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub fn get_derivation_info<T: AsRef<str> + Display>(

let mut command = Command::with_args("nix", ARGS.iter());
command.add_arg_pair("-f", script_path.as_os_str());
command.add_args(["--arg", "flake", flake_ref.as_ref()].iter());
command.add_args(["--argstr", "flake", flake_ref.as_ref()].iter());
command.add_arg(kind.as_ref());
if temp_store {
let temp_store_path = PathBuf::from("/tmp/flake-info-store");
Expand Down
5 changes: 1 addition & 4 deletions flake-info/src/commands/nixpkgs_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>> {
let mut command = Command::new("nix-env");
command.add_args(&[
"--json",
"-f",
"<nixpkgs>",
"-I",
Expand All @@ -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>",
"-qa",
"--meta",
"--json",
]);

command.enable_capture();
Expand Down Expand Up @@ -66,9 +66,6 @@ pub fn get_nixpkgs_options<T: AsRef<str> + Display>(
script_path.to_str().unwrap(),
"-I",
format!("nixpkgs={}", nixpkgs_channel.as_ref()).as_str(),
"--arg",
"flake",
nixpkgs_channel.as_ref(),
"nixos-options",
]);

Expand Down

0 comments on commit 77eeb30

Please sign in to comment.