Skip to content
Merged
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
19 changes: 18 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ Nh supports both Flakes and classical NixOS configurations:
You might want to check `nh os --help` for other values and the defaults from
environment variables.


#### Specialisations support

Nh is capable of detecting which specialisation you are running, so it runs the proper activation script.
Expand All @@ -91,6 +90,24 @@ To do so, you need to give nh some information of the spec that is currently run
}
```

#### Home-Manager

Home specialisations are read from `~/.local/share/home-manager/specialisation`. The config would look like this:

```nix
{config, pkgs, ...}: {
specialisation."foo".configuration = {
xdg.dataFile."home-manager/specialisation".text = "foo";
# ..rest of config
};

specialisation."bar".configuration = {
xdg.dataFile."home-manager/specialisation".text = "bar";
# ..rest of config
};
}
```


# Status

Expand Down
25 changes: 22 additions & 3 deletions src/home.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,30 @@ impl HomeRebuildArgs {

debug!(?prev_generation);

let spec_location =
PathBuf::from(std::env::var("HOME")?).join(".local/share/home-manager/specialisation");

let current_specialisation = std::fs::read_to_string(spec_location.to_str().unwrap()).ok();

let target_specialisation = if self.no_specialisation {
None
} else {
current_specialisation.or(self.specialisation)
};

debug!("target_specialisation: {target_specialisation:?}");

let target_profile = match &target_specialisation {
None => out_path,
Some(spec) => Box::new(out_path.get_path().join("specialisation").join(spec)),
};

// just do nothing for None case (fresh installs)
if let Some(generation) = prev_generation {
Command::new("nvd")
.arg("diff")
.arg(generation)
.arg(out_path.get_path())
.arg(target_profile.get_path())
.message("Comparing changes")
.run()?;
}
Expand All @@ -96,13 +115,13 @@ impl HomeRebuildArgs {
env::set_var("HOME_MANAGER_BACKUP_EXT", ext);
}

Command::new(out_path.get_path().join("activate"))
Command::new(target_profile.get_path().join("activate"))
.message("Activating configuration")
.run()?;

// Make sure out_path is not accidentally dropped
// https://docs.rs/tempfile/3.12.0/tempfile/index.html#early-drop-pitfall
drop(out_path);
drop(target_profile);

Ok(())
}
Expand Down
8 changes: 8 additions & 0 deletions src/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,14 @@ pub struct HomeRebuildArgs {
#[arg(long, short)]
pub configuration: Option<String>,

/// Explicitely select some specialisation
#[arg(long, short)]
pub specialisation: Option<String>,

/// Ignore specialisations
#[arg(long, short = 'S')]
pub no_specialisation: bool,

/// Extra arguments passed to nix build
#[arg(last = true)]
pub extra_args: Vec<String>,
Expand Down