From d0ea61ad4e0a5062cf8d4566ec64e46468a52a94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Na=C3=AFm=20Camille=20Favier?= Date: Thu, 19 May 2022 12:57:42 +0200 Subject: [PATCH] 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 --- VERSION | 2 +- flake-info/src/commands/flake_info.nix | 14 ++++++++------ flake-info/src/commands/nix_flake_attrs.rs | 3 ++- flake-info/src/commands/nixpkgs_info.rs | 5 +---- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/VERSION b/VERSION index 64bb6b7..e85087a 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -30 +31 diff --git a/flake-info/src/commands/flake_info.nix b/flake-info/src/commands/flake_info.nix index c65dca1..42f3729 100644 --- a/flake-info/src/commands/flake_info.nix +++ b/flake-info/src/commands/flake_info.nix @@ -1,6 +1,6 @@ -{ flake }: +{ flake ? null }: let - resolved = builtins.getFlake (toString flake); + resolved = builtins.getFlake "input-flake"; nixpkgs = (import {}); lib = nixpkgs.lib; @@ -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: @@ -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 {}).options}/share/doc/nixos/options.json"))); } diff --git a/flake-info/src/commands/nix_flake_attrs.rs b/flake-info/src/commands/nix_flake_attrs.rs index 5525cd5..5f3b130 100644 --- a/flake-info/src/commands/nix_flake_attrs.rs +++ b/flake-info/src/commands/nix_flake_attrs.rs @@ -25,7 +25,8 @@ pub fn get_derivation_info + 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(["--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()); if temp_store { let temp_store_path = PathBuf::from("/tmp/flake-info-store"); diff --git a/flake-info/src/commands/nixpkgs_info.rs b/flake-info/src/commands/nixpkgs_info.rs index 7a8bd12..cb82da2 100644 --- a/flake-info/src/commands/nixpkgs_info.rs +++ b/flake-info/src/commands/nixpkgs_info.rs @@ -13,6 +13,7 @@ const FLAKE_INFO_SCRIPT: &str = include_str!("flake_info.nix"); pub fn get_nixpkgs_info + Display>(nixpkgs_channel: T) -> Result> { let mut command = Command::new("nix-env"); command.add_args(&[ + "--json", "-f", "", "-I", @@ -22,7 +23,6 @@ pub fn get_nixpkgs_info + Display>(nixpkgs_channel: T) -> Result", "-qa", "--meta", - "--json", ]); command.enable_capture(); @@ -66,9 +66,6 @@ pub fn get_nixpkgs_options + Display>( script_path.to_str().unwrap(), "-I", format!("nixpkgs={}", nixpkgs_channel.as_ref()).as_str(), - "--arg", - "flake", - nixpkgs_channel.as_ref(), "nixos-options", ]);