1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
use crate::PackageManager;
use anyhow::Error;
use std::{env, process::Command};

pub struct Nix {}

impl Nix {
    pub fn new() -> Self {
        Self {}
    }
}

impl PackageManager for Nix {
    fn install(&self, _name: &str) -> Result<(), Error> {
        self.setup()?;
        todo!();
    }

    fn uninstall(&self, _name: &str) -> Result<(), Error> {
        todo!()
    }

    fn setup(&self) -> Result<(), Error> {
        env::set_var(
            "PATH",
            format!(
                "{}:{}",
                env::var("PATH")?,
                "/nix/var/nix/profiles/default/bin"
            ),
        );
        let mut child = Command::new("sh")
        .arg("-c")
        .arg("type nix > /dev/null || curl --proto '=https' --tlsv1.2 -sSf -L https://install.determinate.systems/nix | sh -s -- install")
        .spawn()?;
        child.wait()?;

        let mut child = Command::new("sh")
        .arg("-c")
        .arg("type nix > /dev/null || curl --proto '=https' --tlsv1.2 -sSf -L https://install.determinate.systems/nix | sh -s -- --no-confirm install")
        .spawn()?;
        child.wait()?;

        Ok(())
    }
}