commit 3d8c771d32aff97eb9905000bcdd25300a14526a Author: Anish Lakhwara Date: Sat Sep 24 12:08:07 2022 +1000 template file diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..1856103 --- /dev/null +++ b/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/flake.nix b/flake.nix new file mode 100644 index 0000000..6d015f3 --- /dev/null +++ b/flake.nix @@ -0,0 +1,90 @@ +{ + 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 + + # Shameless plug: looking for a way to nixify your themes and make + # everything match nicely? Try nix-colors! + # nix-colors.url = "github:misterio77/nix-colors"; + }; + + outputs = { nixpkgs, home-manager, ... }@inputs: + let + forAllSystems = nixpkgs.lib.genAttrs [ + "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 { }; + }); + + # This instantiates nixpkgs for each system listed above + # Allowing you to add overlays and configure it (e.g. allowUnfree) + # Our configurations will use these instances + # Your flake will also let you access your package set through nix build, shell, run, etc. + legacyPackages = forAllSystems (system: + import inputs.nixpkgs { + inherit system; + # This adds our overlays to pkgs + overlays = builtins.attrValues overlays; + # NOTE: Using `nixpkgs.config` in your NixOS config won't work + # Instead, you should set nixpkgs configs here + # (https://nixos.org/manual/nixpkgs/stable/#idm140737322551056) + + # config.allowUnfree = true; + } + ); + + nixosConfigurations = { + # FIXME replace with your hostname + your-hostname = nixpkgs.lib.nixosSystem { + pkgs = legacyPackages.x86_64-linux; + specialArgs = { inherit inputs; }; # Pass flake inputs to our config + modules = (builtins.attrValues nixosModules) ++ [ + # > Our main nixos configuration file < + ./nixos/configuration.nix + ]; + }; + }; + + homeConfigurations = { + # FIXME replace with your username@hostname + "your-username@your-hostname" = + home-manager.lib.homeManagerConfiguration { + pkgs = legacyPackages.x86_64-linux; + extraSpecialArgs = { inherit inputs; }; # Pass flake inputs to our config + modules = (builtins.attrValues homeManagerModules) ++ [ + # > Our main home-manager configuration file < + ./home-manager/home.nix + ]; + }; + }; + }; +} diff --git a/home-manager/home.nix b/home-manager/home.nix new file mode 100644 index 0000000..1891b22 --- /dev/null +++ b/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-username"; + homeDirectory = "/home/your-username"; + }; + + # 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/modules/home-manager/default.nix new file mode 100644 index 0000000..e41f7d9 --- /dev/null +++ b/modules/home-manager/default.nix @@ -0,0 +1,7 @@ +# Add your reusable home-manager modules to this directory, on their own file (https://nixos.wiki/wiki/Module). +# These should be stuff you would like to share with others, not your personal configurations. + +{ + # List your module files here + # my-module = import ./my-module.nix; +} diff --git a/modules/nixos/default.nix b/modules/nixos/default.nix new file mode 100644 index 0000000..bec6184 --- /dev/null +++ b/modules/nixos/default.nix @@ -0,0 +1,7 @@ +# Add your reusable NixOS modules to this directory, on their own file (https://nixos.wiki/wiki/Module). +# These should be stuff you would like to share with others, not your personal configurations. + +{ + # List your module files here + # my-module = import ./my-module.nix; +} diff --git a/nixos/configuration.nix b/nixos/configuration.nix new file mode 100644 index 0000000..52a6006 --- /dev/null +++ b/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. + ]; + + nix = { + # This will add each flake input as a registry + # To make nix3 commands consistent with your flake + registry = lib.mapAttrs (_: value: { flake = value; }) inputs; + + # This will additionally add your inputs to the system's legacy channels + # Making legacy nix commands consistent as well, awesome! + nixPath = lib.mapAttrsToList (key: value: "${key}=${value.to.path}") config.nix.registry; + }; + + 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-username = { + # 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/nixos/hardware-configuration.nix b/nixos/hardware-configuration.nix new file mode 100644 index 0000000..dd00939 --- /dev/null +++ b/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/overlay/default.nix new file mode 100644 index 0000000..98339c4 --- /dev/null +++ b/overlay/default.nix @@ -0,0 +1,16 @@ +# This file defines two overlays and composes them +{ inputs, ... }: +let + # This one brings our custom packages from the 'pkgs' directory + additions = final: _prev: import ../pkgs { pkgs = final; }; + + # This one contains whatever you want to overlay + # You can change versions, add patches, set compilation flags, anything really. + # https://nixos.wiki/wiki/Overlays + modifications = final: prev: { + # example = prev.example.overrideAttrs (oldAttrs: rec { + # ... + # }); + }; +in +inputs.nixpkgs.lib.composeManyExtensions [ additions modifications ] diff --git a/pkgs/default.nix b/pkgs/default.nix new file mode 100644 index 0000000..55e428d --- /dev/null +++ b/pkgs/default.nix @@ -0,0 +1,5 @@ +# When you add custom packages, list them here +# These are similar to nixpkgs packages +{ pkgs }: { + # example = pkgs.callPackage ./example { }; +} diff --git a/shell.nix b/shell.nix new file mode 100644 index 0000000..9662b11 --- /dev/null +++ b/shell.nix @@ -0,0 +1,18 @@ +# Shell for bootstrapping flake-enabled nix and home-manager +{ pkgs ? let + # If pkgs is not defined, instanciate nixpkgs from locked commit + lock = (builtins.fromJSON (builtins.readFile ./flake.lock)).nodes.nixpkgs.locked; + nixpkgs = fetchTarball { + url = "https://github.com/nixos/nixpkgs/archive/${lock.rev}.tar.gz"; + sha256 = lock.narHash; + }; + system = builtins.currentSystem; + overlays = [ ]; # Explicit blank overlay to avoid interference + in + import nixpkgs { inherit system overlays; } +, ... +}: pkgs.mkShell { + # Enable experimental features without having to specify the argument + NIX_CONFIG = "experimental-features = nix-command flakes"; + nativeBuildInputs = with pkgs; [ nix home-manager git ]; +}