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

handle permissions issues for --update arg #101

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
20 changes: 20 additions & 0 deletions src/home.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::env;
use std::fs::OpenOptions;
use std::ops::Deref;
use std::path::PathBuf;

Expand Down Expand Up @@ -67,6 +68,25 @@ impl HomeRebuildArgs {
panic!("Failed to get Nix version. Custom Nix fork?");
});

// Get the permissions of flake.lock, check if we can write to it
// as the current user. If we can write, proceed with the update
// or else bail out.
let file = OpenOptions::new()
.read(true)
.write(true)
.create(false) // probably the default, but I am not taking my chances -raf
.open("flake.lock");

match file {
Ok(_) => (),
Err(e) => {
panic!(
"nh does not support updating flakes owned by root. Error: {:?}.",
e
);
}
}

// Default interface for updating flake inputs
let mut update_args = vec!["nix", "flake", "update"];

Expand Down
20 changes: 20 additions & 0 deletions src/nixos.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::fs::OpenOptions;
use std::ops::Deref;

use color_eyre::eyre::{bail, Context};
Expand Down Expand Up @@ -54,6 +55,25 @@ impl OsRebuildArgs {
panic!("Failed to get Nix version. Custom Nix fork?");
});

// Get the permissions of flake.lock, check if we can write to it
// as the current user. If we can write, proceed with the update
// or else bail out.
let file = OpenOptions::new()
.read(true)
.write(true)
.create(false) // probably the default, but I am not taking my chances -raf
.open("flake.lock");

match file {
Ok(_) => (),
Err(e) => {
panic!(
"nh does not support updating flakes owned by root. Error: {:?}.",
e
);
}
}

// Default interface for updating flake inputs
let mut update_args = vec!["nix", "flake", "update"];

Expand Down