Add simple nushell update script

finchie
Mar 6, 2024, 7:46 AM
HINOSPQOA75CMI27YWJOFB5ICZYR7WZS576BFUFH57R75W6LNPQQC

Dependencies

Change contents

  • file addition: update.nu (---r------)
    [2.1]
    #!/usr/bin/env nu
    # Learning nushell by writing a simple updater script
    # Mostly just testing out all the different language features
    use std assert;
    const required_paths = [".pijul" "flake.nix"];
    # Helper function to make sure all necessary paths are present
    def assert_path_exists [candidate] {
    assert ($candidate | path exists) $"(ansi red) Failed to find required file: (ansi red_bold)($candidate)(ansi reset)"
    }
    # If not root, need to elevate permissions
    let script_location = $env.CURRENT_FILE;
    let parent_dir = $script_location | path dirname;
    echo $"(ansi purple)Attempting update in (ansi green_bold)($parent_dir)(ansi reset)";
    cd $parent_dir;
    # Check all the required paths are here
    $required_paths | each {|required_path| assert_path_exists $required_path}
    # Make sure to record changes, even if trivial
    pijul record
    nix flake update;
    sudo nixos-rebuild switch --upgrade-all --impure;
    # Upgrade all the other package managers
    topgrade --disable nix --disable system --yes --no-retry