Skip to content

Instantly share code, notes, and snippets.

@lvnilesh
Forked from 0atman/configuration.nix
Created April 28, 2025 01:38
Show Gist options
  • Select an option

  • Save lvnilesh/92bdc77dfc703bd9e96baf342187c6f5 to your computer and use it in GitHub Desktop.

Select an option

Save lvnilesh/92bdc77dfc703bd9e96baf342187c6f5 to your computer and use it in GitHub Desktop.

Revisions

  1. @0atman 0atman revised this gist Mar 20, 2024. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions nixos-rebuild.sh
    Original file line number Diff line number Diff line change
    @@ -19,7 +19,7 @@ $EDITOR configuration.nix
    pushd ~/dotfiles/nixos/

    # Early return if no changes were detected (thanks @singiamtel!)
    if git diff --quiet *.nix; then
    if git diff --quiet '*.nix'; then
    echo "No changes detected, exiting."
    popd
    exit 0
    @@ -30,7 +30,7 @@ alejandra . &>/dev/null \
    || ( alejandra . ; echo "formatting failed!" && exit 1)

    # Shows your changes
    git diff -U0 *.nix
    git diff -U0 '*.nix'

    echo "NixOS Rebuilding..."

  2. @0atman 0atman revised this gist Mar 19, 2024. 1 changed file with 3 additions and 2 deletions.
    5 changes: 3 additions & 2 deletions nixos-rebuild.sh
    Original file line number Diff line number Diff line change
    @@ -26,15 +26,16 @@ if git diff --quiet *.nix; then
    fi

    # Autoformat your nix files
    alejandra . >/dev/null
    alejandra . &>/dev/null \
    || ( alejandra . ; echo "formatting failed!" && exit 1)

    # Shows your changes
    git diff -U0 *.nix

    echo "NixOS Rebuilding..."

    # Rebuild, output simplified errors, log trackebacks
    sudo nixos-rebuild switch &>nixos-switch.log || (cat nixos-switch.log | grep --color error && false)
    sudo nixos-rebuild switch &>nixos-switch.log || (cat nixos-switch.log | grep --color error && exit 1)

    # Get current generation metadata
    current=$(nixos-rebuild list-generations | grep current)
  3. @0atman 0atman revised this gist Mar 19, 2024. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions nixos-rebuild.sh
    Original file line number Diff line number Diff line change
    @@ -12,6 +12,9 @@
    # A rebuild script that commits on a successful build
    set -e

    # Edit your config
    $EDITOR configuration.nix

    # cd to your config dir
    pushd ~/dotfiles/nixos/

    @@ -22,9 +25,6 @@ if git diff --quiet *.nix; then
    exit 0
    fi

    # Edit your config
    $EDITOR configuration.nix

    # Autoformat your nix files
    alejandra . >/dev/null

  4. @0atman 0atman revised this gist Mar 15, 2024. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion nixos-rebuild.sh
    Original file line number Diff line number Diff line change
    @@ -15,7 +15,7 @@ set -e
    # cd to your config dir
    pushd ~/dotfiles/nixos/

    # Exit early if no files changed (thanks @singiamtel!)
    # Early return if no changes were detected (thanks @singiamtel!)
    if git diff --quiet *.nix; then
    echo "No changes detected, exiting."
    popd
  5. @0atman 0atman revised this gist Mar 15, 2024. 1 changed file with 7 additions and 0 deletions.
    7 changes: 7 additions & 0 deletions nixos-rebuild.sh
    Original file line number Diff line number Diff line change
    @@ -15,6 +15,13 @@ set -e
    # cd to your config dir
    pushd ~/dotfiles/nixos/

    # Exit early if no files changed (thanks @singiamtel!)
    if git diff --quiet *.nix; then
    echo "No changes detected, exiting."
    popd
    exit 0
    fi

    # Edit your config
    $EDITOR configuration.nix

  6. @0atman 0atman revised this gist Mar 3, 2024. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions nixos-rebuild.sh
    Original file line number Diff line number Diff line change
    @@ -6,6 +6,7 @@
    # 2. Symlinking to your own configuration.nix in your home directory (I think I tried and abandoned this and links made relative paths weird)
    # 3. My new favourite way: as @clot27 says, you can provide nixos-rebuild with a path to the config, allowing it to be entirely inside your dotfies, with zero bootstrapping of files required.
    # `nixos-rebuild switch -I nixos-config=path/to/configuration.nix`
    # 4. If you uses a flake as your primary config, you can specify a path to `configuration.nix` in it and then `nixos-rebuild switch —flake` path/to/directory
    # As I hope was clear from the video, I am new to nixos, and there may be other, better, options, in which case I'd love to know them! (I'll update the gist if so)

    # A rebuild script that commits on a successful build
  7. @0atman 0atman revised this gist Mar 3, 2024. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion nixos-rebuild.sh
    Original file line number Diff line number Diff line change
    @@ -18,7 +18,7 @@ pushd ~/dotfiles/nixos/
    $EDITOR configuration.nix

    # Autoformat your nix files
    alejandra . &>/dev/null
    alejandra . >/dev/null

    # Shows your changes
    git diff -U0 *.nix
  8. @0atman 0atman revised this gist Mar 3, 2024. No changes.
  9. @0atman 0atman revised this gist Mar 2, 2024. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion nixos-rebuild.sh
    Original file line number Diff line number Diff line change
    @@ -5,7 +5,7 @@
    # 1. My current way, using a minimal /etc/nixos/configuration.nix that just imports my config from my home directory (see it in the gist)
    # 2. Symlinking to your own configuration.nix in your home directory (I think I tried and abandoned this and links made relative paths weird)
    # 3. My new favourite way: as @clot27 says, you can provide nixos-rebuild with a path to the config, allowing it to be entirely inside your dotfies, with zero bootstrapping of files required.
    #
    # `nixos-rebuild switch -I nixos-config=path/to/configuration.nix`
    # As I hope was clear from the video, I am new to nixos, and there may be other, better, options, in which case I'd love to know them! (I'll update the gist if so)

    # A rebuild script that commits on a successful build
  10. @0atman 0atman revised this gist Mar 2, 2024. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion configuration.nix
    Original file line number Diff line number Diff line change
    @@ -4,7 +4,7 @@
    options,
    ...
    }: let
    hostname = "oatman-pc";
    hostname = "oatman-pc"; # to alllow per-machine config
    in {
    networking.hostName = hostname;

  11. @0atman 0atman revised this gist Mar 2, 2024. 1 changed file with 15 additions and 0 deletions.
    15 changes: 15 additions & 0 deletions configuration.nix
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,15 @@
    {
    config,
    pkgs,
    options,
    ...
    }: let
    hostname = "oatman-pc";
    in {
    networking.hostName = hostname;

    imports = [
    /etc/nixos/hardware-configuration.nix
    (/home/oatman/dotfiles/nixos + "/${hostname}.nix")
    ];
    }
  12. @0atman 0atman revised this gist Mar 2, 2024. 1 changed file with 9 additions and 0 deletions.
    9 changes: 9 additions & 0 deletions nixos-rebuild.sh
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,13 @@
    #!/usr/bin/env bash
    #
    # I believe there are a few ways to do this:
    #
    # 1. My current way, using a minimal /etc/nixos/configuration.nix that just imports my config from my home directory (see it in the gist)
    # 2. Symlinking to your own configuration.nix in your home directory (I think I tried and abandoned this and links made relative paths weird)
    # 3. My new favourite way: as @clot27 says, you can provide nixos-rebuild with a path to the config, allowing it to be entirely inside your dotfies, with zero bootstrapping of files required.
    #
    # As I hope was clear from the video, I am new to nixos, and there may be other, better, options, in which case I'd love to know them! (I'll update the gist if so)

    # A rebuild script that commits on a successful build
    set -e

  13. @0atman 0atman revised this gist Feb 27, 2024. 1 changed file with 20 additions and 2 deletions.
    22 changes: 20 additions & 2 deletions nixos-rebuild.sh
    Original file line number Diff line number Diff line change
    @@ -2,13 +2,31 @@
    # A rebuild script that commits on a successful build
    set -e

    # cd to your config dir
    pushd ~/dotfiles/nixos/
    nvim configuration.nix

    # Edit your config
    $EDITOR configuration.nix

    # Autoformat your nix files
    alejandra . &>/dev/null

    # Shows your changes
    git diff -U0 *.nix

    echo "NixOS Rebuilding..."

    # Rebuild, output simplified errors, log trackebacks
    sudo nixos-rebuild switch &>nixos-switch.log || (cat nixos-switch.log | grep --color error && false)

    # Get current generation metadata
    current=$(nixos-rebuild list-generations | grep current)

    # Commit all changes witih the generation metadata
    git commit -am "$current"

    # Back to where you were
    popd
    notify-send -e "NixOS Rebuilt OK!" --icon=software-update-available

    # Notify all OK!
    notify-send -e "NixOS Rebuilt OK!" --icon=software-update-available
  14. @0atman 0atman revised this gist Feb 27, 2024. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion nixos-rebuild.sh
    Original file line number Diff line number Diff line change
    @@ -7,7 +7,7 @@ nvim configuration.nix
    alejandra . &>/dev/null
    git diff -U0 *.nix
    echo "NixOS Rebuilding..."
    sudo nixos-rebuild switch --impure --flake /etc/nixos/#default &>nixos-switch.log || (cat nixos-switch.log | grep --color error && false)
    sudo nixos-rebuild switch &>nixos-switch.log || (cat nixos-switch.log | grep --color error && false)
    current=$(nixos-rebuild list-generations | grep current)
    git commit -am "$current"
    popd
  15. @0atman 0atman revised this gist Feb 27, 2024. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion nixos-rebuild.sh
    Original file line number Diff line number Diff line change
    @@ -3,7 +3,7 @@
    set -e

    pushd ~/dotfiles/nixos/
    nvim oatman-pc.nix
    nvim configuration.nix
    alejandra . &>/dev/null
    git diff -U0 *.nix
    echo "NixOS Rebuilding..."
  16. @0atman 0atman revised this gist Feb 25, 2024. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion nixos-rebuild.sh
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    #!/bin/bash
    #!/usr/bin/env bash
    # A rebuild script that commits on a successful build
    set -e

  17. @0atman 0atman revised this gist Feb 25, 2024. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion nixos-rebuild.sh
    Original file line number Diff line number Diff line change
    @@ -4,11 +4,11 @@ set -e

    pushd ~/dotfiles/nixos/
    nvim oatman-pc.nix
    alejandra . &>/dev/null
    git diff -U0 *.nix
    echo "NixOS Rebuilding..."
    sudo nixos-rebuild switch --impure --flake /etc/nixos/#default &>nixos-switch.log || (cat nixos-switch.log | grep --color error && false)
    current=$(nixos-rebuild list-generations | grep current)
    alejandra . &>/dev/null
    git commit -am "$current"
    popd
    notify-send -e "NixOS Rebuilt OK!" --icon=software-update-available
  18. @0atman 0atman renamed this gist Feb 24, 2024. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  19. @0atman 0atman created this gist Feb 24, 2024.
    14 changes: 14 additions & 0 deletions rebuild.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,14 @@
    #!/bin/bash
    # A rebuild script that commits on a successful build
    set -e

    pushd ~/dotfiles/nixos/
    nvim oatman-pc.nix
    git diff -U0 *.nix
    echo "NixOS Rebuilding..."
    sudo nixos-rebuild switch --impure --flake /etc/nixos/#default &>nixos-switch.log || (cat nixos-switch.log | grep --color error && false)
    current=$(nixos-rebuild list-generations | grep current)
    alejandra . &>/dev/null
    git commit -am "$current"
    popd
    notify-send -e "NixOS Rebuilt OK!" --icon=software-update-available