diff --git a/README.md b/README.md index 438abb7..f37c2ab 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ Here is the script you need to run to get this working: ```sh nix-shell -p git --command "git clone https://github.com/RGBCube/NixOSConfiguration && cd NixOSConfiguration" -./rebuild.sh +nix-shell -p nu --command "nu rebuild.nu" ``` `machine-name` is a machine selected from the machines in the `machines` directory. @@ -24,7 +24,7 @@ Lets say you have changed the configuration and want to apply the changes to your system. You would have to run the rebuild script: ```sh -./rebuild.sh +./rebuild.nu ``` This runs the script interactively. @@ -38,7 +38,15 @@ You can also check how the script is used: This outputs: ``` -Usage: ./rebuild.sh [-h | --help] [machine-name] +Usage: + > rebuild.nu (machine) ...(arguments) + +Flags: + -h, --help - Display the help message for this command + +Parameters: + machine : The machine to build. (optional, default: '') + ...arguments : Extra arguments to pass to nixos-rebuild. ``` ## License diff --git a/flake.lock b/flake.lock index 4a92f81..1b6e3ed 100644 --- a/flake.lock +++ b/flake.lock @@ -21,6 +21,24 @@ "type": "github" } }, + "flake-parts": { + "inputs": { + "nixpkgs-lib": "nixpkgs-lib" + }, + "locked": { + "lastModified": 1698579227, + "narHash": "sha256-KVWjFZky+gRuWennKsbo6cWyo7c/z/VgCte5pR9pEKg=", + "owner": "hercules-ci", + "repo": "flake-parts", + "rev": "f76e870d64779109e41370848074ac4eaa1606ec", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "flake-parts", + "type": "github" + } + }, "home-manager": { "inputs": { "nixpkgs": [ @@ -88,6 +106,43 @@ "type": "github" } }, + "nh": { + "inputs": { + "flake-parts": "flake-parts", + "nix-filter": "nix-filter", + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1698826948, + "narHash": "sha256-Th05oofIIhsN2bmJNsb0Xev3+RJgtk8stjHZX9EdWA0=", + "owner": "viperML", + "repo": "nh", + "rev": "23d21975231d569afbe3973eb19d955c650f8f08", + "type": "github" + }, + "original": { + "owner": "viperML", + "repo": "nh", + "type": "github" + } + }, + "nix-filter": { + "locked": { + "lastModified": 1694857738, + "narHash": "sha256-bxxNyLHjhu0N8T3REINXQ2ZkJco0ABFPn6PIe2QUfqo=", + "owner": "numtide", + "repo": "nix-filter", + "rev": "41fd48e00c22b4ced525af521ead8792402de0ea", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "nix-filter", + "type": "github" + } + }, "nixpkgs": { "locked": { "lastModified": 1698134075, @@ -104,6 +159,24 @@ "type": "github" } }, + "nixpkgs-lib": { + "locked": { + "dir": "lib", + "lastModified": 1696019113, + "narHash": "sha256-X3+DKYWJm93DRSdC5M6K5hLqzSya9BjibtBsuARoPco=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "f5892ddac112a1e9b3612c39af1b72987ee5783a", + "type": "github" + }, + "original": { + "dir": "lib", + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, "nixpkgs_2": { "locked": { "lastModified": 1699099776, @@ -125,6 +198,7 @@ "fenix": "fenix", "home-manager": "home-manager", "hyprland": "hyprland", + "nh": "nh", "nixpkgs": "nixpkgs_2" } }, diff --git a/rebuild.nu b/rebuild.nu new file mode 100755 index 0000000..8499ebe --- /dev/null +++ b/rebuild.nu @@ -0,0 +1,30 @@ +#!/usr/bin/env nu + +def main [ + machine: string = "" # The machine to build. + ...arguments # Extra arguments to pass to nixos-rebuild. +] { + mut machine_ = $machine + + let valid_machines = ls machines | where type == dir | get name | each { $in | str replace "machines/" "" } + + if ($machine_ | is-empty) { + $machine_ = (input $"Select machine to build [($valid_machines | str join ', ')]: ") + + if ($machine_ | is-empty) and ($valid_machines | length) == 1 { + $machine_ = ($valid_machines | get 0) + } else { + main "" ($arguments | str join " ") + exit + } + } + + if not ($machine_ in $valid_machines) { + main "" ($arguments | str join " ") + exit + } + + nix-shell --packages git --command $"sudo nixos-rebuild switch --impure --flake .#($machine) ($arguments | str join ' ')" +} + + diff --git a/rebuild.sh b/rebuild.sh deleted file mode 100755 index 6470704..0000000 --- a/rebuild.sh +++ /dev/null @@ -1,15 +0,0 @@ -#!/bin/sh - -if [[ $1 == "-h" || $1 == "--help" ]]; then - echo "Usage: $0 [-h | --help] [machine-name]" - exit -fi - -machine=$1 - -if [[ $machine == "" ]]; then - available_machines=$(ls --format=commas machines) - read -p "What machine would you like to build? (Possible options: $available_machines): " machine -fi - -nix-shell --packages git --command "sudo nixos-rebuild switch --impure --flake .#$machine"