├── LICENSE ├── README.md ├── flake.lock ├── flake.nix ├── home-manager └── home.nix ├── modules ├── home-manager │ └── default.nix └── nixos │ └── default.nix ├── nixos ├── configuration.nix ├── hardware-configuration.nix └── modules │ ├── default.nix │ ├── pkgs.nix │ ├── ssh.nix │ ├── system.nix │ └── users.nix ├── nixpkgs.nix ├── overlays └── default.nix ├── pkgs └── default.nix └── shell.nix /LICENSE: -------------------------------------------------------------------------------- 1 | Creative Commons Legal Code 2 | 3 | CC0 1.0 Universal 4 | 5 | CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE 6 | LEGAL SERVICES. DISTRIBUTION OF THIS DOCUMENT DOES NOT CREATE AN 7 | ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS 8 | INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES 9 | REGARDING THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS 10 | PROVIDED HEREUNDER, AND DISCLAIMS LIABILITY FOR DAMAGES RESULTING FROM 11 | THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED 12 | HEREUNDER. 13 | 14 | Statement of Purpose 15 | 16 | The laws of most jurisdictions throughout the world automatically confer 17 | exclusive Copyright and Related Rights (defined below) upon the creator 18 | and subsequent owner(s) (each and all, an "owner") of an original work of 19 | authorship and/or a database (each, a "Work"). 20 | 21 | Certain owners wish to permanently relinquish those rights to a Work for 22 | the purpose of contributing to a commons of creative, cultural and 23 | scientific works ("Commons") that the public can reliably and without fear 24 | of later claims of infringement build upon, modify, incorporate in other 25 | works, reuse and redistribute as freely as possible in any form whatsoever 26 | and for any purposes, including without limitation commercial purposes. 27 | These owners may contribute to the Commons to promote the ideal of a free 28 | culture and the further production of creative, cultural and scientific 29 | works, or to gain reputation or greater distribution for their Work in 30 | part through the use and efforts of others. 31 | 32 | For these and/or other purposes and motivations, and without any 33 | expectation of additional consideration or compensation, the person 34 | associating CC0 with a Work (the "Affirmer"), to the extent that he or she 35 | is an owner of Copyright and Related Rights in the Work, voluntarily 36 | elects to apply CC0 to the Work and publicly distribute the Work under its 37 | terms, with knowledge of his or her Copyright and Related Rights in the 38 | Work and the meaning and intended legal effect of CC0 on those rights. 39 | 40 | 1. Copyright and Related Rights. A Work made available under CC0 may be 41 | protected by copyright and related or neighboring rights ("Copyright and 42 | Related Rights"). Copyright and Related Rights include, but are not 43 | limited to, the following: 44 | 45 | i. the right to reproduce, adapt, distribute, perform, display, 46 | communicate, and translate a Work; 47 | ii. moral rights retained by the original author(s) and/or performer(s); 48 | iii. publicity and privacy rights pertaining to a person's image or 49 | likeness depicted in a Work; 50 | iv. rights protecting against unfair competition in regards to a Work, 51 | subject to the limitations in paragraph 4(a), below; 52 | v. rights protecting the extraction, dissemination, use and reuse of data 53 | in a Work; 54 | vi. database rights (such as those arising under Directive 96/9/EC of the 55 | European Parliament and of the Council of 11 March 1996 on the legal 56 | protection of databases, and under any national implementation 57 | thereof, including any amended or successor version of such 58 | directive); and 59 | vii. other similar, equivalent or corresponding rights throughout the 60 | world based on applicable law or treaty, and any national 61 | implementations thereof. 62 | 63 | 2. Waiver. To the greatest extent permitted by, but not in contravention 64 | of, applicable law, Affirmer hereby overtly, fully, permanently, 65 | irrevocably and unconditionally waives, abandons, and surrenders all of 66 | Affirmer's Copyright and Related Rights and associated claims and causes 67 | of action, whether now known or unknown (including existing as well as 68 | future claims and causes of action), in the Work (i) in all territories 69 | worldwide, (ii) for the maximum duration provided by applicable law or 70 | treaty (including future time extensions), (iii) in any current or future 71 | medium and for any number of copies, and (iv) for any purpose whatsoever, 72 | including without limitation commercial, advertising or promotional 73 | purposes (the "Waiver"). Affirmer makes the Waiver for the benefit of each 74 | member of the public at large and to the detriment of Affirmer's heirs and 75 | successors, fully intending that such Waiver shall not be subject to 76 | revocation, rescission, cancellation, termination, or any other legal or 77 | equitable action to disrupt the quiet enjoyment of the Work by the public 78 | as contemplated by Affirmer's express Statement of Purpose. 79 | 80 | 3. Public License Fallback. Should any part of the Waiver for any reason 81 | be judged legally invalid or ineffective under applicable law, then the 82 | Waiver shall be preserved to the maximum extent permitted taking into 83 | account Affirmer's express Statement of Purpose. In addition, to the 84 | extent the Waiver is so judged Affirmer hereby grants to each affected 85 | person a royalty-free, non transferable, non sublicensable, non exclusive, 86 | irrevocable and unconditional license to exercise Affirmer's Copyright and 87 | Related Rights in the Work (i) in all territories worldwide, (ii) for the 88 | maximum duration provided by applicable law or treaty (including future 89 | time extensions), (iii) in any current or future medium and for any number 90 | of copies, and (iv) for any purpose whatsoever, including without 91 | limitation commercial, advertising or promotional purposes (the 92 | "License"). The License shall be deemed effective as of the date CC0 was 93 | applied by Affirmer to the Work. Should any part of the License for any 94 | reason be judged legally invalid or ineffective under applicable law, such 95 | partial invalidity or ineffectiveness shall not invalidate the remainder 96 | of the License, and in such case Affirmer hereby affirms that he or she 97 | will not (i) exercise any of his or her remaining Copyright and Related 98 | Rights in the Work or (ii) assert any associated claims and causes of 99 | action with respect to the Work, in either case contrary to Affirmer's 100 | express Statement of Purpose. 101 | 102 | 4. Limitations and Disclaimers. 103 | 104 | a. No trademark or patent rights held by Affirmer are waived, abandoned, 105 | surrendered, licensed or otherwise affected by this document. 106 | b. Affirmer offers the Work as-is and makes no representations or 107 | warranties of any kind concerning the Work, express, implied, 108 | statutory or otherwise, including without limitation warranties of 109 | title, merchantability, fitness for a particular purpose, non 110 | infringement, or the absence of latent or other defects, accuracy, or 111 | the present or absence of errors, whether or not discoverable, all to 112 | the greatest extent permissible under applicable law. 113 | c. Affirmer disclaims responsibility for clearing rights of other persons 114 | that may apply to the Work or any use thereof, including without 115 | limitation any person's Copyright and Related Rights in the Work. 116 | Further, Affirmer disclaims responsibility for obtaining any necessary 117 | consents, permissions or other rights required for any use of the 118 | Work. 119 | d. Affirmer understands and acknowledges that Creative Commons is not a 120 | party to this document and has no duty or obligation with respect to 121 | this CC0 or use of the Work. 122 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Nix Starter Config 2 | 3 | This repo contains a few a simple nix flake templates for getting started with 4 | NixOS + home-manager. 5 | 6 | # What this provides 7 | 8 | - [Minimal version](./minimal): 9 | - NixOS configuration on `nixos/configuration.nix`, accessible via 10 | `nixos-rebuild --flake .` 11 | - Home-manager configuration on `home-manager/home.nix`, accessible via 12 | `home-manager --flake .` 13 | - [Standard version](./standard): 14 | - Basic boilerplate for adding custom packages (under `pkgs`) and overlays 15 | (under `overlay`). Accessible on your system, home config, as well as `nix 16 | build .#package-name`. 17 | - Boilerplate for custom NixOS (`modules/nixos`) and home-manager 18 | (`modules/home-manager`) modules 19 | - NixOS and home-manager configurations from minimal, and they should 20 | also use your overlays and custom packages right out of the box. 21 | 22 | # Getting started 23 | 24 | Assuming you have a basic NixOS booted up (either live or installed, anything 25 | works). [Here's a link to the latest NixOS downloads, just for 26 | you](https://nixos.org/download#download-nixos). 27 | 28 | Alternatively, you can totally use `nix` and `home-manager` on your existing 29 | distro (or even on Darwin). [Install nix](https://nixos.org/download.html#nix) 30 | and follow along (just ignore the `nixos-*` commands). 31 | 32 | ## What template to chose? 33 | 34 | If this is your first trying flakes, or you're attempting to migrate your 35 | (simple) config to it; you should use the minimal version. 36 | 37 | If you're here looking for inspiration/tips/good practices (and you already use 38 | flakes), or you're migrating a config that already has overlays and custom 39 | packages; try the standard version. 40 | 41 | ## I like your funny words, magic man 42 | 43 | Not sure what this all means? 44 | 45 | Take a look at [the learn hub on the NixOS 46 | website](https://nixos.org/learn.html) (scroll down to guides, the manuals, and 47 | the other awesome learning resources). 48 | 49 | Learning the basics of what Nix (the package manager) is, how the Nix language 50 | works, and a bit of NixOS basics should get you up and running. Don't worry if 51 | it seems a little confusing at first. Get confortable with the basic concepts 52 | and come back here to get your feet wet, it's the best way to learn! 53 | 54 | ## The repo 55 | 56 | - [Install git](https://nixos.wiki/wiki/git), if you haven't already. 57 | - Create a repository for your config, for example: 58 | ```bash 59 | cd ~/Documents 60 | git init nix-config 61 | cd nix-config 62 | ``` 63 | - Make sure you're running Nix 2.4+, and opt into the experimental `flakes` and `nix-command` features: 64 | ```bash 65 | # Should be 2.4+ 66 | nix --version 67 | export NIX_CONFIG="experimental-features = nix-command flakes" 68 | ``` 69 | - Get the template: 70 | ```bash 71 | # For minimal version 72 | nix flake init -t github:misterio77/nix-starter-config#minimal 73 | 74 | # For standard version 75 | nix flake init -t github:misterio77/nix-starter-config#standard 76 | ``` 77 | - If you want to use NixOS: add stuff you currently have on `/etc/nixos/` to 78 | `nixos` (usually `configuration.nix` and `hardware-configuration.nix`, when 79 | you're starting out). 80 | - The included file has some options you might want, specially if you don't 81 | have a configuration ready. Make sure you have generated your own 82 | `hardware-configuration.nix`; if not, just mount your partitions to 83 | `/mnt` and run: `nixos-generate-config --root /mnt`. 84 | - If you want to use home-manager: add your stuff from `~/.config/nixpkgs` 85 | to `home-manager` (probably `home.nix`). 86 | - The included file is also a good starting point if you don't have a config 87 | yet. 88 | - Take a look at `flake.nix`, making sure to fill out anything marked with 89 | FIXME (required) or TODO (usually tips or optional stuff you might want) 90 | - `git add` and `git push` your changes! Or at least copy them somewhere if 91 | you're on a live medium. 92 | 93 | ## Usage 94 | 95 | - Run `sudo nixos-rebuild switch --flake .#hostname` to apply your system 96 | configuration. 97 | - If you're still on a live installation medium, run `nixos-install --flake 98 | .#hostname` instead, and reboot. 99 | - Run `home-manager switch --flake .#username@hostname` to apply your home 100 | configuration. 101 | - If you don't have home-manager installed, try `nix shell nixpkgs#home-manager`. 102 | 103 | And that's it, really! You're ready to have fun with your configurations using 104 | the latest and greatest nix3 flake-enabled command UX. 105 | 106 | # What next? 107 | 108 | ## Use home-manager as a NixOS module 109 | 110 | If you prefer to build your home configuration together with your NixOS one, 111 | it's pretty simple. 112 | 113 | Simply remove the `homeConfigurations` block from the `flake.nix` file; then 114 | add this to your NixOS configuration (either directly on 115 | `nixos/configuration.nix` or on a separate file and import it): 116 | 117 | ```nix 118 | { inputs, ... }: { 119 | imports = [ 120 | # Import home-manager's NixOS module 121 | inputs.home-manager.nixosModules.home-manager 122 | ]; 123 | 124 | home-manager = { 125 | extraSpecialArgs = { inherit inputs; }; 126 | users = { 127 | # Import your home-manager configuration 128 | your-username = import ../home-manager; 129 | }; 130 | }; 131 | } 132 | ``` 133 | 134 | ## Adding more hosts or users 135 | 136 | You can organize them by hostname and username on `nixos` and `home-manager` 137 | directories, be sure to also add them to `flake.nix`. 138 | 139 | You can take a look at my (beware, here be reproductible dragons) 140 | [configuration repo](https://github.com/misterio77/nix-config) for ideas. 141 | 142 | NixOS makes it easy to share common configuration between hosts (you might want 143 | to create a common directory for these), while keeping everything in sync. 144 | home-manager can help you sync your environment (from editor to WM and 145 | everything in between) anywhere you use it. Have fun! 146 | 147 | ## User password and secrets 148 | 149 | You have basically two ways of setting up default passwords: 150 | - By default, you'll be prompted for a root password when installing with 151 | `nixos-install`. After you reboot, be sure to add a password to your own 152 | account and lock root using `sudo passwd -l root`. 153 | - Alternatively, you can specify `initialPassword` for your user. This will 154 | give your account a default password, be sure to change it after rebooting! 155 | If you do, you should pass `--no-root-passwd` to `nixos-install`, to skip 156 | setting a password on the root account. 157 | 158 | If you don't want to set your password imperatively, you can also use 159 | `passwordFile` for safely and declaratively setting a password from a file 160 | outside the nix store. 161 | 162 | There's also [more advanced options for secret 163 | management](https://nixos.wiki/wiki/Comparison_of_secret_managing_schemes), 164 | including some that can include them (encrypted) into your config repo and/or 165 | nix store, be sure to check them out if you're interested. 166 | 167 | ## Dotfile management with home-manager 168 | 169 | Besides just adding packages to your environment, home-manager can also manage 170 | your dotfiles. I strongly recommend you do, it's awesome! 171 | 172 | For full nix goodness, check out the home-manager options with `man 173 | home-configuration.nix`. Using them, you'll be able to fully configure any 174 | program with nix syntax and its powerful abstractions. 175 | 176 | Alternatively, if you're still not ready to rewrite all your configs to nix 177 | syntax, there's home-manager options (such as `xdg.configFile`) for including 178 | files from your config repository into your usual dot directories. Add your 179 | existing dotfiles to this repo and try it out! 180 | 181 | ## Try opt-in persistance 182 | 183 | You might have noticed that there's impurity in your NixOS system, in the form 184 | of configuration files and other cruft your system generates when running. What 185 | if you change them in a whim to get something working and forget about it? 186 | Boom, your system is not fully reproductible anymore. 187 | 188 | You can instead fully delete your `/` and `/home` on every boot! Nix is okay 189 | with a empty root on boot (all you need is `/boot` and `/nix`), and will 190 | happily reapply your configurations. 191 | 192 | There's two main approaches to this: mount a `tmpfs` (RAM disk) to `/`, or 193 | (using a filesystem such as btrfs or zfs) mount a blank snapshot and reset it 194 | on boot. 195 | 196 | For stuff that can't be managed through nix (such as games downloaded from 197 | steam, or logs), use [impermanence](https://github.com/nix-community/impermanence) 198 | for mounting stuff you to keep to a separate partition/volume (such as 199 | `/nix/persist` or `/persist`). This makes everything vanish by default, and you 200 | can keep track of what you specifically asked to be kept. 201 | 202 | Here's some awesome blog posts about it: 203 | - [Erase your darlings](https://grahamc.com/blog/erase-your-darlings) 204 | - [Encrypted BTRFS with Opt-In State on 205 | NixOS](https://mt-caret.github.io/blog/posts/2020-06-29-optin-state.html) 206 | - [NixOS: tmpfs as root](https://elis.nu/blog/2020/05/nixos-tmpfs-as-root/) and 207 | [tmpfs as home](https://elis.nu/blog/2020/06/nixos-tmpfs-as-home/) 208 | 209 | ## Adding custom packages 210 | 211 | Something you want to use that's not in nixpkgs yet? You can easily build and 212 | iterate on a derivation (package) from this very repository. 213 | 214 | Create a folder with the desired name inside `pkgs`, and add a `default.nix` 215 | file containing a derivation. Be sure to also `callPackage` them on 216 | `pkgs/default.nix`. 217 | 218 | You'll be able to refer to that package from anywhere on your 219 | home-manager/nixos configurations, build them with `nix build .#package-name`, 220 | or bring them into your shell with `nix shell .#package-name`. 221 | 222 | See [the manual](https://nixos.org/manual/nixpkgs/stable/) for some tips on how 223 | to package stuff. 224 | 225 | ## Adding overlays 226 | 227 | Found some outdated package on nixpkgs you need the latest version of? Perhaps 228 | you want to apply a patch to fix a behaviour you don't like? Nix makes it easy 229 | and manageble with overlays! 230 | 231 | Use the `overlays/default.nix` file for this. 232 | 233 | If you're creating patches, you can keep them on the `overlays` folder as well. 234 | 235 | See [the wiki article](https://nixos.wiki/wiki/Overlays) to see how it all 236 | works. 237 | 238 | ## Adding your own modules 239 | 240 | Got some configurations you want to create an abstraction of? Modules are the 241 | answer. These awesome files can expose _options_ and implement _configurations_ 242 | based on how the options are set. 243 | 244 | Create a file for them on either `modules/nixos` or `modules/home-manager`. Be 245 | sure to also add them to the listing at `modules/nixos/default.nix` or 246 | `modules/home-manager/default.nix`. 247 | 248 | See [the wiki article](https://nixos.wiki/wiki/Module) to learn more about 249 | them. 250 | 251 | # Troubleshooting / FAQ 252 | 253 | Please [let me know](https://github.com/Misterio77/nix-starter-config/issues) 254 | any questions or issues you face with these templates, so I can add more info 255 | here! 256 | 257 | ## Nix says my repo files don't exist, even though they do! 258 | 259 | Nix flakes only see files that git is currently tracked, so just `git add .` 260 | and you should be good to go. Files on `.gitignore`, of course, are invisible 261 | to nix - this is to guarantee your build won't depend on anything that is not 262 | on your repo. 263 | 264 | 268 | -------------------------------------------------------------------------------- /flake.lock: -------------------------------------------------------------------------------- 1 | { 2 | "nodes": { 3 | "home-manager": { 4 | "inputs": { 5 | "nixpkgs": [ 6 | "nixpkgs" 7 | ], 8 | "utils": "utils" 9 | }, 10 | "locked": { 11 | "lastModified": 1681092193, 12 | "narHash": "sha256-JerCqqOqbT2tBnXQW4EqwFl0hHnuZp21rIQ6lu/N4rI=", 13 | "owner": "nix-community", 14 | "repo": "home-manager", 15 | "rev": "f9edbedaf015013eb35f8caacbe0c9666bbc16af", 16 | "type": "github" 17 | }, 18 | "original": { 19 | "owner": "nix-community", 20 | "ref": "release-22.11", 21 | "repo": "home-manager", 22 | "type": "github" 23 | } 24 | }, 25 | "nixpkgs": { 26 | "locked": { 27 | "lastModified": 1684398685, 28 | "narHash": "sha256-TRE62m91iZ5ArVMgA+uj22Yda8JoQuuhc9uwZ+NoX+0=", 29 | "owner": "nixos", 30 | "repo": "nixpkgs", 31 | "rev": "628d4bb6e9f4f0c30cfd9b23d3c1cdcec9d3cb5c", 32 | "type": "github" 33 | }, 34 | "original": { 35 | "owner": "nixos", 36 | "ref": "nixos-22.11", 37 | "repo": "nixpkgs", 38 | "type": "github" 39 | } 40 | }, 41 | "nixpkgs-unstable": { 42 | "locked": { 43 | "lastModified": 1684570954, 44 | "narHash": "sha256-FX5y4Sm87RWwfu9PI71XFvuRpZLowh00FQpIJ1WfXqE=", 45 | "owner": "nixos", 46 | "repo": "nixpkgs", 47 | "rev": "3005f20ce0aaa58169cdee57c8aa12e5f1b6e1b3", 48 | "type": "github" 49 | }, 50 | "original": { 51 | "owner": "nixos", 52 | "ref": "nixos-unstable", 53 | "repo": "nixpkgs", 54 | "type": "github" 55 | } 56 | }, 57 | "root": { 58 | "inputs": { 59 | "home-manager": "home-manager", 60 | "nixpkgs": "nixpkgs", 61 | "nixpkgs-unstable": "nixpkgs-unstable" 62 | } 63 | }, 64 | "utils": { 65 | "locked": { 66 | "lastModified": 1667395993, 67 | "narHash": "sha256-nuEHfE/LcWyuSWnS8t12N1wc105Qtau+/OdUAjtQ0rA=", 68 | "owner": "numtide", 69 | "repo": "flake-utils", 70 | "rev": "5aed5285a952e0b949eb3ba02c12fa4fcfef535f", 71 | "type": "github" 72 | }, 73 | "original": { 74 | "owner": "numtide", 75 | "repo": "flake-utils", 76 | "type": "github" 77 | } 78 | } 79 | }, 80 | "root": "root", 81 | "version": 7 82 | } 83 | -------------------------------------------------------------------------------- /flake.nix: -------------------------------------------------------------------------------- 1 | { 2 | description = "Your new nix config"; 3 | 4 | inputs = { 5 | # Nixpkgs 6 | nixpkgs.url = "github:nixos/nixpkgs/nixos-22.11"; 7 | # You can access packages and modules from different nixpkgs revs 8 | # at the same time. Here's an working example: 9 | nixpkgs-unstable.url = "github:nixos/nixpkgs/nixos-unstable"; 10 | # Also see the 'unstable-packages' overlay at 'overlays/default.nix'. 11 | 12 | # Home manager 13 | home-manager.url = "github:nix-community/home-manager/release-22.11"; 14 | home-manager.inputs.nixpkgs.follows = "nixpkgs"; 15 | 16 | # TODO: Add any other flake you might need 17 | # hardware.url = "github:nixos/nixos-hardware"; 18 | 19 | # Shameless plug: looking for a way to nixify your themes and make 20 | # everything match nicely? Try nix-colors! 21 | # nix-colors.url = "github:misterio77/nix-colors"; 22 | }; 23 | 24 | outputs = { self, nixpkgs, home-manager, ... }@inputs: 25 | let 26 | inherit (self) outputs; 27 | forAllSystems = nixpkgs.lib.genAttrs [ 28 | "aarch64-linux" 29 | "i686-linux" 30 | "x86_64-linux" 31 | "aarch64-darwin" 32 | "x86_64-darwin" 33 | ]; 34 | in 35 | rec { 36 | # Your custom packages 37 | # Acessible through 'nix build', 'nix shell', etc 38 | packages = forAllSystems (system: 39 | let pkgs = nixpkgs.legacyPackages.${system}; 40 | in import ./pkgs { inherit pkgs; } 41 | ); 42 | # Devshell for bootstrapping 43 | # Acessible through 'nix develop' or 'nix-shell' (legacy) 44 | devShells = forAllSystems (system: 45 | let pkgs = nixpkgs.legacyPackages.${system}; 46 | in import ./shell.nix { inherit pkgs; } 47 | ); 48 | 49 | # Your custom packages and modifications, exported as overlays 50 | overlays = import ./overlays { inherit inputs; }; 51 | # Reusable nixos modules you might want to export 52 | # These are usually stuff you would upstream into nixpkgs 53 | nixosModules = import ./modules/nixos; 54 | # Reusable home-manager modules you might want to export 55 | # These are usually stuff you would upstream into home-manager 56 | homeManagerModules = import ./modules/home-manager; 57 | 58 | # NixOS configuration entrypoint 59 | # Available through 'nixos-rebuild --flake .#your-hostname' 60 | nixosConfigurations = { 61 | # FIXME replace with your hostname 62 | your-hostname = nixpkgs.lib.nixosSystem { 63 | specialArgs = { inherit inputs outputs; }; 64 | modules = [ 65 | # > Our main nixos configuration file < 66 | ./nixos/configuration.nix 67 | ]; 68 | }; 69 | }; 70 | 71 | # Standalone home-manager configuration entrypoint 72 | # Available through 'home-manager --flake .#your-username@your-hostname' 73 | homeConfigurations = { 74 | # FIXME replace with your username@hostname 75 | "your-username@your-hostname" = home-manager.lib.homeManagerConfiguration { 76 | pkgs = nixpkgs.legacyPackages.x86_64-linux; # Home-manager requires 'pkgs' instance 77 | extraSpecialArgs = { inherit inputs outputs; }; 78 | modules = [ 79 | # > Our main home-manager configuration file < 80 | ./home-manager/home.nix 81 | ]; 82 | }; 83 | }; 84 | }; 85 | } 86 | -------------------------------------------------------------------------------- /home-manager/home.nix: -------------------------------------------------------------------------------- 1 | # This is your home-manager configuration file 2 | # Use this to configure your home environment (it replaces ~/.config/nixpkgs/home.nix) 3 | 4 | { inputs, outputs, lib, config, pkgs, ... }: { 5 | # You can import other home-manager modules here 6 | imports = [ 7 | # If you want to use modules your own flake exports (from modules/home-manager): 8 | # outputs.homeManagerModules.example 9 | 10 | # Or modules exported from other flakes (such as nix-colors): 11 | # inputs.nix-colors.homeManagerModules.default 12 | 13 | # You can also split up your configuration and import pieces of it here: 14 | # ./nvim.nix 15 | ]; 16 | 17 | nixpkgs = { 18 | # You can add overlays here 19 | overlays = [ 20 | # Add overlays your own flake exports (from overlays and pkgs dir): 21 | outputs.overlays.additions 22 | outputs.overlays.modifications 23 | outputs.overlays.unstable-packages 24 | 25 | # You can also add overlays exported from other flakes: 26 | # neovim-nightly-overlay.overlays.default 27 | 28 | # Or define it inline, for example: 29 | # (final: prev: { 30 | # hi = final.hello.overrideAttrs (oldAttrs: { 31 | # patches = [ ./change-hello-to-hi.patch ]; 32 | # }); 33 | # }) 34 | ]; 35 | # Configure your nixpkgs instance 36 | config = { 37 | # Disable if you don't want unfree packages 38 | allowUnfree = true; 39 | # Workaround for https://github.com/nix-community/home-manager/issues/2942 40 | allowUnfreePredicate = (_: true); 41 | }; 42 | }; 43 | 44 | # TODO: Set your username 45 | home = { 46 | username = "your-username"; 47 | homeDirectory = "/home/your-username"; 48 | }; 49 | 50 | # Add stuff for your user as you see fit: 51 | # programs.neovim.enable = true; 52 | # home.packages = with pkgs; [ steam ]; 53 | 54 | # Enable home-manager and git 55 | programs.home-manager.enable = true; 56 | programs.git.enable = true; 57 | 58 | # Nicely reload system units when changing configs 59 | systemd.user.startServices = "sd-switch"; 60 | 61 | # https://nixos.wiki/wiki/FAQ/When_do_I_update_stateVersion 62 | home.stateVersion = "22.11"; 63 | } 64 | -------------------------------------------------------------------------------- /modules/home-manager/default.nix: -------------------------------------------------------------------------------- 1 | # Add your reusable home-manager modules to this directory, on their own file (https://nixos.wiki/wiki/Module). 2 | # These should be stuff you would like to share with others, not your personal configurations. 3 | 4 | { 5 | # List your module files here 6 | # my-module = import ./my-module.nix; 7 | } 8 | -------------------------------------------------------------------------------- /modules/nixos/default.nix: -------------------------------------------------------------------------------- 1 | # Add your reusable NixOS modules to this directory, on their own file (https://nixos.wiki/wiki/Module). 2 | # These should be stuff you would like to share with others, not your personal configurations. 3 | 4 | { 5 | # List your module files here 6 | # my-module = import ./my-module.nix; 7 | } 8 | -------------------------------------------------------------------------------- /nixos/configuration.nix: -------------------------------------------------------------------------------- 1 | # This is your system's configuration file. 2 | # Use this to configure your system environment (it replaces /etc/nixos/configuration.nix) 3 | 4 | { inputs, outputs, lib, config, pkgs, ... }: { 5 | # You can import other NixOS modules here 6 | imports = [ 7 | # If you want to use modules your own flake exports (from modules/nixos): 8 | # outputs.nixosModules.example 9 | 10 | # Or modules from other flakes (such as nixos-hardware): 11 | # inputs.hardware.nixosModules.common-cpu-amd 12 | # inputs.hardware.nixosModules.common-ssd 13 | 14 | # You can also split up your configuration and import pieces of it here: 15 | 16 | # Import modules 17 | ./modules 18 | 19 | # Import your generated (nixos-generate-config) hardware configuration 20 | ./hardware-configuration.nix 21 | ]; 22 | 23 | nix = { 24 | # This will add each flake input as a registry 25 | # To make nix3 commands consistent with your flake 26 | registry = lib.mapAttrs (_: value: { flake = value; }) inputs; 27 | 28 | # This will additionally add your inputs to the system's legacy channels 29 | # Making legacy nix commands consistent as well, awesome! 30 | nixPath = lib.mapAttrsToList (key: value: "${key}=${value.to.path}") config.nix.registry; 31 | 32 | settings = { 33 | # Enable flakes and new 'nix' command 34 | experimental-features = "nix-command flakes"; 35 | # Deduplicate and optimize nix store 36 | auto-optimise-store = true; 37 | }; 38 | }; 39 | 40 | # FIXME: Add the rest of your current configuration 41 | } 42 | -------------------------------------------------------------------------------- /nixos/hardware-configuration.nix: -------------------------------------------------------------------------------- 1 | # This is just an example, you should generate yours with nixos-generate-config and put it in here. 2 | { 3 | fileSystems."/" = { 4 | device = "/dev/sda1"; 5 | fsType = "ext4"; 6 | }; 7 | 8 | # Set your system kind (needed for flakes) 9 | nixpkgs.hostPlatform = "x86_64-linux"; 10 | } 11 | -------------------------------------------------------------------------------- /nixos/modules/default.nix: -------------------------------------------------------------------------------- 1 | { 2 | imports = [ 3 | ./pkgs.nix 4 | ./ssh.nix 5 | ./system.nix 6 | ./users.nix 7 | ]; 8 | } 9 | -------------------------------------------------------------------------------- /nixos/modules/pkgs.nix: -------------------------------------------------------------------------------- 1 | # 2 | # pkgs.nix 3 | # 4 | # Configure nixpkgs for the system 5 | # 6 | 7 | { pkgs, config, ... }: 8 | 9 | { 10 | nixpkgs = { 11 | # You can add overlays here 12 | overlays = [ 13 | # Add overlays your own flake exports (from overlays and pkgs dir): 14 | outputs.overlays.additions 15 | outputs.overlays.modifications 16 | outputs.overlays.unstable-packages 17 | 18 | # You can also add overlays exported from other flakes: 19 | # neovim-nightly-overlay.overlays.default 20 | 21 | # Or define it inline, for example: 22 | # (final: prev: { 23 | # hi = final.hello.overrideAttrs (oldAttrs: { 24 | # patches = [ ./change-hello-to-hi.patch ]; 25 | # }); 26 | # }) 27 | ]; 28 | # Configure your nixpkgs instance 29 | config = { 30 | # Disable if you don't want unfree packages 31 | allowUnfree = true; 32 | }; 33 | }; 34 | } 35 | -------------------------------------------------------------------------------- /nixos/modules/ssh.nix: -------------------------------------------------------------------------------- 1 | # 2 | # ssh.nix 3 | # 4 | # Configure ssh server 5 | # 6 | 7 | { pkgs, config, ... }: 8 | 9 | { 10 | # This setups a SSH server. Very important if you're setting up a headless system. 11 | # Feel free to remove if you don't need it. 12 | services.openssh = { 13 | enable = true; 14 | # Forbid root login through SSH. 15 | permitRootLogin = "no"; 16 | # Use keys only. Remove if you want to SSH using password (not recommended) 17 | passwordAuthentication = false; 18 | }; 19 | } 20 | -------------------------------------------------------------------------------- /nixos/modules/system.nix: -------------------------------------------------------------------------------- 1 | # 2 | # system.nix 3 | # 4 | # Configure the system 5 | # 6 | 7 | { pkgs, config, ... }: 8 | 9 | { 10 | # TODO: Set your hostname 11 | networking.hostName = "your-hostname"; 12 | 13 | # Bootloader 14 | boot.loader.systemd-boot.enable = true; 15 | boot.loader.efi.canTouchEfiVariables = true; 16 | boot.loader.efi.efiSysMountPoint = "/boot/efi"; 17 | 18 | # https://nixos.wiki/wiki/FAQ/When_do_I_update_stateVersion 19 | system.stateVersion = "22.11"; 20 | } 21 | -------------------------------------------------------------------------------- /nixos/modules/users.nix: -------------------------------------------------------------------------------- 1 | # 2 | # users.nix 3 | # 4 | # Configure the users 5 | # 6 | 7 | { config, ... }: 8 | 9 | { 10 | # TODO: Configure your system-wide user settings (groups, etc), add more users as needed. 11 | users.users = { 12 | # FIXME: Replace with your username 13 | your-username = { 14 | # TODO: You can set an initial password for your user. 15 | # If you do, you can skip setting a root password by passing '--no-root-passwd' to nixos-install. 16 | # Be sure to change it (using passwd) after rebooting! 17 | initialPassword = "correcthorsebatterystaple"; 18 | isNormalUser = true; 19 | openssh.authorizedKeys.keys = [ 20 | # TODO: Add your SSH public key(s) here, if you plan on using SSH to connect 21 | ]; 22 | # TODO: Be sure to add any other groups you need (such as networkmanager, audio, docker, etc) 23 | extraGroups = [ "wheel" ]; 24 | }; 25 | }; 26 | } 27 | -------------------------------------------------------------------------------- /nixpkgs.nix: -------------------------------------------------------------------------------- 1 | # A nixpkgs instance that is grabbed from the pinned nixpkgs commit in the lock file 2 | # This is useful to avoid using channels when using legacy nix commands 3 | let lock = (builtins.fromJSON (builtins.readFile ./flake.lock)).nodes.nixpkgs.locked; 4 | in 5 | import (fetchTarball { 6 | url = "https://github.com/nixos/nixpkgs/archive/${lock.rev}.tar.gz"; 7 | sha256 = lock.narHash; 8 | }) 9 | -------------------------------------------------------------------------------- /overlays/default.nix: -------------------------------------------------------------------------------- 1 | # This file defines overlays 2 | { inputs, ... }: 3 | { 4 | # This one brings our custom packages from the 'pkgs' directory 5 | additions = final: _prev: import ../pkgs { pkgs = final; }; 6 | 7 | # This one contains whatever you want to overlay 8 | # You can change versions, add patches, set compilation flags, anything really. 9 | # https://nixos.wiki/wiki/Overlays 10 | modifications = final: prev: { 11 | # example = prev.example.overrideAttrs (oldAttrs: rec { 12 | # ... 13 | # }); 14 | }; 15 | 16 | # When applied, the unstable nixpkgs set (declared in the flake inputs) will 17 | # be accessible through 'pkgs.unstable' 18 | unstable-packages = final: _prev: { 19 | unstable = import inputs.nixpkgs-unstable { 20 | system = final.system; 21 | config.allowUnfree = true; 22 | }; 23 | }; 24 | } 25 | -------------------------------------------------------------------------------- /pkgs/default.nix: -------------------------------------------------------------------------------- 1 | # Custom packages, that can be defined similarly to ones from nixpkgs 2 | # You can build them using 'nix build .#example' or (legacy) 'nix-build -A example' 3 | 4 | { pkgs ? (import ../nixpkgs.nix) { } }: { 5 | # example = pkgs.callPackage ./example { }; 6 | } 7 | -------------------------------------------------------------------------------- /shell.nix: -------------------------------------------------------------------------------- 1 | # Shell for bootstrapping flake-enabled nix and home-manager 2 | # You can enter it through 'nix develop' or (legacy) 'nix-shell' 3 | 4 | { pkgs ? (import ./nixpkgs.nix) { } }: { 5 | default = pkgs.mkShell { 6 | # Enable experimental features without having to specify the argument 7 | NIX_CONFIG = "experimental-features = nix-command flakes"; 8 | nativeBuildInputs = with pkgs; [ nix home-manager git ]; 9 | }; 10 | } 11 | --------------------------------------------------------------------------------