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

[Chore] Make it possible to override input instead of updating #30

Open
wants to merge 2 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
12 changes: 11 additions & 1 deletion module.nix
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@ let
lib.mapAttrsFlatten
(owner: lib.mapAttrsFlatten (repo: settings: { inherit type owner repo settings; })))
cfg.repos));
input_override = lib.types.submodule {
input = lib.mkOption {
type = lib.types.str;
description = "Input to override";
};
override_url = lib.mkOption {
type = lib.types.str;
description = "Input to override";
};
};
in {
options.services.update-daemon = with lib;
with types; {
Expand Down Expand Up @@ -97,7 +107,7 @@ in {
default = 100;
};
inputs = mkOption {
type = listOf str;
type = listOf (either str input_override);
description = "List of input names to be updated, if empty, all inputs will be updated";
default = [];
example = [ "haskell-nix" ];
Expand Down
19 changes: 15 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,24 @@ fn flake_update(
} else {
nix_flake_update.arg("lock");
for input in settings.inputs.iter() {
let input_name = match input {
UpdateOrOverrideInput::Update(input_name) => {
nix_flake_update.arg("--update-input");
nix_flake_update.arg(input_name);
input_name
},
UpdateOrOverrideInput::Override{input, override_url} => {
nix_flake_update.arg("--override-input");
nix_flake_update.arg(input);
nix_flake_update.arg(override_url);
input
},
};
// Abort flake update if input is missing from the flake.lock root nodes
// and allow_missing_inputs is not set
if !settings.allow_missing_inputs && lock.get_root_dep(input.clone()).is_none() {
return Err(FlakeUpdateError::MissingInput(input.clone()));
if !settings.allow_missing_inputs && lock.get_root_dep(input_name.clone()).is_none() {
return Err(FlakeUpdateError::MissingInput(input_name.clone()));
};
nix_flake_update.arg("--update-input");
nix_flake_update.arg(input);
}
};

Expand Down
11 changes: 9 additions & 2 deletions src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub struct UpdateSettings {
pub title: String,
pub extra_body: String,
pub cooldown: Duration,
pub inputs: Vec<String>,
pub inputs: Vec<UpdateOrOverrideInput>,
pub allow_missing_inputs: bool,
}

Expand All @@ -36,10 +36,17 @@ pub struct UpdateSettingsOptional {
pub title: Option<String>,
pub extra_body: Option<String>,
pub cooldown: Option<u64>,
pub inputs: Option<Vec<String>>,
pub inputs: Option<Vec<UpdateOrOverrideInput>>,
pub allow_missing_inputs: Option<bool>,
}

#[derive(Debug, Clone, Deserialize)]
#[serde(untagged)]
pub enum UpdateOrOverrideInput {
Update (String),
Override {input: String, override_url: String},
}

#[derive(Debug, Error)]
pub struct UpdateSettingsMissingField(String);

Expand Down