diff options
Diffstat (limited to 'nixos')
-rw-r--r-- | nixos/README.md | 9 | ||||
-rw-r--r-- | nixos/hamac-configuration.nix (renamed from nixos/configuration.nix) | 5 | ||||
-rw-r--r-- | nixos/hamac-hardware-configuration.nix (renamed from nixos/hardware-configuration.nix) | 0 | ||||
-rw-r--r-- | nixos/nixpkgs/path.nix | 2 | ||||
-rwxr-xr-x | nixos/rebuild | 28 |
5 files changed, 33 insertions, 11 deletions
diff --git a/nixos/README.md b/nixos/README.md index 6c4bcb1..1a9c50e 100644 --- a/nixos/README.md +++ b/nixos/README.md @@ -31,10 +31,13 @@ We're assuming that you just installed NixOS by going through the [official inst ``` nixos-generate-config --dir . ``` -3. Pin Nixpkgs to the [latest stable version](https://nixos.org/manual/nixos/stable/release-notes) using npins: +3. Rename the files to `$host-configuration.nix` and `$host-hardware-configuration.nix` where `$host` is the configured hostname. + Add `# channel="..."` to the start of the `$host-configuration.nix` file where `...` is the key of a channel pinned in `npins/sources.json`. + A new channel can be pinned with: + ``` nix-shell -p npins --run \ - 'npins init --bare && npins add --name nixos channel nixos-23.11' + 'npins add --name nixos channel nixos-23.11' ``` 4. Remove all stateful channels: ``` @@ -42,7 +45,7 @@ We're assuming that you just installed NixOS by going through the [official inst ``` 5. Rebuild: ``` - sudo ./rebuild switch + sudo HOSTNAME=$host ./rebuild switch ``` 6. Log out and back in again. diff --git a/nixos/configuration.nix b/nixos/hamac-configuration.nix index 7d785ab..306260d 100644 --- a/nixos/configuration.nix +++ b/nixos/hamac-configuration.nix @@ -1,10 +1,11 @@ +# channel="nixos" # See the configuration.nix(5) man page and the NixOS manual (accessible by running `nixos-help`). { config, pkgs, ... }: { imports = [ - ./hardware-configuration.nix + ./hamac-hardware-configuration.nix ./sanix.nix ]; @@ -12,7 +13,7 @@ boot.loader.systemd-boot.enable = true; boot.loader.efi.canTouchEfiVariables = true; - networking.hostName = "nixos"; # Define your hostname. + networking.hostName = "hamac"; networking.networkmanager.enable = true; diff --git a/nixos/hardware-configuration.nix b/nixos/hamac-hardware-configuration.nix index 54b9d60..54b9d60 100644 --- a/nixos/hardware-configuration.nix +++ b/nixos/hamac-hardware-configuration.nix diff --git a/nixos/nixpkgs/path.nix b/nixos/nixpkgs/path.nix deleted file mode 100644 index 7ae177e..0000000 --- a/nixos/nixpkgs/path.nix +++ /dev/null @@ -1,2 +0,0 @@ -# The Nixpkgs path to use -(import ../npins).nixos.outPath diff --git a/nixos/rebuild b/nixos/rebuild index 98101c1..3cb086e 100755 --- a/nixos/rebuild +++ b/nixos/rebuild @@ -1,10 +1,30 @@ #!/usr/bin/env bash set -euo pipefail -# nix-instantiate --eval has no raw mode yet -nixpkgsPath=$(nix-instantiate --eval --read-write-mode nixpkgs/path.nix | tr -d \") -# Get the ./configuration.nix relative to this script -configPath=$(realpath -- "$(dirname -- "${BASH_SOURCE[0]}")/configuration.nix") +# Enable all future paths in this script to be relative to the directory containing the script. +cd "$(dirname -- "${BASH_SOURCE[0]}")" + +configPath=$(realpath -- "$HOSTNAME-configuration.nix") + +if [ ! -f $configPath ]; then + echo "aborting: $configPath doesn't exist" + exit 1 +fi + +firstLine=$(head -n1 "$configPath") + +if ! echo "$firstLine" | grep -E ^"# channel *=" > /dev/null; then + echo "aborting: $configPath doesn't start with \`# channel=\"...\"\`, where ... is a pin from sources.json" + exit 1 +fi + +nix-eval() { + nix-instantiate --eval --read-write-mode "$@" \ + | tr -d \" # nix-instantiate has no raw output yet (like the experimental nix eval) +} + +channel=$(nix-eval --argstr line "$(echo $firstLine | tr -d \#)" --expr '{line}: (builtins.fromTOML line).channel') +nixpkgsPath=$(nix-eval --argstr channel "$channel" --expr '{channel}: (import ./npins).${channel}.outPath') # nixos-rebuild always reads Nixpkgs from the NIX_PATH, # so we need to set it explicitly to our pinned version |