From 68de2e924b96ebadae317bf4c925b2e25f4ff8de Mon Sep 17 00:00:00 2001 From: Dave Gallant Date: Tue, 26 Oct 2021 22:06:47 -0400 Subject: [PATCH] Switch to a Makefile --- Makefile | 21 +++++++++++++++++++++ README.md | 7 +++---- flake.lock | 18 +++++++++--------- rebuild.sh | 20 -------------------- 4 files changed, 33 insertions(+), 33 deletions(-) create mode 100644 Makefile delete mode 100755 rebuild.sh diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..ac7a1ed --- /dev/null +++ b/Makefile @@ -0,0 +1,21 @@ +SHELL := bash +.SHELLFLAGS := -eu -o pipefail -c +.DELETE_ON_ERROR: +MAKEFLAGS += --warn-undefined-variables +MAKEFLAGS += --no-builtin-rules + +HOSTAME ?= $(shell hostname) +UNAME_S := $(shell uname -s) + +ifeq ($(UNAME_S),Linux) + SWITCH_CMD := sudo nixos-rebuild -I nixos-config="machines/$(HOSTNAME)/configuration.nix" switch --flake '.\#' +endif +ifeq ($(UNAME_S),Darwin) + SWITCH_CMD := exec darwin-rebuild switch --flake . +endif + +switch: + $(SWITCH_CMD) + +update: + nix flake update diff --git a/README.md b/README.md index b4cf541..76efe2b 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ [![built with nix](https://builtwithnix.org/badge.svg)](https://builtwithnix.org) -This repo stores nix to manage my machines running both [NixOS](https://nixos.org/) and macOS. The initial structure was inspired by [samuelgrf/nixos-config](https://gitlab.com/samuelgrf/nixos-config/-/tree/master/). +This repo stores nix to manage my machines running both [NixOS](https://nixos.org/) and macOS. The configuration is very specific to my own machines and setup, but it may be a useful reference for anyone else learning or experimenting with nix, whether it be on a personal machine or a server. @@ -14,16 +14,15 @@ The configuration is very specific to my own machines and setup, but it may be a To run a rebuild: ```sh -./rebuild.sh switch +make switch ``` - ## Update To update nixpkgs defined in [flake.nix](./flake.nix), run: ```sh -nix flake update +make update ``` If there are updates, they should be reflected in [flake.lock](./flake.lock). diff --git a/flake.lock b/flake.lock index 95fe87c..c7b6409 100644 --- a/flake.lock +++ b/flake.lock @@ -58,11 +58,11 @@ ] }, "locked": { - "lastModified": 1635017514, - "narHash": "sha256-tdV/y8nJZqKDoqFVE8ORB0drdGdSze2xeWfhWz9M3oo=", + "lastModified": 1635285717, + "narHash": "sha256-CGsOBSkdjIHmKEbUkik1JKQhiKCJ64Hj7dROx7yEDCo=", "owner": "nix-community", "repo": "home-manager", - "rev": "406eeec0b98903561767ce7aca311034d298d53e", + "rev": "46a69810cb95d2e7286089830dc535d6719eaa6f", "type": "github" }, "original": { @@ -81,11 +81,11 @@ }, "locked": { "dir": "contrib", - "lastModified": 1635040504, - "narHash": "sha256-EtwuXPxOnITZSyQKO4OiB4mc6GFFPYhyA+dtJIX87DQ=", + "lastModified": 1635085216, + "narHash": "sha256-gy1TjtpL8Sjaa7UnwsdcgmvsxA57D16kXMbDqSfHgGI=", "owner": "neovim", "repo": "neovim", - "rev": "6acebb8b56e21247423a5692e9ca30dff05abb63", + "rev": "09e96fe6096f07365eb65b51bb7f2fd0f1b043b0", "type": "github" }, "original": { @@ -102,11 +102,11 @@ "nixpkgs": "nixpkgs" }, "locked": { - "lastModified": 1635063163, - "narHash": "sha256-RZ2xoYcAnk67UTy0isQ5+UEwQ5uBffrzU5wUKGC3saw=", + "lastModified": 1635149654, + "narHash": "sha256-JxqJEtG744ZMrLiGxZgoGh2eWergDVm9VN5xSgPyo8E=", "owner": "nix-community", "repo": "neovim-nightly-overlay", - "rev": "5ff5c9f2d167d348bd959fa4eddf37e84493a261", + "rev": "c4e9149ff03c9d77bc9023d1bd658bfbb3035bc0", "type": "github" }, "original": { diff --git a/rebuild.sh b/rebuild.sh deleted file mode 100755 index 304fc75..0000000 --- a/rebuild.sh +++ /dev/null @@ -1,20 +0,0 @@ -#!/usr/bin/env bash - -cd "$(dirname "$0")" || exit - -uname="$(uname -s)" -case "${uname}" in -Linux*) machine=linux ;; -Darwin*) machine=mac ;; -*) machine="unknown" ;; -esac - -if [[ "$machine" == "linux" ]]; then - sudo nixos-rebuild -I nixos-config="machines/$(hostname)/configuration.nix" "$@" --flake '.#' -elif [[ "$machine" == "mac" ]]; then - exec darwin-rebuild "$@" --flake . -else - echo 'Unsupported OS.' - echo 'Exiting...' - exit 1 -fi