NixOS build helper tool
Find a file
2025-09-16 15:16:34 +02:00
npins Innitial proof of concept :) 2025-09-09 17:46:09 +02:00
src We don't need switch fix we do it ourselves 2025-09-16 15:16:34 +02:00
.envrc Innitial proof of concept :) 2025-09-09 17:46:09 +02:00
.gitignore Innitial proof of concept :) 2025-09-09 17:46:09 +02:00
Cargo.lock Add tokio 2025-09-15 20:06:32 +02:00
Cargo.toml Add tokio 2025-09-15 20:06:32 +02:00
LICENSE Add license 2025-09-09 18:06:15 +02:00
package.nix Add tokio 2025-09-15 20:06:32 +02:00
README.md We don't need switch fix we do it ourselves 2025-09-16 15:16:34 +02:00
shell.nix Add tokio 2025-09-15 20:06:32 +02:00

nake the humble NixOS build tool

enbyware

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";
    };
  };
}