From a06bdecdad4354d8e7f60e026572d42f1102c8aa Mon Sep 17 00:00:00 2001 From: Gabriel Fontes Date: Fri, 5 Aug 2022 22:34:46 -0300 Subject: [PATCH] new version, with both templates on the same branch --- .gitignore | 2 - README.md | 16 ++- flake.nix | 97 +++---------------- minimal/README.md | 66 +++++++++++++ flake.lock => minimal/flake.lock | 0 minimal/flake.nix | 39 ++++++++ .../home-manager}/home.nix | 0 {nixos => minimal/nixos}/configuration.nix | 0 .../nixos}/hardware-configuration.nix | 0 standard/flake.lock | 80 +++++++++++++++ standard/flake.nix | 86 ++++++++++++++++ standard/home-manager/home.nix | 34 +++++++ .../modules}/home-manager/default.nix | 0 .../modules}/nixos/default.nix | 0 standard/nixos/configuration.nix | 80 +++++++++++++++ standard/nixos/hardware-configuration.nix | 10 ++ {overlay => standard/overlay}/default.nix | 0 {pkgs => standard/pkgs}/default.nix | 0 shell.nix => standard/shell.nix | 0 19 files changed, 418 insertions(+), 92 deletions(-) delete mode 100644 .gitignore create mode 100644 minimal/README.md rename flake.lock => minimal/flake.lock (100%) create mode 100644 minimal/flake.nix rename {home-manager => minimal/home-manager}/home.nix (100%) rename {nixos => minimal/nixos}/configuration.nix (100%) rename {nixos => minimal/nixos}/hardware-configuration.nix (100%) create mode 100644 standard/flake.lock create mode 100644 standard/flake.nix create mode 100644 standard/home-manager/home.nix rename {modules => standard/modules}/home-manager/default.nix (100%) rename {modules => standard/modules}/nixos/default.nix (100%) create mode 100644 standard/nixos/configuration.nix create mode 100644 standard/nixos/hardware-configuration.nix rename {overlay => standard/overlay}/default.nix (100%) rename {pkgs => standard/pkgs}/default.nix (100%) rename shell.nix => standard/shell.nix (100%) diff --git a/.gitignore b/.gitignore deleted file mode 100644 index 87a3018..0000000 --- a/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -result -*.qcow2 diff --git a/README.md b/README.md index 5a69c32..8d5d1c5 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,6 @@ -# Nix Starter Config (Full version) +# Nix Starter Config -This is a simple nix flake for getting started with NixOS + home-manager. - -**[Looking for the minimal version?](https://github.com/Misterio77/nix-starter-config/tree/minimal)** +This repo contains a few a simple nix flakes for getting started with NixOS + home-manager. # What this provides @@ -12,7 +10,7 @@ This is a simple nix flake for getting started with NixOS + home-manager. `home-manager --flake .` - Basic boilerplate for adding custom packages (under `pkgs`) and overlays (under `overlay`). Accessible on your system, home config, as well as `nix - build .#package-name` + build .#package-name`. - Boilerplate for custom NixOS (`modules/nixos`) and home-manager (`modules/home-manager`) modules @@ -38,10 +36,10 @@ and come back here to get your feet wet, it's the best way to learn! ## The repo - [Install git](https://nixos.wiki/wiki/git) -- [Hit "Use this - template"](https://github.com/Misterio77/nix-starter-config/generate) on this - repo (or clone this down and push to any another git remote) - +- Create a repository for your config, for example: `cd ~/Documents && git init nix-config` +- Choose your template: + - [Minimal version](./minimal): `nix flake init -t github:misterio77/nix-starter-config#minimal` + - [Standard version](./standard): `nix flake init -t github:misterio77/nix-starter-config#standard` - Add stuff you currently have on `/etc/nixos/` to `nixos` (usually `configuration.nix` and `hardware-configuration.nix`, when you're starting out). diff --git a/flake.nix b/flake.nix index 3b297bc..591094b 100644 --- a/flake.nix +++ b/flake.nix @@ -1,86 +1,21 @@ { - description = "You new nix config"; - - inputs = { - # Nixpkgs - nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; - hardware.url = "github:nixos/nixos-hardware"; - - # Home manager - home-manager.url = "github:nix-community/home-manager"; - home-manager.inputs.nixpkgs.follows = "nixpkgs"; - - # TODO: Add any other flake you might need - }; - - outputs = { nixpkgs, home-manager, ... }@inputs: - let - forAllSystems = nixpkgs.lib.genAttrs systems; - systems = [ - "aarch64-linux" - "i686-linux" - "x86_64-linux" - "aarch64-darwin" - "x86_64-darwin" - ]; - in - rec { - # Your custom packages and modifications - overlays = { - default = import ./overlay { inherit inputs; }; + description = "NixOS + standalone home-manager config flakes to get you started!"; + outputs = inputs: { + templates = { + minimal = { + description = '' + Minimal flake - contains only the configs. + Contains the bare minimum to migrate your existing legacy configs to flakes. + ''; + path = ./minimal; }; - - # Reusable nixos modules you might want to export - # These are usually stuff you would upstream into nixpkgs - nixosModules = import ./modules/nixos; - # Reusable home-manager modules you might want to export - # These are usually stuff you would upstream into home-manager - homeManagerModules = import ./modules/home-manager; - - # Devshell for bootstrapping - # Acessible through 'nix develop' or 'nix-shell' (legacy) - devShells = forAllSystems (system: { - default = legacyPackages.${system}.callPackage ./shell.nix { }; - }); - - # Reexport nixpkgs with our overlays applied - # Acessible on our configurations, and through nix build, shell, run, etc. - legacyPackages = forAllSystems (system: - import inputs.nixpkgs { - inherit system; - overlays = builtins.attrValues overlays; - } - ); - - nixosConfigurations = { - # FIXME replace with your hostname - your-hostname = nixpkgs.lib.nixosSystem { - pkgs = legacyPackages.x86_64-linux; - - modules = [ - # > Our main nixos configuration file < - ./nixos/configuration.nix - ] ++ (builtins.attrValues nixosModules); # Import our reusable nixos modules - - # Pass inputs down to our config, so that they can consume flake inputs - specialArgs = { inherit inputs; }; - }; - }; - - homeConfigurations = { - # FIXME replace with your username@hostname - "your-name@your-hostname" = home-manager.lib.homeManagerConfiguration { - pkgs = legacyPackages.x86_64-linux; - - modules = [ - # > Our main home-manager configuration file < - ./home-manager/home.nix - # Import our reusable home-manager modules - ] ++ (builtins.attrValues homeManagerModules); # Import our reusable home-manager modules - - # Pass inputs down to our config, so that they can consume flake inputs - extraSpecialArgs = { inherit inputs; }; - }; + standard = { + description = '' + Standard flake - augmented with boilerplate for custom packages, overlays, and reusable modules. + Perfect migration path for when you want to dive a little deeper. + ''; + path = ./standard; }; }; + }; } diff --git a/minimal/README.md b/minimal/README.md new file mode 100644 index 0000000..bf23e5d --- /dev/null +++ b/minimal/README.md @@ -0,0 +1,66 @@ +# Nix Starter Config (Minimal version) + +This is a simple nix flake for getting started with NixOS + home-manager. + +[**Looking for the full version?**](https://github.com/Misterio77/nix-starter-config/tree/main) + +# What this provides + +- NixOS configuration on `nixos/configuration.nix`, accessible via + `nixos-rebuild --flake .` +- Home-manager configuration on `home-manager/home.nix`, accessible via + `home-manager --flake .` + +# Getting started + +Assuming you have a basic NixOS booted up (either live or installed, anything +works). [Here's a link to the latest NixOS downloads, just for +you](https://nixos.org/download#download-nixos). + +## The repo + +- [Install git](https://nixos.wiki/wiki/git) +- [Hit "Use this + template"](https://github.com/Misterio77/nix-starter-config/generate) on this + repo (or clone this down and push to any another git remote) + +- Add stuff you currently have on `/etc/nixos/` to `nixos` (usually + `configuration.nix` and `hardware-configuration.nix`, when you're starting + out). + - The included file has some options you might want, specially if you don't + have a configuration ready. Make sure you have generated your own + `hardware-configuration.nix`; if not, just mount your partitions to + `/mnt` and run: `nixos-generate-config --root /mnt`. +- If you're already using home-manager, add your stuff from `~/.config/nixpkgs` + to `home-manager` (probably `home.nix`). + - I also include one with some simple options if you need. Feel free to + ignore this step if you don't want to use home-manager just yet. +- Take a look at `flake.nix`, making sure to fill out anything marked with + FIXME (required) or TODO (usually tips or optional stuff you might want) +- Push your changes! Or at least copy them somewhere if you're on a live + medium. + +## Bootstrapping + +To get everything up and running, you need flake-enabled nix and/or home-manager. + +For simplicity, this minimal version does not include a bootstrap shell. + +Check the [NixOS wiki](https://nixos.wiki/wiki/Flakes) for information on how to enable flakes. + +## Usage + +- Run `sudo nixos-rebuild switch --flake .#hostname` to apply your system + configuration. + - If you're still on a live installation medium, run `nixos-install --flake + .#hostname` instead, and reboot. +- Run `home-manager switch --flake .#username@hostname` to apply your home + configuration. + +# What next? + +## Full version + +Once you're confortable with this flake, take a look at the [full +version](https://github.com/Misterio77/nix-starter-config/tree/main), it includes +boilerplate for overlays, custom packages, and more. diff --git a/flake.lock b/minimal/flake.lock similarity index 100% rename from flake.lock rename to minimal/flake.lock diff --git a/minimal/flake.nix b/minimal/flake.nix new file mode 100644 index 0000000..5ab09ea --- /dev/null +++ b/minimal/flake.nix @@ -0,0 +1,39 @@ +{ + description = "You new nix config"; + + inputs = { + # Nixpkgs + nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; + hardware.url = "github:nixos/nixos-hardware"; + + # Home manager + home-manager.url = "github:nix-community/home-manager"; + home-manager.inputs.nixpkgs.follows = "nixpkgs"; + + # TODO: Add any other flake you might need + }; + + outputs = { nixpkgs, home-manager, ... }@inputs: { + nixosConfigurations = { + # FIXME replace with your hostname + your-hostname = nixpkgs.lib.nixosSystem { + pkgs = nixpkgs.legacyPackages.x86_64-linux; + + modules = [ ./nixos/configuration.nix ]; + # Pass inputs down to our config, so that they can consume flake inputs + specialArgs = { inherit inputs; }; + }; + }; + + homeConfigurations = { + # FIXME replace with your username@hostname + "your-name@your-hostname" = home-manager.lib.homeManagerConfiguration { + pkgs = nixpkgs.legacyPackages.x86_64-linux; + + modules = [ ./home-manager/home.nix ]; + # Pass inputs down to our config, so that they can consume flake inputs + extraSpecialArgs = { inherit inputs; }; + }; + }; + }; +} diff --git a/home-manager/home.nix b/minimal/home-manager/home.nix similarity index 100% rename from home-manager/home.nix rename to minimal/home-manager/home.nix diff --git a/nixos/configuration.nix b/minimal/nixos/configuration.nix similarity index 100% rename from nixos/configuration.nix rename to minimal/nixos/configuration.nix diff --git a/nixos/hardware-configuration.nix b/minimal/nixos/hardware-configuration.nix similarity index 100% rename from nixos/hardware-configuration.nix rename to minimal/nixos/hardware-configuration.nix diff --git a/standard/flake.lock b/standard/flake.lock new file mode 100644 index 0000000..1856103 --- /dev/null +++ b/standard/flake.lock @@ -0,0 +1,80 @@ +{ + "nodes": { + "hardware": { + "locked": { + "lastModified": 1659356074, + "narHash": "sha256-UwV6hZZEtchvtiTCCD/ODEv1226eam8kEgEyQb7xB0E=", + "owner": "nixos", + "repo": "nixos-hardware", + "rev": "ea3efc80f8ab83cb73aec39f4e76fe87afb15a08", + "type": "github" + }, + "original": { + "owner": "nixos", + "repo": "nixos-hardware", + "type": "github" + } + }, + "home-manager": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ], + "utils": "utils" + }, + "locked": { + "lastModified": 1659484873, + "narHash": "sha256-6VoPiGyDdjBHOJ3IpS24lY1lrDiOHeuEefOFI0qz3WE=", + "owner": "nix-community", + "repo": "home-manager", + "rev": "d8d9ff0b2df77defa10375c6665b51f0251c34d6", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "home-manager", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1659522808, + "narHash": "sha256-HBcM19nGhI3IWwPNVlYb0MZ8VW6iKp4JbAVkeIHVykc=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "168d1c578909dc143ba52dbed661c36e76b12b36", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "hardware": "hardware", + "home-manager": "home-manager", + "nixpkgs": "nixpkgs" + } + }, + "utils": { + "locked": { + "lastModified": 1653893745, + "narHash": "sha256-0jntwV3Z8//YwuOjzhV2sgJJPt+HY6KhU7VZUL0fKZQ=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "1ed9fb1935d260de5fe1c2f7ee0ebaae17ed2fa1", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/standard/flake.nix b/standard/flake.nix new file mode 100644 index 0000000..3b297bc --- /dev/null +++ b/standard/flake.nix @@ -0,0 +1,86 @@ +{ + description = "You new nix config"; + + inputs = { + # Nixpkgs + nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; + hardware.url = "github:nixos/nixos-hardware"; + + # Home manager + home-manager.url = "github:nix-community/home-manager"; + home-manager.inputs.nixpkgs.follows = "nixpkgs"; + + # TODO: Add any other flake you might need + }; + + outputs = { nixpkgs, home-manager, ... }@inputs: + let + forAllSystems = nixpkgs.lib.genAttrs systems; + systems = [ + "aarch64-linux" + "i686-linux" + "x86_64-linux" + "aarch64-darwin" + "x86_64-darwin" + ]; + in + rec { + # Your custom packages and modifications + overlays = { + default = import ./overlay { inherit inputs; }; + }; + + # Reusable nixos modules you might want to export + # These are usually stuff you would upstream into nixpkgs + nixosModules = import ./modules/nixos; + # Reusable home-manager modules you might want to export + # These are usually stuff you would upstream into home-manager + homeManagerModules = import ./modules/home-manager; + + # Devshell for bootstrapping + # Acessible through 'nix develop' or 'nix-shell' (legacy) + devShells = forAllSystems (system: { + default = legacyPackages.${system}.callPackage ./shell.nix { }; + }); + + # Reexport nixpkgs with our overlays applied + # Acessible on our configurations, and through nix build, shell, run, etc. + legacyPackages = forAllSystems (system: + import inputs.nixpkgs { + inherit system; + overlays = builtins.attrValues overlays; + } + ); + + nixosConfigurations = { + # FIXME replace with your hostname + your-hostname = nixpkgs.lib.nixosSystem { + pkgs = legacyPackages.x86_64-linux; + + modules = [ + # > Our main nixos configuration file < + ./nixos/configuration.nix + ] ++ (builtins.attrValues nixosModules); # Import our reusable nixos modules + + # Pass inputs down to our config, so that they can consume flake inputs + specialArgs = { inherit inputs; }; + }; + }; + + homeConfigurations = { + # FIXME replace with your username@hostname + "your-name@your-hostname" = home-manager.lib.homeManagerConfiguration { + pkgs = legacyPackages.x86_64-linux; + + modules = [ + # > Our main home-manager configuration file < + ./home-manager/home.nix + # Import our reusable home-manager modules + ] ++ (builtins.attrValues homeManagerModules); # Import our reusable home-manager modules + + # Pass inputs down to our config, so that they can consume flake inputs + extraSpecialArgs = { inherit inputs; }; + }; + }; + }; +} diff --git a/standard/home-manager/home.nix b/standard/home-manager/home.nix new file mode 100644 index 0000000..a7af0ad --- /dev/null +++ b/standard/home-manager/home.nix @@ -0,0 +1,34 @@ +# This is your home-manager configuration file +# Use this to configure your home environment (it replaces ~/.config/nixpkgs/home.nix) + +{ inputs, lib, config, pkgs, ... }: { + imports = [ + # If you want to use home-manager modules from other flakes (such as nix-colors), use something like: + # inputs.nix-colors.homeManagerModule + + # Feel free to split up your configuration and import pieces of it here. + ]; + + # Comment out if you wish to disable unfree packages for your system + nixpkgs.config.allowUnfree = true; + + # TODO: Set your username + home = { + username = "your-name"; + homeDirectory = "/home/your-name"; + }; + + # Add stuff for your user as you see fit: + # programs.neovim.enable = true; + # home.packages = with pkgs; [ steam ]; + + # Enable home-manager and git + programs.home-manager.enable = true; + programs.git.enable = true; + + # Nicely reload system units when changing configs + systemd.user.startServices = "sd-switch"; + + # https://nixos.wiki/wiki/FAQ/When_do_I_update_stateVersion + home.stateVersion = "22.05"; +} diff --git a/modules/home-manager/default.nix b/standard/modules/home-manager/default.nix similarity index 100% rename from modules/home-manager/default.nix rename to standard/modules/home-manager/default.nix diff --git a/modules/nixos/default.nix b/standard/modules/nixos/default.nix similarity index 100% rename from modules/nixos/default.nix rename to standard/modules/nixos/default.nix diff --git a/standard/nixos/configuration.nix b/standard/nixos/configuration.nix new file mode 100644 index 0000000..bfc6edb --- /dev/null +++ b/standard/nixos/configuration.nix @@ -0,0 +1,80 @@ +# This is your system's configuration file. +# Use this to configure your system environment (it replaces /etc/nixos/configuration.nix) + +{ inputs, lib, config, pkgs, ... }: { + + imports = [ + # If you want to use modules from other flakes (such as nixos-hardware), use something like: + # inputs.hardware.nixosModules.common-cpu-amd + # inputs.hardware.nixosModules.common-ssd + + # It's strongly recommended you take a look at + # https://github.com/nixos/nixos-hardware + # and import modules relevant to your hardware. + + # Import your generated (nixos-generate-config) hardware configuration + ./hardware-configuration.nix + + # You can also split up your configuration and import pieces of it here. + ]; + + # This will add your inputs as registries, making operations with them (such + # as nix shell nixpkgs#name) consistent with your flake inputs. + nix.registry = lib.mapAttrs' (n: v: lib.nameValuePair n { flake = v; }) inputs; + + # Will activate home-manager profiles for each user upon login + # This is useful when using ephemeral installations + environment.loginShellInit = '' + [ -d "$HOME/.nix-profile" ] || /nix/var/nix/profiles/per-user/$USER/home-manager/activate &> /dev/null + ''; + + nix = { + settings = { + # Enable flakes and new 'nix' command + experimental-features = "nix-command flakes"; + # Deduplicate and optimize nix store + auto-optimise-store = true; + }; + }; + + # Remove if you wish to disable unfree packages for your system + nixpkgs.config.allowUnfree = true; + + # FIXME: Add the rest of your current configuration + + # TODO: Set your hostname + networking.hostName = "your-hostname"; + + # TODO: This is just an example, be sure to use whatever bootloader you prefer + boot.loader.systemd-boot.enable = true; + + # TODO: Configure your system-wide user settings (groups, etc), add more users as needed. + users.users = { + # FIXME: Replace with your username + your-name = { + # TODO: You can set an initial password for your user. + # If you do, you can skip setting a root password by passing '--no-root-passwd' to nixos-install. + # Be sure to change it (using passwd) after rebooting! + # initialPassword = "correcthorsebatterystaple"; + isNormalUser = true; + openssh.authorizedKeys.keys = [ + # TODO: Add your SSH public key(s) here, if you plan on using SSH to connect + ]; + # TODO: Be sure to add any other groups you need (such as networkmanager, audio, docker, etc) + extraGroups = [ "wheel" ]; + }; + }; + + # This setups a SSH server. Very important if you're setting up a headless system. + # Feel free to remove if you don't need it. + services.openssh = { + enable = true; + # Forbid root login through SSH. + permitRootLogin = "no"; + # Use keys only. Remove if you want to SSH using password (not recommended) + passwordAuthentication = false; + }; + + # https://nixos.wiki/wiki/FAQ/When_do_I_update_stateVersion + system.stateVersion = "22.05"; +} diff --git a/standard/nixos/hardware-configuration.nix b/standard/nixos/hardware-configuration.nix new file mode 100644 index 0000000..dd00939 --- /dev/null +++ b/standard/nixos/hardware-configuration.nix @@ -0,0 +1,10 @@ +# This is just an example, you should generate yours with nixos-generate-config and put it in here. +{ + fileSystems."/" = { + device = "/dev/sda1"; + fsType = "ext4"; + }; + + # Set your system kind (needed for flakes) + nixpkgs.hostPlatform = "x86_64-linux"; +} diff --git a/overlay/default.nix b/standard/overlay/default.nix similarity index 100% rename from overlay/default.nix rename to standard/overlay/default.nix diff --git a/pkgs/default.nix b/standard/pkgs/default.nix similarity index 100% rename from pkgs/default.nix rename to standard/pkgs/default.nix diff --git a/shell.nix b/standard/shell.nix similarity index 100% rename from shell.nix rename to standard/shell.nix