Switch to a Makefile

This commit is contained in:
Dave Gallant
2021-10-26 22:06:47 -04:00
parent fe1a2654b6
commit 68de2e924b
4 changed files with 33 additions and 33 deletions

21
Makefile Normal file
View File

@@ -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

View File

@@ -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).

18
flake.lock generated
View File

@@ -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": {

View File

@@ -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