From 4877675b063917a5bdb5cbf67f51bca93acadd96 Mon Sep 17 00:00:00 2001 From: Erik Reinert <4638629+erikreinert@users.noreply.github.com> Date: Mon, 27 Nov 2023 22:05:23 -0800 Subject: [PATCH 1/5] feat(template): implements template for all existing flakes --- README.md | 12 ++-- flake.lock | 65 +------------------ flake.nix | 47 ++++---------- template/darwin/flake.nix | 23 +++++++ template/darwin/module/configuration.nix | 17 +++++ .../darwin/module}/home-manager.nix | 0 {system => template/darwin/system}/darwin.nix | 0 template/go/flake.lock | 63 ++++++++++++++++++ template/nixos/flake.nix | 22 +++++++ .../nixos/module}/configuration.nix | 0 template/nixos/module/home-manager.nix | 7 ++ .../nixos/system/hardware-configuration.nix | 0 {system => template/nixos/system}/nixos.nix | 2 +- 13 files changed, 155 insertions(+), 103 deletions(-) create mode 100644 template/darwin/flake.nix create mode 100644 template/darwin/module/configuration.nix rename {module => template/darwin/module}/home-manager.nix (100%) rename {system => template/darwin/system}/darwin.nix (100%) create mode 100644 template/go/flake.lock create mode 100644 template/nixos/flake.nix rename {module => template/nixos/module}/configuration.nix (100%) create mode 100644 template/nixos/module/home-manager.nix rename system/nixos-hardware-configuration.nix => template/nixos/system/hardware-configuration.nix (100%) rename {system => template/nixos/system}/nixos.nix (92%) diff --git a/README.md b/README.md index 721f3fc..b5c1cbf 100644 --- a/README.md +++ b/README.md @@ -53,13 +53,17 @@ nix.settings.experimental-features = [ "nix-command" "flakes" ]; Would you like to manage with nix-channel? [y/n] y ``` -6. Fork this repository to create your own flake kickstart. +6. Create a new directory for your `flake.nix` configuration: -> **Note** -> This can be done in the Github UI at: https://github.com/ALT-F4-LLC/kickstart.nix +```bash +mkdir -p ~/Desktop/kickstart.nix +cd ~/Desktop/kickstart.nix +``` + +7. Using `nix flake init` generate the `kickstart.nix` template locally: ```bash -gh repo fork ALT-F4-LLC/kickstart.nix +nix flake init --template github:ALT-F4-LLC/kickstart.nix ``` 7. Clone your new fork locally to customize: diff --git a/flake.lock b/flake.lock index 966bacb..5999137 100644 --- a/flake.lock +++ b/flake.lock @@ -1,69 +1,6 @@ { "nodes": { - "darwin": { - "inputs": { - "nixpkgs": [ - "nixpkgs" - ] - }, - "locked": { - "lastModified": 1691275315, - "narHash": "sha256-9WN0IA0vNZSNxKHpy/bYvPnCw4VH/nr5iBv7c+7KUts=", - "owner": "lnl7", - "repo": "nix-darwin", - "rev": "829041cf10c4f6751a53c0a11ca2fd22ff0918d6", - "type": "github" - }, - "original": { - "owner": "lnl7", - "repo": "nix-darwin", - "type": "github" - } - }, - "home-manager": { - "inputs": { - "nixpkgs": [ - "nixpkgs" - ] - }, - "locked": { - "lastModified": 1687871164, - "narHash": "sha256-bBFlPthuYX322xOlpJvkjUBz0C+MOBjZdDOOJJ+G2jU=", - "owner": "nix-community", - "repo": "home-manager", - "rev": "07c347bb50994691d7b0095f45ebd8838cf6bc38", - "type": "github" - }, - "original": { - "owner": "nix-community", - "ref": "release-23.05", - "repo": "home-manager", - "type": "github" - } - }, - "nixpkgs": { - "locked": { - "lastModified": 1691252436, - "narHash": "sha256-SKKPKYOnFcwqECehxoFBMLv29CZXC5qCDuETSuXd82g=", - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "9607b9149c9d81fdf3dc4f3bcc278da146ffbd77", - "type": "github" - }, - "original": { - "owner": "NixOS", - "ref": "nixos-23.05", - "repo": "nixpkgs", - "type": "github" - } - }, - "root": { - "inputs": { - "darwin": "darwin", - "home-manager": "home-manager", - "nixpkgs": "nixpkgs" - } - } + "root": {} }, "root": "root", "version": 7 diff --git a/flake.nix b/flake.nix index 2ee4da7..2425b42 100644 --- a/flake.nix +++ b/flake.nix @@ -1,43 +1,22 @@ { - description = "Example kickstart Nix development setup."; + description = "Minimal templates to get started with Nix."; - inputs = { - darwin.inputs.nixpkgs.follows = "nixpkgs"; - darwin.url = "github:lnl7/nix-darwin"; - home-manager.inputs.nixpkgs.follows = "nixpkgs"; - home-manager.url = "github:nix-community/home-manager/release-23.05"; - nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.05"; - }; - - outputs = inputs@{ self, darwin, home-manager, nixpkgs, ... }: - let - ### START OPTIONS ### - username = ""; # should match your host username - ### END OPTIONS ### - - ### START SYSTEMS ### - darwin-system = import ./system/darwin.nix { inherit inputs username; }; - nixos-system = import ./system/nixos.nix { inherit inputs username; }; - ### END SYSTEMS ### - in - { - darwinConfigurations = { - darwin-aarch64 = darwin-system "aarch64-darwin"; - darwin-x86_64 = darwin-system "x86_64-darwin"; + outputs = inputs: { + templates = { + darwin = { + description = "A minimal Darwin development environment flake."; + path = ./template/darwin; }; - nixosConfigurations = { - nixos-aarch64 = nixos-system "aarch64-linux"; - nixos-x86_64 = nixos-system "x86_64-linux"; + go = { + description = "A minimal Go language flake."; + path = ./template/go; }; - templates = { - go = { - path = ./template/go; - description = '' - A minimal Go flake using flake-parts. - ''; - }; + nixos = { + description = "A minimal NixOS development environment flake."; + path = ./template/nixos; }; }; + }; } diff --git a/template/darwin/flake.nix b/template/darwin/flake.nix new file mode 100644 index 0000000..7ac076a --- /dev/null +++ b/template/darwin/flake.nix @@ -0,0 +1,23 @@ +{ + description = "Example kickstart Nix development setup."; + + inputs = { + darwin.inputs.nixpkgs.follows = "nixpkgs"; + darwin.url = "github:lnl7/nix-darwin"; + home-manager.inputs.nixpkgs.follows = "nixpkgs"; + home-manager.url = "github:nix-community/home-manager/release-23.05"; + nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.05"; + }; + + outputs = inputs@{ self, darwin, home-manager, nixpkgs, ... }: + let + username = throw ""; # TODO: replace with user name and remove throw + darwin-system = import ./system/darwin.nix { inherit inputs username; }; + in + { + darwinConfigurations = { + darwin-aarch64 = darwin-system "aarch64-darwin"; + darwin-x86_64 = darwin-system "x86_64-darwin"; + }; + }; +} diff --git a/template/darwin/module/configuration.nix b/template/darwin/module/configuration.nix new file mode 100644 index 0000000..9c05d8b --- /dev/null +++ b/template/darwin/module/configuration.nix @@ -0,0 +1,17 @@ +{ + # add more system settings here + nix = { + settings = { + auto-optimise-store = true; + builders-use-substitutes = true; + experimental-features = [ "flakes" "nix-command" ]; + substituters = [ "https://nix-community.cachix.org" ]; + trusted-public-keys = [ + "nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs=" + ]; + trusted-users = [ "@wheel" ]; + warn-dirty = false; + }; + }; + programs.zsh.enable = true; +} diff --git a/module/home-manager.nix b/template/darwin/module/home-manager.nix similarity index 100% rename from module/home-manager.nix rename to template/darwin/module/home-manager.nix diff --git a/system/darwin.nix b/template/darwin/system/darwin.nix similarity index 100% rename from system/darwin.nix rename to template/darwin/system/darwin.nix diff --git a/template/go/flake.lock b/template/go/flake.lock new file mode 100644 index 0000000..29b0d80 --- /dev/null +++ b/template/go/flake.lock @@ -0,0 +1,63 @@ +{ + "nodes": { + "flake-parts": { + "inputs": { + "nixpkgs-lib": "nixpkgs-lib" + }, + "locked": { + "lastModified": 1698882062, + "narHash": "sha256-HkhafUayIqxXyHH1X8d9RDl1M2CkFgZLjKD3MzabiEo=", + "owner": "hercules-ci", + "repo": "flake-parts", + "rev": "8c9fa2545007b49a5db5f650ae91f227672c3877", + "type": "github" + }, + "original": { + "id": "flake-parts", + "type": "indirect" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1700612854, + "narHash": "sha256-yrQ8osMD+vDLGFX7pcwsY/Qr5PUd6OmDMYJZzZi0+zc=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "19cbff58383a4ae384dea4d1d0c823d72b49d614", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs-lib": { + "locked": { + "dir": "lib", + "lastModified": 1698611440, + "narHash": "sha256-jPjHjrerhYDy3q9+s5EAsuhyhuknNfowY6yt6pjn9pc=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "0cbe9f69c234a7700596e943bfae7ef27a31b735", + "type": "github" + }, + "original": { + "dir": "lib", + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-parts": "flake-parts", + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/template/nixos/flake.nix b/template/nixos/flake.nix new file mode 100644 index 0000000..4e2d288 --- /dev/null +++ b/template/nixos/flake.nix @@ -0,0 +1,22 @@ +{ + description = "Example kickstart Nix development setup."; + + inputs = { + home-manager.inputs.nixpkgs.follows = "nixpkgs"; + home-manager.url = "github:nix-community/home-manager/release-23.05"; + nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.05"; + }; + + outputs = inputs@{ self, home-manager, nixpkgs, ... }: + let + username = ""; # should match your host username + + nixos-system = import ./system/nixos.nix { inherit inputs username; }; + in + { + nixosConfigurations = { + nixos-aarch64 = nixos-system "aarch64-linux"; + nixos-x86_64 = nixos-system "x86_64-linux"; + }; + }; +} diff --git a/module/configuration.nix b/template/nixos/module/configuration.nix similarity index 100% rename from module/configuration.nix rename to template/nixos/module/configuration.nix diff --git a/template/nixos/module/home-manager.nix b/template/nixos/module/home-manager.nix new file mode 100644 index 0000000..5a20c9f --- /dev/null +++ b/template/nixos/module/home-manager.nix @@ -0,0 +1,7 @@ +{ pkgs, ... }: + +{ + # add home-manager user settings here + home.packages = with pkgs; [ git neovim ]; + home.stateVersion = "23.05"; +} diff --git a/system/nixos-hardware-configuration.nix b/template/nixos/system/hardware-configuration.nix similarity index 100% rename from system/nixos-hardware-configuration.nix rename to template/nixos/system/hardware-configuration.nix diff --git a/system/nixos.nix b/template/nixos/system/nixos.nix similarity index 92% rename from system/nixos.nix rename to template/nixos/system/nixos.nix index 188aa4e..b3fd9ca 100644 --- a/system/nixos.nix +++ b/template/nixos/system/nixos.nix @@ -3,7 +3,7 @@ system: let - hardware-configuration = import ./nixos-hardware-configuration.nix; + hardware-configuration = import ./hardware-configuration.nix; configuration = import ../module/configuration.nix; in inputs.nixpkgs.lib.nixosSystem { From 9f86736394b88c85fb7af285015ce3f402429aed Mon Sep 17 00:00:00 2001 From: Erik Reinert <4638629+erikreinert@users.noreply.github.com> Date: Tue, 28 Nov 2023 10:14:38 -0800 Subject: [PATCH 2/5] feat(README) --- README.md | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index b5c1cbf..e279af2 100644 --- a/README.md +++ b/README.md @@ -63,16 +63,7 @@ cd ~/Desktop/kickstart.nix 7. Using `nix flake init` generate the `kickstart.nix` template locally: ```bash -nix flake init --template github:ALT-F4-LLC/kickstart.nix -``` - -7. Clone your new fork locally to customize: - -> **Note** -> If the following command does not work revist steps 1 & 2. - -```bash -nix run nixpkgs#git clone https://github.com//kickstart.nix +nix flake init --template github:ALT-F4-LLC/kickstart.nix#darwin ``` 8. Update the following value(s) in `flake.nix` configuration: @@ -86,10 +77,18 @@ in 9. Switch to `kickstart.nix` environment for your system with flake configuration: ```bash -darwin-rebuild switch --flake ".#darwin-aarch64" # for M1/M2 Chipsets -darwin-rebuild switch --flake ".#darwin-x86_64" # for Intel Chipsets +darwin-rebuild switch --flake ".#aarch64" # M Series Chipsets +darwin-rebuild switch --flake ".#x86_64" # Intel Chipsets ``` +Congrats! You've setup Nix with Home Manager on macOS! + +Be sure to explore the files below to get started customizing: + +- `system/darwin.nix` for all `nix-darwin` related settings +- `module/configuration.nix` for `Nix` related settings +- `module/home-manager.nix` for `Home Manager` related settings + ### NixOS 1. Add the following to `/etc/nixos/configuration.nix` to enable `nix-command` and `flakes` features: From a3eb1672c18c0c19e5a8d4f513e0983f81d28e35 Mon Sep 17 00:00:00 2001 From: Erik Reinert <4638629+erikreinert@users.noreply.github.com> Date: Wed, 29 Nov 2023 18:22:36 -0800 Subject: [PATCH 3/5] feat(template): improvements for nixos --- README.md | 64 ++++++++++++++++++--------------- template/darwin/flake.nix | 4 +-- template/nixos/flake.nix | 9 ++--- template/nixos/system/nixos.nix | 4 +-- 4 files changed, 44 insertions(+), 37 deletions(-) diff --git a/README.md b/README.md index e279af2..4188469 100644 --- a/README.md +++ b/README.md @@ -5,8 +5,8 @@ Kickstart your Nix environment. ## Table of Contents - [Prerequisites](#prerequisites) -- [Initial Setup](#initial-setup) -- [Personalizing Your Environment](#personalizing-your-environment) +- [Setup macOS](#setup-macos) +- [Setup NixOS](#setup-nixos) ## Prerequisites @@ -16,11 +16,7 @@ Kickstart your Nix environment. - [GitHub CLI](https://github.com/cli/cli) (`gh`) installed for some commands. -## Initial Setup - -Choose the appropriate setup instructions based on your operating system. - -### macOS +## Setup macOS 1. Install `nixpkgs` with official script: @@ -56,8 +52,8 @@ Would you like to manage with nix-channel? [y/n] y 6. Create a new directory for your `flake.nix` configuration: ```bash -mkdir -p ~/Desktop/kickstart.nix -cd ~/Desktop/kickstart.nix +mkdir -p ~/kickstart.nix +cd ~/kickstart.nix ``` 7. Using `nix flake init` generate the `kickstart.nix` template locally: @@ -70,7 +66,8 @@ nix flake init --template github:ALT-F4-LLC/kickstart.nix#darwin ```nix let - username = ""; # replace + password = throw ""; # TODO: replace with password and remove throw + username = throw ""; # TODO: replace with user name and remove throw in ``` @@ -89,53 +86,62 @@ Be sure to explore the files below to get started customizing: - `module/configuration.nix` for `Nix` related settings - `module/home-manager.nix` for `Home Manager` related settings -### NixOS +### Setup NixOS + +1. Install NixOS using the [latest ISO image](https://nixos.org/download#nixos-iso). -1. Add the following to `/etc/nixos/configuration.nix` to enable `nix-command` and `flakes` features: +2. Add the following to `/etc/nixos/configuration.nix` to enable `nix-command` and `flakes` features: ```nix -nix.settings.experimental-features = [ "nix-command" "flakes" ]; +nix.extraOptions = "experimental-features = nix-command flakes"; ``` -2. Update you system to reflect the changes: +3. Update you system to reflect the changes: ```bash nixos-rebuild switch ``` -3. Fork this repository to create your own flake kickstart. - -> **Note** -> This can be done in the Github UI at: https://github.com/ALT-F4-LLC/kickstart.nix +4. Create a new directory for your `flake.nix` configuration: ```bash -gh repo fork ALT-F4-LLC/kickstart.nix +mkdir -p ~/kickstart.nix +cd ~/kickstart.nix ``` -4. Clone your new fork locally to customize: - -> **Note** -> If the following command does not work revist steps 1 & 2. +5. Using `nix flake init` generate the `kickstart.nix` template locally: ```bash -nix run nixpkgs#git clone https://github.com//kickstart.nix +nix flake init --template github:ALT-F4-LLC/kickstart.nix#nixos ``` -5. Update the following value(s) in `flake.nix` configuration: +6. Update the following value(s) in `flake.nix` configuration: + +> **Important** +> The default user password can be found in `flake.nix`. ```nix let - username = ""; # replace + password = throw ""; # TODO: replace with password and remove throw + username = throw ""; # TODO: replace with user name and remove throw in ``` -6. Switch to `kickstart.nix` environment for your system with flake configuration: +7. Switch to `kickstart.nix` environment for your system with flake configuration: ```bash -nixos-rebuild switch --flake ".#nixos-aarch64" # for ARM Chipsets -nixos-rebuild switch --flake ".#nixos-x86_64" # for Intel Chipsets +nixos-rebuild switch --flake ".#aarch64" # M Series Chipsets +nixos-rebuild switch --flake ".#x86_64" # Intel Chipsets ``` +Congrats! You've setup NixOS with Home Manager! + +Be sure to explore the files below to get started customizing: + +- `system/hardware-configuration.nix` for `NixOS` hardware related settings +- `system/nixos.nix` for `NixOS` system related settings +- `module/configuration.nix` for more `NixOS` system related settings +- `module/home-manager.nix` for `Home Manager` related settings ## Personalizing Your Environment diff --git a/template/darwin/flake.nix b/template/darwin/flake.nix index 7ac076a..6d91f9b 100644 --- a/template/darwin/flake.nix +++ b/template/darwin/flake.nix @@ -16,8 +16,8 @@ in { darwinConfigurations = { - darwin-aarch64 = darwin-system "aarch64-darwin"; - darwin-x86_64 = darwin-system "x86_64-darwin"; + aarch64 = darwin-system "aarch64-darwin"; + x86_64 = darwin-system "x86_64-darwin"; }; }; } diff --git a/template/nixos/flake.nix b/template/nixos/flake.nix index 4e2d288..69ce262 100644 --- a/template/nixos/flake.nix +++ b/template/nixos/flake.nix @@ -9,14 +9,15 @@ outputs = inputs@{ self, home-manager, nixpkgs, ... }: let - username = ""; # should match your host username + password = throw ""; # TODO: replace with password and remove throw + username = throw ""; # TODO: replace with user name and remove throw - nixos-system = import ./system/nixos.nix { inherit inputs username; }; + nixos-system = import ./system/nixos.nix { inherit inputs password username; }; in { nixosConfigurations = { - nixos-aarch64 = nixos-system "aarch64-linux"; - nixos-x86_64 = nixos-system "x86_64-linux"; + aarch64 = nixos-system "aarch64-linux"; + x86_64 = nixos-system "x86_64-linux"; }; }; } diff --git a/template/nixos/system/nixos.nix b/template/nixos/system/nixos.nix index b3fd9ca..a448ad1 100644 --- a/template/nixos/system/nixos.nix +++ b/template/nixos/system/nixos.nix @@ -1,4 +1,4 @@ -{ inputs, username }: +{ inputs, username, password }: system: @@ -23,7 +23,7 @@ inputs.nixpkgs.lib.nixosSystem { extraGroups = [ "wheel" ]; home = "/home/${username}"; isNormalUser = true; - password = "password"; + password = password; }; system.stateVersion = "23.05"; } From f2d5edce666ed7d0741b06e013345cd695420287 Mon Sep 17 00:00:00 2001 From: Erik Reinert <4638629+erikreinert@users.noreply.github.com> Date: Wed, 29 Nov 2023 18:34:02 -0800 Subject: [PATCH 4/5] feat(README) --- README.md | 25 +------------------------ 1 file changed, 1 insertion(+), 24 deletions(-) diff --git a/README.md b/README.md index 4188469..595e9aa 100644 --- a/README.md +++ b/README.md @@ -86,7 +86,7 @@ Be sure to explore the files below to get started customizing: - `module/configuration.nix` for `Nix` related settings - `module/home-manager.nix` for `Home Manager` related settings -### Setup NixOS +## Setup NixOS 1. Install NixOS using the [latest ISO image](https://nixos.org/download#nixos-iso). @@ -142,26 +142,3 @@ Be sure to explore the files below to get started customizing: - `system/nixos.nix` for `NixOS` system related settings - `module/configuration.nix` for more `NixOS` system related settings - `module/home-manager.nix` for `Home Manager` related settings - -## Personalizing Your Environment - -You can further tailor your Nix environment through configurations. - -### Darwin - -- `nix-darwin` system options exist in `./system/darwin.nix` -- `home-manager` system options exist in `./system/darwin.nix` - -### NixOS - -> **Important** -> The default user password can be found and updated in `./system/nixos.nix`. - -- `nixos` system hardware options exist in `./system/nixos-hardware-configuration.nix` -- `nixos` system options exist in `./system/nixos.nix` -- `home-manager` system options exist in `./module/home-manager.nix` - -### Shared - -- `nix` system options exist in `./module/configuration.nix` -- `home-manager` user options exist in `./module/home-manager.nix` From 2a66829eb610d3b99b76ca36903d4dfd4f03ebe1 Mon Sep 17 00:00:00 2001 From: Erik Reinert <4638629+erikreinert@users.noreply.github.com> Date: Wed, 29 Nov 2023 18:36:39 -0800 Subject: [PATCH 5/5] chore(README) --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 595e9aa..45ab746 100644 --- a/README.md +++ b/README.md @@ -88,7 +88,7 @@ Be sure to explore the files below to get started customizing: ## Setup NixOS -1. Install NixOS using the [latest ISO image](https://nixos.org/download#nixos-iso). +1. Install NixOS using the [latest ISO image](https://nixos.org/download#nixos-iso) for your system. 2. Add the following to `/etc/nixos/configuration.nix` to enable `nix-command` and `flakes` features: