simple version
This commit is contained in:
parent
a4d2b03b3c
commit
c735d3b576
180
README.md
180
README.md
|
@ -1,18 +1,15 @@
|
||||||
# Nix Starter Config
|
# Nix Starter Config (Minimal version)
|
||||||
|
|
||||||
This is a simple nix flake for getting started with NixOS + home-manager.
|
This is a simple nix flake for getting started with NixOS + home-manager.
|
||||||
|
|
||||||
|
[**Looking for the full version?**](https://github.com/Misterio77/nix-config/tree/main)
|
||||||
|
|
||||||
# What this provides
|
# What this provides
|
||||||
|
|
||||||
- NixOS configuration on `nixos/configuration.nix`, accessible via
|
- NixOS configuration on `nixos/configuration.nix`, accessible via
|
||||||
`nixos-rebuild --flake .`
|
`nixos-rebuild --flake .`
|
||||||
- Home-manager configuration on `home-manager/home.nix`, accessible via
|
- Home-manager configuration on `home-manager/home.nix`, accessible via
|
||||||
`home-manager --flake .`
|
`home-manager --flake .`
|
||||||
- Basic boilerplate for adding custom packages (under `pkgs`) and overlays
|
|
||||||
(under `overlays`). Accessible on your system, home config, as well as `nix
|
|
||||||
build .#package-name`
|
|
||||||
- Boilerplate for custom NixOS (`modules/nixos`) and home-manager
|
|
||||||
(`modules/home-manager`) modules
|
|
||||||
|
|
||||||
# Getting started
|
# Getting started
|
||||||
|
|
||||||
|
@ -20,19 +17,6 @@ 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
|
works). [Here's a link to the latest NixOS downloads, just for
|
||||||
you](https://nixos.org/download#download-nixos).
|
you](https://nixos.org/download#download-nixos).
|
||||||
|
|
||||||
## I like your funny words, magic man
|
|
||||||
|
|
||||||
Not sure what this all means?
|
|
||||||
|
|
||||||
Take a look at [the learn hub on the NixOS
|
|
||||||
website](https://nixos.org/learn.html) (scroll down to guides, the manuals, and
|
|
||||||
the other awesome learning resources).
|
|
||||||
|
|
||||||
Learning the basics of what Nix (the package manager) is, how the Nix language
|
|
||||||
works, and a bit of NixOS basics should get you up and running. Don't worry if
|
|
||||||
it seems a little confusing at first. Get confortable with the basic concepts
|
|
||||||
and come back here to get your feet wet, it's the best way to learn!
|
|
||||||
|
|
||||||
## The repo
|
## The repo
|
||||||
|
|
||||||
- [Install git](https://nixos.wiki/wiki/git)
|
- [Install git](https://nixos.wiki/wiki/git)
|
||||||
|
@ -58,44 +42,11 @@ and come back here to get your feet wet, it's the best way to learn!
|
||||||
|
|
||||||
## Bootstrapping
|
## Bootstrapping
|
||||||
|
|
||||||
To get everything up and running, you need flake-enabled nix and home-manager.
|
To get everything up and running, you need flake-enabled nix and/or home-manager.
|
||||||
|
|
||||||
First off, check your nix version using `nix --version`.
|
For simplicity, this minimal version does not include a bootstrap shell.
|
||||||
|
|
||||||
### Version < 2.4
|
Check the [NixOS wiki](https://nixos.wiki/wiki/Flakes) for information on how to enable flakes.
|
||||||
|
|
||||||
Bummer, your nix version does not support flakes. But fear not!
|
|
||||||
|
|
||||||
You _don't_ need to mess around with channels to get up and running.
|
|
||||||
|
|
||||||
Just run:
|
|
||||||
```bash
|
|
||||||
nix-shell
|
|
||||||
```
|
|
||||||
|
|
||||||
Wow, that was easy. Our `shell.nix` file will detect you can't evaluate (nor
|
|
||||||
lock) the flake, and will grab `nix` and `home-manager` from the latest
|
|
||||||
`nixos-unstable` versions, just for you.
|
|
||||||
|
|
||||||
Once you're bootstrapped, remember to run `nix flake lock` and commit the
|
|
||||||
newly-created `flake.lock` into your repository, this will make future
|
|
||||||
bootstraps reproductible.
|
|
||||||
|
|
||||||
### Version >= 2.4
|
|
||||||
|
|
||||||
Congrats, your nix version supports flakes! It's just hidden behind a feature flag.
|
|
||||||
|
|
||||||
You can bootstrap with:
|
|
||||||
```bash
|
|
||||||
nix --experimental-features develop "nix-command flakes" .#default
|
|
||||||
```
|
|
||||||
|
|
||||||
The shell will also enable those experimental features, so no need to pass that
|
|
||||||
argument while you're inside (or after installation, if you set the option that
|
|
||||||
enables them globally).
|
|
||||||
|
|
||||||
This should generate a `flake.lock`. Remember to commit it, as this will make
|
|
||||||
future bootstraps reproductible.
|
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
|
@ -106,121 +57,10 @@ future bootstraps reproductible.
|
||||||
- Run `home-manager switch --flake .#username@hostname` to apply your home
|
- Run `home-manager switch --flake .#username@hostname` to apply your home
|
||||||
configuration.
|
configuration.
|
||||||
|
|
||||||
And that's it, really! You're ready to have fun with your configurations using
|
|
||||||
the latest and greatest nix3 flake-enabled command UX.
|
|
||||||
|
|
||||||
# What next?
|
# What next?
|
||||||
|
|
||||||
## User password and secrets
|
## Full version
|
||||||
|
|
||||||
You have basically two ways of setting up default passwords:
|
Once you're confortable with this flake, take a look at the [full
|
||||||
- By default, you'll be prompted for a root password when installing with
|
version](https://github.com/Misterio77/nix-config/tree/main), it includes
|
||||||
`nixos-install`. After you reboot, be sure to add a password to your own
|
boilerplate for overlays, custom packages, and more.
|
||||||
account and lock root using `sudo passwd -l root`.
|
|
||||||
- Alternatively, you can specify `initialPassword` for your user. This will
|
|
||||||
give your account a default password, be sure to change it after rebooting!
|
|
||||||
If you do, you should pass `--no-root-passwd` to `nixos-install`, to skip
|
|
||||||
setting a password on the root account.
|
|
||||||
|
|
||||||
If you don't want to set your password imperatively, you can also use
|
|
||||||
`passwordFile` for safely and declaratively setting a password from a file
|
|
||||||
outside the nix store.
|
|
||||||
|
|
||||||
There's also [more advanced options for secret
|
|
||||||
management](https://nixos.wiki/wiki/Comparison_of_secret_managing_schemes),
|
|
||||||
including some that can include them (encrypted) into your config repo and/or
|
|
||||||
nix store, be sure to check them out if you're interested.
|
|
||||||
|
|
||||||
## Dotfile management with home-manager
|
|
||||||
|
|
||||||
Besides just adding packages to your environment, home-manager can also manage
|
|
||||||
your dotfiles. I strongly recommend you do, it's awesome!
|
|
||||||
|
|
||||||
For full nix goodness, check out the home-manager options with `man
|
|
||||||
home-configuration.nix`. Using them, you'll be able to fully configure any
|
|
||||||
program with nix syntax and its powerful abstractions.
|
|
||||||
|
|
||||||
Alternatively, if you're still not ready to rewrite all your configs to nix
|
|
||||||
syntax, there's home-manager options (such as `xdg.configFile`) for including
|
|
||||||
files from your config repository into your usual dot directories. Add your
|
|
||||||
existing dotfiles to this repo and try it out!
|
|
||||||
|
|
||||||
## Try opt-in persistance
|
|
||||||
|
|
||||||
You might have noticed that there's impurity in your NixOS system, in the form
|
|
||||||
of configuration files and other cruft your system generates when running. What
|
|
||||||
if you change them in a whim to get something working and forget about it?
|
|
||||||
Boom, your system is not fully reproductible anymore.
|
|
||||||
|
|
||||||
You can instead fully delete your `/` and `/home` on every boot! Nix is okay
|
|
||||||
with a empty root on boot (all you need is `/boot` and `/nix`), and will
|
|
||||||
happily reapply your configurations.
|
|
||||||
|
|
||||||
There's two main approaches to this: mount a `tmpfs` (RAM disk) to `/`, or
|
|
||||||
(using a filesystem such as btrfs or zfs) mount a blank snapshot and reset it
|
|
||||||
on boot.
|
|
||||||
|
|
||||||
For stuff that can't be managed through nix (such as games downloaded from
|
|
||||||
steam, or logs), use [impermanence](https://github.com/nix-community/impermanence)
|
|
||||||
for mounting stuff you to keep to a separate partition/volume (such as
|
|
||||||
`/nix/persist` or `/persist`). This makes everything vanish by default, and you
|
|
||||||
can keep track of what you specifically asked to be kept.
|
|
||||||
|
|
||||||
Here's some awesome blog posts about it:
|
|
||||||
- [Erase your darlings](https://grahamc.com/blog/erase-your-darlings)
|
|
||||||
- [Encrypted BTRFS with Opt-In State on
|
|
||||||
NixOS](https://mt-caret.github.io/blog/posts/2020-06-29-optin-state.html)
|
|
||||||
- [NixOS: tmpfs as root](https://elis.nu/blog/2020/05/nixos-tmpfs-as-root/) and
|
|
||||||
[tmpfs as home](https://elis.nu/blog/2020/06/nixos-tmpfs-as-home/)
|
|
||||||
|
|
||||||
## Adding custom packages
|
|
||||||
|
|
||||||
Something you want to use that's not in nixpkgs yet? You can easily build and
|
|
||||||
iterate on a derivation (package) from this very repository.
|
|
||||||
|
|
||||||
Create a folder with the desired name inside `pkgs`, and add a `default.nix`
|
|
||||||
file containing a derivation. Be sure to also `callPackage` them on
|
|
||||||
`pkgs/default.nix`.
|
|
||||||
|
|
||||||
You'll be able to refer to that package from anywhere on your
|
|
||||||
home-manager/nixos configurations, build them with `nix build .#package-name`,
|
|
||||||
or bring them into your shell with `nix shell .#package-name`.
|
|
||||||
|
|
||||||
See [the manual](https://nixos.org/manual/nixpkgs/stable/) for some tips on how
|
|
||||||
to package stuff.
|
|
||||||
|
|
||||||
## Adding overlays
|
|
||||||
|
|
||||||
Found some outdated package on nixpkgs you need the latest version of? Perhaps
|
|
||||||
you want to apply a patch to fix a behaviour you don't like? Nix makes it easy
|
|
||||||
and manageble with overlays!
|
|
||||||
|
|
||||||
Use the `overlay/default.nix` file for this.
|
|
||||||
|
|
||||||
If you're creating patches, you can keep them on the `overlay` folder as well.
|
|
||||||
|
|
||||||
See [the wiki article](https://nixos.wiki/wiki/Overlays) to see how it all
|
|
||||||
works.
|
|
||||||
|
|
||||||
## Adding your own modules
|
|
||||||
|
|
||||||
Got some configurations you want to create an abstraction of? Modules are the
|
|
||||||
answer. These awesome files can expose _options_ and implement _configurations_
|
|
||||||
based on how the options are set.
|
|
||||||
|
|
||||||
Create a file for them on either `modules/nixos` or `modules/home-manager`. Be
|
|
||||||
sure to also add them to the listing at `modules/nixos/default.nix` or
|
|
||||||
`modules/home-manager/default.nix`.
|
|
||||||
|
|
||||||
See [the wiki article](https://nixos.wiki/wiki/Module) to learn more about
|
|
||||||
them.
|
|
||||||
|
|
||||||
## Adding more hosts or users
|
|
||||||
|
|
||||||
You can organize them by hostname and username on `nixos` and `home-manager`
|
|
||||||
directories, be sure to also add them to `flake.nix`.
|
|
||||||
|
|
||||||
NixOS makes it easy to share common configuration between hosts (you might want
|
|
||||||
to create a common directory for these), while keeping everything in sync.
|
|
||||||
home-manager can help you sync your environment (from editor to WM and
|
|
||||||
everything in between) anywhere you use it. Have fun!
|
|
||||||
|
|
64
flake.lock
Normal file
64
flake.lock
Normal file
|
@ -0,0 +1,64 @@
|
||||||
|
{
|
||||||
|
"nodes": {
|
||||||
|
"hardware": {
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1653145312,
|
||||||
|
"narHash": "sha256-affCuB0Boa8CDFykoJVPZfhHLBok7Sq+QEOJvo3Xf+k=",
|
||||||
|
"owner": "nixos",
|
||||||
|
"repo": "nixos-hardware",
|
||||||
|
"rev": "8b5e1bf2fd62adefff05ae67cd49440be93ea193",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "nixos",
|
||||||
|
"repo": "nixos-hardware",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"home-manager": {
|
||||||
|
"inputs": {
|
||||||
|
"nixpkgs": [
|
||||||
|
"nixpkgs"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1653153149,
|
||||||
|
"narHash": "sha256-8B/tWWZziFq4DqnAm9uO7M4Z4PNfllYg5+teX1e5yDQ=",
|
||||||
|
"owner": "nix-community",
|
||||||
|
"repo": "home-manager",
|
||||||
|
"rev": "94780dd888881bf35165dfdd334a57ef6b14ead8",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "nix-community",
|
||||||
|
"repo": "home-manager",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"nixpkgs": {
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1653060744,
|
||||||
|
"narHash": "sha256-kfRusllRumpt33J1hPV+CeCCylCXEU7e0gn2/cIM7cY=",
|
||||||
|
"owner": "nixos",
|
||||||
|
"repo": "nixpkgs",
|
||||||
|
"rev": "dfd82985c273aac6eced03625f454b334daae2e8",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "nixos",
|
||||||
|
"ref": "nixos-unstable",
|
||||||
|
"repo": "nixpkgs",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"root": {
|
||||||
|
"inputs": {
|
||||||
|
"hardware": "hardware",
|
||||||
|
"home-manager": "home-manager",
|
||||||
|
"nixpkgs": "nixpkgs"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"root": "root",
|
||||||
|
"version": 7
|
||||||
|
}
|
52
flake.nix
52
flake.nix
|
@ -4,54 +4,28 @@
|
||||||
inputs = {
|
inputs = {
|
||||||
# Nixpkgs
|
# Nixpkgs
|
||||||
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
|
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
|
||||||
|
hardware.url = "github:nixos/nixos-hardware";
|
||||||
|
|
||||||
# Home manager
|
# Home manager
|
||||||
home-manager.url = "github:nix-community/home-manager";
|
home-manager.url = "github:nix-community/home-manager";
|
||||||
home-manager.inputs.nixpkgs.follows = "nixpkgs";
|
home-manager.inputs.nixpkgs.follows = "nixpkgs";
|
||||||
|
|
||||||
# Utilities for building our flake
|
|
||||||
flake-utils.url = "github:numtide/flake-utils";
|
|
||||||
|
|
||||||
# Extra flakes for modules, packages, etc
|
|
||||||
hardware.url = "github:nixos/nixos-hardware"; # Convenience modules for hardware-specific quirks
|
|
||||||
# nur.url = "github:nix-community/NUR"; # User contributed pkgs and modules
|
|
||||||
# nix-colors.url = "github:misterio77/nix-colors"; # Color schemes for usage with home-manager
|
|
||||||
# impermanence.url = "github:riscadoa/impermanence"; # Utilities for opt-in persistance
|
|
||||||
# TODO: Add any other flakes you need
|
|
||||||
};
|
};
|
||||||
|
|
||||||
outputs = { nixpkgs, home-manager, flake-utils, ... }@inputs:
|
outputs = { nixpkgs, home-manager, ... }@inputs:
|
||||||
let
|
let
|
||||||
# Bring some functions into scope (from builtins and other flakes)
|
# Bring some functions into scope (from builtins and other flakes)
|
||||||
inherit (builtins) attrValues;
|
|
||||||
inherit (flake-utils.lib) eachSystemMap defaultSystems;
|
|
||||||
inherit (nixpkgs.lib) nixosSystem;
|
inherit (nixpkgs.lib) nixosSystem;
|
||||||
inherit (home-manager.lib) homeManagerConfiguration;
|
inherit (home-manager.lib) homeManagerConfiguration;
|
||||||
eachDefaultSystemMap = eachSystemMap defaultSystems;
|
|
||||||
in
|
in
|
||||||
rec {
|
rec {
|
||||||
# TODO: If you want to use packages exported from other flakes, add their overlays here.
|
|
||||||
# They will be added to your 'pkgs'
|
|
||||||
overlays = {
|
|
||||||
default = import ./overlay; # Our own overlay
|
|
||||||
# nur = nur.overlay
|
|
||||||
};
|
|
||||||
|
|
||||||
# System configurations
|
# System configurations
|
||||||
# Accessible via 'nixos-rebuild'
|
# Accessible via 'nixos-rebuild'
|
||||||
nixosConfigurations = {
|
nixosConfigurations = {
|
||||||
# FIXME: Replace with your hostname
|
# FIXME: Replace with your hostname
|
||||||
your-hostname = nixosSystem {
|
your-hostname = nixosSystem {
|
||||||
system = "x86_64-linux";
|
system = "x86_64-linux";
|
||||||
|
|
||||||
modules = [
|
|
||||||
# >> Main NixOS configuration file <<
|
# >> Main NixOS configuration file <<
|
||||||
./nixos/configuration.nix
|
modules = [ ./nixos/configuration.nix ];
|
||||||
# Adds your custom NixOS modules
|
|
||||||
./modules/nixos
|
|
||||||
# Adds overlays
|
|
||||||
{ nixpkgs.overlays = attrValues overlays; }
|
|
||||||
];
|
|
||||||
# Make our inputs available to the config (for importing modules)
|
# Make our inputs available to the config (for importing modules)
|
||||||
specialArgs = { inherit inputs; };
|
specialArgs = { inherit inputs; };
|
||||||
};
|
};
|
||||||
|
@ -66,31 +40,11 @@
|
||||||
username = "your-name";
|
username = "your-name";
|
||||||
homeDirectory = "/home/${username}";
|
homeDirectory = "/home/${username}";
|
||||||
system = "x86_64-linux";
|
system = "x86_64-linux";
|
||||||
|
|
||||||
# >> Main home-manager configuration file <<
|
# >> Main home-manager configuration file <<
|
||||||
configuration = ./home-manager/home.nix;
|
configuration = ./home-manager/home.nix;
|
||||||
extraModules = [
|
|
||||||
# Adds your custom home-manager modules
|
|
||||||
./modules/home-manager
|
|
||||||
# Adds overlays
|
|
||||||
{ nixpkgs.overlays = attrValues overlays; }
|
|
||||||
];
|
|
||||||
# Make our inputs available to the config (for importing modules)
|
# Make our inputs available to the config (for importing modules)
|
||||||
extraSpecialArgs = { inherit inputs; };
|
extraSpecialArgs = { inherit inputs; };
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
# Packages
|
|
||||||
# Accessible via 'nix build'
|
|
||||||
packages = eachDefaultSystemMap (system:
|
|
||||||
# Propagate nixpkgs' packages, with our overlays applied
|
|
||||||
import nixpkgs { inherit system; overlays = attrValues overlays; }
|
|
||||||
);
|
|
||||||
|
|
||||||
# Devshell for bootstrapping
|
|
||||||
# Accessible via 'nix develop'
|
|
||||||
devShells = eachDefaultSystemMap (system: {
|
|
||||||
default = import ./shell.nix { pkgs = packages.${system}; };
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +0,0 @@
|
||||||
# Add your home-manager modules to this directory, on their own file (https://nixos.wiki/wiki/Module).
|
|
||||||
|
|
||||||
{
|
|
||||||
imports = [
|
|
||||||
# List your module files here
|
|
||||||
];
|
|
||||||
}
|
|
|
@ -1,7 +0,0 @@
|
||||||
# Add your NixOS modules to this directory, on their own file (https://nixos.wiki/wiki/Module).
|
|
||||||
|
|
||||||
{
|
|
||||||
imports = [
|
|
||||||
# List your module files here
|
|
||||||
];
|
|
||||||
}
|
|
|
@ -1,8 +0,0 @@
|
||||||
# Your overlays go here (see https://nixos.wiki/wiki/Overlays)
|
|
||||||
|
|
||||||
final: prev: {
|
|
||||||
# example = prev.example.overrideAttrs (oldAttrs: rec {
|
|
||||||
# ...
|
|
||||||
# });
|
|
||||||
# This line adds our custom packages into the overlay.
|
|
||||||
} // import ../pkgs { pkgs = final; }
|
|
|
@ -1,4 +0,0 @@
|
||||||
# When you add custom packages, list them here
|
|
||||||
{ pkgs }: {
|
|
||||||
# example = pkgs.callPackage ./example { };
|
|
||||||
}
|
|
37
shell.nix
37
shell.nix
|
@ -1,37 +0,0 @@
|
||||||
# Shell for bootstrapping flake-enabled nix and home-manager, from any nix version
|
|
||||||
{ pkgs ? let
|
|
||||||
inherit (builtins) currentSystem pathExists fromJSON readFile;
|
|
||||||
|
|
||||||
nixpkgs =
|
|
||||||
if pathExists ./flake.lock
|
|
||||||
then
|
|
||||||
# If we have a lock, fetch locked nixpkgs
|
|
||||||
let
|
|
||||||
inherit ((fromJSON (readFile ./flake.lock)).nodes.nixpkgs) locked;
|
|
||||||
in
|
|
||||||
fetchTarball {
|
|
||||||
url = "https://github.com/nixos/nixpkgs/archive/${locked.rev}.tar.gz";
|
|
||||||
sha256 = locked.narHash;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
# If not (probably because not flake-enabled), fetch nixos-unstable impurely
|
|
||||||
fetchTarball {
|
|
||||||
url = "https://github.com/nixos/nixpkgs/archive/nixos-unstable.tar.gz";
|
|
||||||
};
|
|
||||||
|
|
||||||
system = currentSystem;
|
|
||||||
overlays = [ ];
|
|
||||||
|
|
||||||
in
|
|
||||||
import nixpkgs { inherit system overlays; }
|
|
||||||
, ...
|
|
||||||
}:
|
|
||||||
let
|
|
||||||
# Enable experimental features without having to specify the argument
|
|
||||||
nix = pkgs.writeShellScriptBin "nix" ''
|
|
||||||
exec ${pkgs.nixFlakes}/bin/nix --experimental-features "nix-command flakes" "$@"
|
|
||||||
'';
|
|
||||||
in
|
|
||||||
pkgs.mkShell {
|
|
||||||
nativeBuildInputs = with pkgs; [ nix home-manager git ];
|
|
||||||
}
|
|
Loading…
Reference in a new issue