diff --git a/data/icons/selection-mode-symbolic.svg b/data/icons/selection-mode-symbolic.svg
new file mode 100644
index 0000000..0a984d8
--- /dev/null
+++ b/data/icons/selection-mode-symbolic.svg
@@ -0,0 +1,7 @@
+
+
diff --git a/nsc-helper/src/main.rs b/nsc-helper/src/main.rs
index 8f4bfe0..55513ba 100644
--- a/nsc-helper/src/main.rs
+++ b/nsc-helper/src/main.rs
@@ -82,40 +82,42 @@ fn main() {
}
},
SubCommands::Channel { rebuild: dorebuild, arguments } => {
- match dorebuild {
- true => match rebuild(arguments) {
- Ok(_) => (),
- Err(err) => {
- eprintln!("{}", err);
- std::process::exit(1);
- }
- },
- false => match channel() {
- Ok(_) => (),
- Err(err) => {
- eprintln!("{}", err);
- std::process::exit(1);
+ match channel() {
+ Ok(_) => {
+ if dorebuild {
+ match rebuild(arguments) {
+ Ok(_) => (),
+ Err(err) => {
+ eprintln!("{}", err);
+ std::process::exit(1);
+ }
+ }
}
},
+ Err(err) => {
+ eprintln!("{}", err);
+ std::process::exit(1);
+ }
}
},
SubCommands::Flake { rebuild: dorebuild, flakepath, arguments } => {
- match dorebuild {
- true => match rebuild(arguments) {
- Ok(_) => (),
- Err(err) => {
- eprintln!("{}", err);
- std::process::exit(1);
+ match flake(&flakepath) {
+ Ok(_) => {
+ if dorebuild {
+ match rebuild(arguments) {
+ Ok(_) => (),
+ Err(err) => {
+ eprintln!("{}", err);
+ std::process::exit(1);
+ }
+ }
}
},
- false => match flake(&flakepath) {
- Ok(_) => (),
- Err(err) => {
- eprintln!("{}", err);
- std::process::exit(1);
- }
- },
- }
+ Err(err) => {
+ eprintln!("{}", err);
+ std::process::exit(1);
+ }
+ }
}
}
}
@@ -164,7 +166,7 @@ fn channel() -> Result<(), Box> {
fn flake(path: &str) -> Result<(), Box> {
let mut cmd = Command::new("nix")
.arg("flake")
- .arg("upgrade")
+ .arg("update")
.arg(path)
.spawn()?;
let x = cmd.wait()?;
diff --git a/src/main.rs b/src/main.rs
index faf56cb..3e1e5bf 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,10 +1,12 @@
use adw::gio;
use nix_software_center::ui::window::AppModel;
use relm4::*;
+use nix_software_center::config::PKGDATADIR;
fn main() {
pretty_env_logger::init();
- let res = gio::Resource::load("@PKGDATA_DIR@".to_string() + "/resources.gresource").unwrap();
- gio::resources_register(&res);
+ if let Ok(res) = gio::Resource::load(PKGDATADIR.to_string() + "/resources.gresource") {
+ gio::resources_register(&res);
+ }
let app = RelmApp::new("dev.vlinkz.NixSoftwareCenter");
let application = app.app.clone();
app.run::(application);
diff --git a/src/meson.build b/src/meson.build
index af8105e..59ef8b0 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -11,7 +11,9 @@ resources = gnome.compile_resources(
'resources',
'resources.gresource.xml',
gresource_bundle: true,
- source_dir: meson.current_build_dir()
+ source_dir: meson.current_build_dir(),
+ install: true,
+ install_dir: pkgdatadir,
)
config = configure_file(
diff --git a/src/parse/cache.rs b/src/parse/cache.rs
index 69423a2..c26fb6f 100644
--- a/src/parse/cache.rs
+++ b/src/parse/cache.rs
@@ -11,6 +11,8 @@ use std::{
process::Command,
};
+use crate::ui::window::{SystemPkgs, UserPkgs};
+
#[derive(Serialize, Deserialize, Debug)]
struct NewPackageBase {
packages: HashMap,
@@ -21,11 +23,20 @@ struct NewPackage {
version: IString,
}
-pub fn checkcache() -> Result<(), Box> {
- // setuplegacypkgscache().unwrap();
- // setupupdatecache().unwrap();
- // setupnewestver().unwrap();
- setupflakepkgscache()?;
+pub fn checkcache(syspkgs: SystemPkgs, userpkgs: UserPkgs) -> Result<(), Box> {
+ match syspkgs {
+ SystemPkgs::Legacy => {
+ setuplegacypkgscache().unwrap();
+ setupupdatecache().unwrap();
+ setupnewestver().unwrap();
+ }
+ SystemPkgs::Flake => {
+ setupflakepkgscache()?;
+ }
+ }
+ if userpkgs == UserPkgs::Profile {
+ setupprofilepkgscache()?;
+ }
Ok(())
}
@@ -172,13 +183,15 @@ fn setupflakepkgscache() -> Result<(), Box> {
if Path::new(format!("{}/chnver.txt", &cachedir).as_str()).exists() {
fs::remove_file(format!("{}/chnver.txt", &cachedir).as_str())?;
}
-
- let vout = Command::new("nixos-version")
- .arg("--json")
- .output()?;
-
+
+ let vout = Command::new("nixos-version").arg("--json").output()?;
+
let versiondata: Value = serde_json::from_str(&String::from_utf8_lossy(&vout.stdout))?;
- let rev = versiondata.get("nixpkgsRevision").unwrap().as_str().unwrap();
+ let rev = versiondata
+ .get("nixpkgsRevision")
+ .unwrap()
+ .as_str()
+ .unwrap();
let dlver = versiondata.get("nixosVersion").unwrap().as_str().unwrap();
let mut relver = dlver.split('.').collect::>()[0..2].join(".");
@@ -214,23 +227,13 @@ fn setupflakepkgscache() -> Result<(), Box> {
Ok(())
}
- fn writeprofilepkgs(outfile: &str) -> Result<(), Box> {
- let output = Command::new("nix")
- .arg("search")
- .arg("nixpkgs")
- .arg("--json")
- .output()?;
- let mut file = fs::File::create(outfile)?;
- file.write_all(&output.stdout)?;
- Ok(())
- }
-
if !Path::new(&format!("{}/flakever.txt", &cachedir)).exists() {
let mut sysver = fs::File::create(format!("{}/flakever.txt", &cachedir))?;
sysver.write_all(rev.as_bytes())?;
writesyspkgs(&format!("{}/syspackages.json", &cachedir))?;
} else {
- let oldver = fs::read_to_string(&Path::new(format!("{}/flakever.txt", &cachedir).as_str()))?;
+ let oldver =
+ fs::read_to_string(&Path::new(format!("{}/flakever.txt", &cachedir).as_str()))?;
let sysver = rev;
if oldver != sysver {
println!("OLD FLAKEVER: {}, != NEW: {}", oldver, sysver);
@@ -244,41 +247,6 @@ fn setupflakepkgscache() -> Result<(), Box> {
writesyspkgs(&format!("{}/syspackages.json", &cachedir))?;
}
-
-
- // Check nix profile nixpkgs version
- let client = reqwest::blocking::Client::builder()
- .user_agent("request")
- .build()?;
- let response = client.get("https://api.github.com/repos/NixOS/nixpkgs/commits/nixpkgs-unstable").send()?;
- if response.status().is_success() {
- let profilerevjson = response.text()?;
- let profilerevdata: Value = serde_json::from_str(&profilerevjson)?;
- let profilerev = profilerevdata.get("sha").unwrap().as_str().unwrap();
- println!("PROFILE REV {}", profilerev);
-
- if !Path::new(&format!("{}/profilever.txt", &cachedir)).exists() {
- let mut sysver = fs::File::create(format!("{}/profilever.txt", &cachedir))?;
- sysver.write_all(profilerev.as_bytes())?;
- writeprofilepkgs(&format!("{}/profilepackages.json", &cachedir))?;
- } else {
- let oldver = fs::read_to_string(&Path::new(format!("{}/profilever.txt", &cachedir).as_str()))?;
- let sysver = profilerev;
- if oldver != sysver {
- println!("OLD PROFILEVER: {}, != NEW: {}", oldver, sysver);
- let mut sysver = fs::File::create(format!("{}/profilever.txt", &cachedir))?;
- sysver.write_all(profilerev.as_bytes())?;
- writeprofilepkgs(&format!("{}/profilepackages.json", &cachedir))?;
- } else {
- println!("PROFILEVER UP TO DATE");
- }
- }
- }
- if !Path::new(&format!("{}/profilepackages.json", &cachedir)).exists() {
- writeprofilepkgs(&format!("{}/profilepackages.json", &cachedir))?;
- }
-
-
// Check newest nixpkgs version
let revurl = format!("https://channels.nixos.org/nixos-{}/git-revision", relver);
let response = reqwest::blocking::get(revurl)?;
@@ -295,55 +263,81 @@ fn setupflakepkgscache() -> Result<(), Box> {
dl = true;
}
let mut sysver = fs::File::create(format!("{}/newver.txt", &cachedir))?;
- sysver.write_all(newrev.as_bytes())?;
- // if !Path::new(&format!("{}/newver.txt", &cachedir)).exists() {
- // }
+ sysver.write_all(newrev.as_bytes())?;
}
-
-
- // if Path::new(format!("{}/chnver.txt", &cachedir).as_str()).exists()
- // && fs::read_to_string(&Path::new(format!("{}/chnver.txt", &cachedir).as_str()))? == dlver
- // && Path::new(format!("{}/packages.json", &cachedir).as_str()).exists()
- // {
- // return Ok(());
- // } else {
- // let oldver = fs::read_to_string(&Path::new(format!("{}/chnver.txt", &cachedir).as_str()))?;
- // let sysver = &dlver;
- // // Change to debug msg
- // println!("OLD: {}, != NEW: {}", oldver, sysver);
- // }
- // if Path::new(format!("{}/chnver.txt", &cachedir).as_str()).exists() {
- // fs::remove_file(format!("{}/chnver.txt", &cachedir).as_str())?;
- // }
- // let mut sysver = fs::File::create(format!("{}/chnver.txt", &cachedir))?;
- // sysver.write_all(dlver.as_bytes())?;
-
-
-
let outfile = format!("{}/packages.json", &cachedir);
- if dl {
+ if dl {
dlfile(&url, &outfile)?;
}
Ok(())
}
+fn setupprofilepkgscache() -> Result<(), Box> {
+ let cachedir = format!("{}/.cache/nix-software-center", env::var("HOME")?);
+ fn writeprofilepkgs(outfile: &str) -> Result<(), Box> {
+ let output = Command::new("nix")
+ .arg("search")
+ .arg("nixpkgs")
+ .arg("--json")
+ .output()?;
+ let mut file = fs::File::create(outfile)?;
+ file.write_all(&output.stdout)?;
+ Ok(())
+ }
+ // Check nix profile nixpkgs version
+ let client = reqwest::blocking::Client::builder()
+ .user_agent("request")
+ .build()?;
+ let response = client
+ .get("https://api.github.com/repos/NixOS/nixpkgs/commits/nixpkgs-unstable")
+ .send()?;
+ if response.status().is_success() {
+ let profilerevjson = response.text()?;
+ let profilerevdata: Value = serde_json::from_str(&profilerevjson)?;
+ let profilerev = profilerevdata.get("sha").unwrap().as_str().unwrap();
+ println!("PROFILE REV {}", profilerev);
+
+ if !Path::new(&format!("{}/profilever.txt", &cachedir)).exists() {
+ let mut sysver = fs::File::create(format!("{}/profilever.txt", &cachedir))?;
+ sysver.write_all(profilerev.as_bytes())?;
+ writeprofilepkgs(&format!("{}/profilepackages.json", &cachedir))?;
+ } else {
+ let oldver =
+ fs::read_to_string(&Path::new(format!("{}/profilever.txt", &cachedir).as_str()))?;
+ let sysver = profilerev;
+ if oldver != sysver {
+ println!("OLD PROFILEVER: {}, != NEW: {}", oldver, sysver);
+ let mut sysver = fs::File::create(format!("{}/profilever.txt", &cachedir))?;
+ sysver.write_all(profilerev.as_bytes())?;
+ writeprofilepkgs(&format!("{}/profilepackages.json", &cachedir))?;
+ } else {
+ println!("PROFILEVER UP TO DATE");
+ }
+ }
+ }
+ if !Path::new(&format!("{}/profilepackages.json", &cachedir)).exists() {
+ writeprofilepkgs(&format!("{}/profilepackages.json", &cachedir))?;
+ }
+ Ok(())
+}
+
// nix-instantiate --eval -E '(builtins.getFlake "/home/victor/nix").inputs.nixpkgs.outPath'
// nix-env -f /nix/store/sjmq1gphj1arbzf4aqqnygd9pf4hkfkf-source -qa --json > packages.json
fn setupupdatecache() -> Result<(), Box> {
let vout = Command::new("nix-instantiate")
- .arg("-I")
- .arg("nixpkgs=/nix/var/nix/profiles/per-user/root/channels/nixos")
- .arg("")
- .arg("-A")
- .arg("version")
- .arg("--eval")
- .arg("--json")
- .output()?;
+ .arg("-I")
+ .arg("nixpkgs=/nix/var/nix/profiles/per-user/root/channels/nixos")
+ .arg("")
+ .arg("-A")
+ .arg("version")
+ .arg("--eval")
+ .arg("--json")
+ .output()?;
-let dlver = String::from_utf8_lossy(&vout.stdout)
- .to_string()
- .replace('"', "");
+ let dlver = String::from_utf8_lossy(&vout.stdout)
+ .to_string()
+ .replace('"', "");
// let dlver = fs::read_to_string("/run/current-system/nixos-version")?;
let mut relver = dlver.split('.').collect::>().join(".")[0..5].to_string();
diff --git a/src/resources.gresource.xml b/src/resources.gresource.xml
index 34486de..3cb266a 100644
--- a/src/resources.gresource.xml
+++ b/src/resources.gresource.xml
@@ -2,5 +2,6 @@
../data/icons/compass-symbolic.svg
+ ../data/icons/selection-mode-symbolic.svg
\ No newline at end of file
diff --git a/src/ui/updateworker.rs b/src/ui/updateworker.rs
index 244c482..f61ea21 100644
--- a/src/ui/updateworker.rs
+++ b/src/ui/updateworker.rs
@@ -110,7 +110,10 @@ impl Worker for UpdateAsyncHandler {
let syspkgs = self.syspkgs.clone();
relm4::spawn(async move {
println!("STARTED");
- let result = runcmd(NscCmd::Rebuild, systenconfig, flakeargs, syspkgs).await;
+ let result = match syspkgs {
+ SystemPkgs::Legacy => runcmd(NscCmd::Rebuild, systenconfig, flakeargs, syspkgs).await,
+ SystemPkgs::Flake => runcmd(NscCmd::All, systenconfig, flakeargs, syspkgs).await,
+ };
match result {
Ok(true) => {
println!("REBUILD DONE");
@@ -150,24 +153,14 @@ impl Worker for UpdateAsyncHandler {
let userpkgs = self.userpkgs.clone();
relm4::spawn(async move {
println!("STARTED");
- // if syspkgs == SystemPkgs::Flake {
- // if let Some(fa) = &flakeargs {
- // match updateflake(fa.split('#').collect::>().first().unwrap().to_string()).await {
- // Ok(true) => {
- // println!("FLAKE DONE");
- // }
- // _ => {
- // println!("FLAKE FAILED");
- // sender.output(UpdatePageMsg::FailedWorking);
- // }
- // }
- // }
- // }
let result = runcmd(NscCmd::All, systemconfig, flakeargs, syspkgs).await;
match result {
Ok(true) => {
println!("ALL pkexec DONE");
- match updateenv().await {
+ match match userpkgs {
+ UserPkgs::Env => updateenv().await,
+ UserPkgs::Profile => updateprofile().await,
+ } {
Ok(true) => {
println!("ALL DONE");
sender.output(UpdatePageMsg::DoneWorking);
@@ -251,7 +244,7 @@ async fn runcmd(
.args(&rebuildargs)
.stderr(Stdio::piped())
.spawn()?,
- SystemPkgs::Flake => tokio::process::Command::new("pkexec")
+ SystemPkgs::Flake => { println!("ALL FLAKE UPDATE!!!!!!!!!!!!!!!!!!!!!!"); tokio::process::Command::new("pkexec")
.arg(&exe)
.arg("flake")
.arg("--rebuild")
@@ -261,7 +254,7 @@ async fn runcmd(
.arg("switch")
.args(&rebuildargs)
.stderr(Stdio::piped())
- .spawn()?,
+ .spawn()? },
},
};
diff --git a/src/ui/window.rs b/src/ui/window.rs
index 44e9ce6..735a1bc 100644
--- a/src/ui/window.rs
+++ b/src/ui/window.rs
@@ -489,6 +489,8 @@ impl Component for AppModel {
searchvs.set_name(Some("search"));
updatesvs.set_name(Some("updates"));
frontvs.set_icon_name(Some("compass"));
+ installedvs.set_icon_name(Some("selection-mode"));
+ updatesvs.set_icon_name(Some("emblem-synchronizing-symbolic"));
ComponentParts { model, widgets }
}
diff --git a/src/ui/windowloading.rs b/src/ui/windowloading.rs
index e195ce0..f0310f3 100644
--- a/src/ui/windowloading.rs
+++ b/src/ui/windowloading.rs
@@ -41,8 +41,10 @@ impl Worker for WindowAsyncHandler {
match msg {
WindowAsyncHandlerMsg::CheckCache(cr, syspkgs, userpkgs) => {
println!("CHECK CACHE");
+ let syspkgs2 = syspkgs.clone();
+ let userpkgs2 = userpkgs.clone();
relm4::spawn(async move {
- match checkcache() {
+ match checkcache(syspkgs2, userpkgs2) {
Ok(_) => {}
Err(_) => {
println!("FAILED TO CHECK CACHE");