flake-info: remove broken NIXOS_CHANNELS
check (#586)
Fixing it would be undesirable. Co-authored-by: Rok Garbas <rok@garbas.si>
This commit is contained in:
parent
19f4984615
commit
25e8dbdb94
|
@ -1,5 +1,4 @@
|
||||||
{ pkgs ? import <nixpkgs> {}
|
{ pkgs ? import <nixpkgs> {}
|
||||||
, nixosChannels ? {}
|
|
||||||
}:
|
}:
|
||||||
pkgs.rustPlatform.buildRustPackage rec {
|
pkgs.rustPlatform.buildRustPackage rec {
|
||||||
name = "flake-info";
|
name = "flake-info";
|
||||||
|
@ -34,7 +33,6 @@ pkgs.rustPlatform.buildRustPackage rec {
|
||||||
cp -rt "$out" assets
|
cp -rt "$out" assets
|
||||||
|
|
||||||
wrapProgram $out/bin/flake-info \
|
wrapProgram $out/bin/flake-info \
|
||||||
--set NIXOS_CHANNELS '${builtins.toJSON nixosChannels}' \
|
|
||||||
--prefix PATH : ${pkgs.pandoc}/bin
|
--prefix PATH : ${pkgs.pandoc}/bin
|
||||||
'';
|
'';
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,13 +3,10 @@ use flake_info::commands::NixCheckError;
|
||||||
use flake_info::data::import::Kind;
|
use flake_info::data::import::Kind;
|
||||||
use flake_info::data::{self, Export, Source};
|
use flake_info::data::{self, Export, Source};
|
||||||
use flake_info::elastic::{self, ElasticsearchError, ExistsStrategy};
|
use flake_info::elastic::{self, ElasticsearchError, ExistsStrategy};
|
||||||
use lazy_static::lazy_static;
|
|
||||||
use log::{error, info, warn};
|
use log::{error, info, warn};
|
||||||
use serde::Deserialize;
|
|
||||||
use sha2::Digest;
|
use sha2::Digest;
|
||||||
use std::io;
|
use std::io;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::str::FromStr;
|
|
||||||
use structopt::{clap::ArgGroup, StructOpt};
|
use structopt::{clap::ArgGroup, StructOpt};
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
use tokio::fs::File;
|
use tokio::fs::File;
|
||||||
|
@ -190,9 +187,6 @@ enum FlakeInfoError {
|
||||||
#[error("Nix check failed: {0}")]
|
#[error("Nix check failed: {0}")]
|
||||||
NixCheck(#[from] NixCheckError),
|
NixCheck(#[from] NixCheckError),
|
||||||
|
|
||||||
#[error("Nixos Channel `{0}` not among the allowed Channels set by NIXOS_CHANNELS ({:?}", .1.channels)]
|
|
||||||
UnknownNixOSChannel(String, NixosChannels),
|
|
||||||
|
|
||||||
#[error("Getting flake info caused an error: {0:?}")]
|
#[error("Getting flake info caused an error: {0:?}")]
|
||||||
Flake(anyhow::Error),
|
Flake(anyhow::Error),
|
||||||
#[error("Getting nixpkgs info caused an error: {0:?}")]
|
#[error("Getting nixpkgs info caused an error: {0:?}")]
|
||||||
|
@ -225,8 +219,6 @@ async fn run_command(
|
||||||
Ok((exports, ident))
|
Ok((exports, ident))
|
||||||
}
|
}
|
||||||
Command::Nixpkgs { channel } => {
|
Command::Nixpkgs { channel } => {
|
||||||
NIXOS_CHANNELS.check_channel(&channel)?;
|
|
||||||
|
|
||||||
let nixpkgs = Source::nixpkgs(channel)
|
let nixpkgs = Source::nixpkgs(channel)
|
||||||
.await
|
.await
|
||||||
.map_err(FlakeInfoError::Nixpkgs)?;
|
.map_err(FlakeInfoError::Nixpkgs)?;
|
||||||
|
@ -241,8 +233,6 @@ async fn run_command(
|
||||||
Ok((exports, ident))
|
Ok((exports, ident))
|
||||||
}
|
}
|
||||||
Command::NixpkgsArchive { source, channel } => {
|
Command::NixpkgsArchive { source, channel } => {
|
||||||
NIXOS_CHANNELS.check_channel(&channel)?;
|
|
||||||
|
|
||||||
let ident = (
|
let ident = (
|
||||||
"nixos".to_string(),
|
"nixos".to_string(),
|
||||||
channel.to_owned(),
|
channel.to_owned(),
|
||||||
|
@ -397,48 +387,3 @@ async fn push_to_elastic(
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Information about allowed and default nixos channels.
|
|
||||||
/// Typyically passed by environment variable NIXOS_CHANNELS.
|
|
||||||
/// Used to filter the input arguments for `flake-info nixpkgs` and `flake-info nixpkgs-archive`
|
|
||||||
#[derive(Clone, Debug, Deserialize)]
|
|
||||||
struct NixosChannels {
|
|
||||||
channels: Vec<Channel>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone, Debug, Deserialize)]
|
|
||||||
struct Channel {
|
|
||||||
branch: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl NixosChannels {
|
|
||||||
fn check_channel(&self, channel: &String) -> Result<(), FlakeInfoError> {
|
|
||||||
self.channels
|
|
||||||
.iter()
|
|
||||||
.find(|c| &c.branch == channel)
|
|
||||||
.map_or_else(
|
|
||||||
|| Ok(()),
|
|
||||||
|_| {
|
|
||||||
Err(FlakeInfoError::UnknownNixOSChannel(
|
|
||||||
channel.clone(),
|
|
||||||
self.clone(),
|
|
||||||
))
|
|
||||||
},
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl FromStr for NixosChannels {
|
|
||||||
type Err = serde_json::Error;
|
|
||||||
|
|
||||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
|
||||||
serde_json::from_str(s)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
lazy_static! {
|
|
||||||
static ref NIXOS_CHANNELS: NixosChannels = std::env::var("NIXOS_CHANNELS")
|
|
||||||
.unwrap_or("".to_string())
|
|
||||||
.parse()
|
|
||||||
.unwrap();
|
|
||||||
}
|
|
||||||
|
|
|
@ -85,7 +85,7 @@
|
||||||
in rec {
|
in rec {
|
||||||
|
|
||||||
packages.default = packages.flake-info;
|
packages.default = packages.flake-info;
|
||||||
packages.flake-info = import ./flake-info { inherit pkgs nixosChannels; };
|
packages.flake-info = import ./flake-info { inherit pkgs; };
|
||||||
packages.frontend = import ./frontend { inherit pkgs nixosChannels version; };
|
packages.frontend = import ./frontend { inherit pkgs nixosChannels version; };
|
||||||
packages.nixosChannels = nixosChannelsFile;
|
packages.nixosChannels = nixosChannelsFile;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue