| npins | ||
| src | ||
| .envrc | ||
| .gitignore | ||
| Cargo.lock | ||
| Cargo.toml | ||
| LICENSE | ||
| package.nix | ||
| README.md | ||
| shell.nix | ||
nake the humble NixOS build tool
I wrote this to simplify calling multiple commands that have dependent outputs on eachother in NixOS build process.
This is partially due to the fact that I am weird and I do all of my
configuration without any nixos-rebuild or flakes.
the setup
nake expects the current working directory to contain default.nix
with the following schema:
{
<name> = <config>;
...
}
if your hostname matches any <name> attribute, it is picked by
default.
pushing updates
nake allows for pushing updates to remote servers, from the comfort
of your own device. To do this you must have been selected as a
"trusted user" on your target.
This is usually done with setting nix.settings.trusted-users either
with your remote username or @group.
rollbacks
nake enables you to automatically roll-back remote machines that are
unreachable after the configuration change. This is done in two parts,
a nix module and support in nake itself.
Use the following in your config: (this was taken from switch-fix.nix https://github.com/femtodata/nix-utils/blob/main/modules/switch-fix.nix, BSD-2 license)
{ pkgs, ... }:
let
rollback-profile-path = "/var/lib/nix-autorollback/profile";
rollback-delay = "90";
set-rollback = pkgs.writeShellScriptBin "set-rollback" ''
sudo mkdir -p $(dirname ${rollback-profile-path})
sudo ln -sf $(readlink /run/current-system) ${rollback-profile-path}
'';
cancel-rollback = pkgs.writeShellScriptBin "cancel-rollback" ''
sudo systemctl stop nix-autorollback.service
sudo rm ${rollback-profile-path}
'';
in
{
environment.systemPackages = [
switch-fix
boot-fix
set-rollback
cancel-rollback
];
systemd.services."nix-autorollback" = {
description = "rollback to set profile unless stopped";
wantedBy = [ "sysinit.target" ];
script = ''
if [ -d ${rollback-profile-path} ]; then
${pkgs.util-linux}/bin/wall -t 5 "Autorollback in ${rollback-delay}"
echo "Autorollback in ${rollback-delay}"
${pkgs.coreutils}/bin/sleep ${rollback-delay}
${pkgs.util-linux}/bin/wall "Rolling back to $(readlink ${rollback-profile-path})"
echo "Rolling back to $(readlink ${rollback-profile-path})"
${pkgs.nix}/bin/nix-env --profile /nix/var/nix/profiles/system --set $(readlink ${rollback-profile-path})
$(readlink ${rollback-profile-path})/bin/switch-to-configuration boot
rm ${rollback-profile-path}
${pkgs.systemd}/bin/shutdown -r now
fi
'';
serviceConfig = {
Type = "simple";
User = "root";
};
};
}