Explore nixos-unified as an alternative to flake-parts and colmena #109
Labels
No labels
needs/docs
needs/research
needs/upstream
type/bug
type/external
type/feature
type/refactor
urgency
high
urgency
immediate
urgency
low
urgency
medium
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
ScottyLabs/infrastructure#109
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
nixos-unified is a flake-parts module that unifies NixOS + nix darwin + homemanger configuration in a single flake. It provides consistent interface at the DX and UX level.
.#activate can activate things in one click and remotely over SSH and therefore acts as an alternative to colmena.
.#update can be used to update the primary inputs (which can be overridden)
NIXos/nix-darwin/home-manager modules receive specialargs which includes all information in the top level flake. It also has sensible defaults.
It also autowires flake outputs.
https://nixos-unified.org/
Initializing templates using Omnix
nix --accept-flake-config run github:juspay/omnix --
init -o ~/nix-config github:srid/nixos-unified#linux
nix run .#activate (nix run .#activate $USER@
If errors on Mac:
nix --accept-flake-config run github:juspay/omnix --
init -o ~/nix-config github:srid/nixos-unified#macos
sudo mv /etc/nix/nix.conf /etc/nix/nix.conf.before-nix-darwin
nix --extra-experimental-features "nix-command flakes" run .#activate
nix run .#activate (nix run .#activate $USER@
To activate a system for the current host, run
nix run .#activate
If you want sudoers to match a single command, configure the target host to run this code since by default, nixos-rebuild decides when to invoke sudo for privileged steps.
{
nixos-unified.localPrivilegeMode = "sudo-nixos-rebuild";
}
Optionally, you can use this to add a narrowly scoped sudoers rule for the user and command you use for activation
{
security.sudo.extraRules = [
{
users = [ "myuser" ];
commands = [
{
command = "/run/current-system/sw/bin/nixos-rebuild switch *";
options = [ "NOPASSWD" ];
}
];
}
];
}
For remote activation, set the nixos-unified.sshTarget option in configuration then run the code to deply to myhost from any machine.
{
nixos-unified.sshTarget = "myuser@myhost";
}
nix run .#activate myhost
Remote activation doesn't replace other deployment tools so it doesn't provide features like rollbacks.
For home-manager configuration, check the website for activation: https://nixos-unified.org/guide/activate
NixOS, nix-darwin, and home-manager modules implicitly receive a specialArgs called flake. Components of flake attrset are
inputs: inputs of your flake; inputs.self referring to the flake itself
config: the flake-parts perSystem config.
Example of how inputs and config can be used:
{ flake, pkgs, lib, ... }:
let
inherit (flake) config inputs;
inherit (inputs) self;
in
{
imports = [
# Reference a flake input directly from a nix-darwin module
inputs.agenix.darwinModules.default
];
Reference an arbitrary flake-parts config
home-manager.users.${config.me.username} = { };
}
Importing nixos-unified flake-parts module will autowire the following flake outputs in your flake
nixos-unified.lib: functions like mkLinuxSystem, mcMacosSystem and mkHomeConfiguration
packages.update: flake app to update key flake inputs
packages.activate: flake app to build and activate the system or home configuration
All NixOS/nix-darwin/home-manager modules implicitly receive the following specialArgs:
flake@{self, inputs, config} (config is from flake parts)
rosettaPkgs (if on darwin)
According to AI, Flake-parts provides an autowiring system where configuration files are automatically wired to standard flake-parts outputs.
Nixos-unified performs a similar function to colemna, allowing users to deploy over SSH without needing to install, configure, or learn Colemna.
Implementation: Start with a Template (probably the official one)
Organize .nix files into standard directories, like configurations/, modules/nixos/, modules/darwin/, or modules/home/. Autowiring automatically scans these directories and builds flake outputs.
For small projects like Scottylabs, applying nixos-unified is beneficial and relatively a simple task.
Run this command for the template:
nix --accept-flake-config run github:juspay/omnix --
init -o ~/nix-config github:srid/nixos-unified#linux
nix run .#activate (nix run .#activate $USER@