nix/flake.org

156 lines
7.1 KiB
Org Mode
Raw Normal View History

2022-03-16 10:43:27 +00:00
* Mr Hedgehog's Nix Config
This is a declarative [[https://nixos.org][Nix]] config, built in Emacs' [[https://orgmode.org/][Org Mode]]. This uses [[https://orgmode.org/manual/Extracting-Source-Code.html][tangling]] to make it that code stays perfectly in sync with the documentation, as the code is pulled directly from the documentation itself.
Each of the code blocks here has a description of what is inside the code block.
** The Inputs block
This is where the inputs are declared. In [[https://nixos.wiki/wiki/Flakes][Nix Flakes]], these are git repositories that are locked in the [[file:flake.lock][flake.lock]] file, which is a json lockfile that's automatically created by Nix. When you run a command like =nix flake update=, this lockfile is used to create or update your system. In this way, flakes are [[wikipedia:Immutable][immutable]], and they will not change.
#+NAME: inputs
#+BEGIN_SRC nix :tangle flake.nix
{
description = "Mr Hedgehog's Nix config with flakes";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
nixos.url = "github:nixos/nixpkgs?rev=7f9b6e2babf232412682c09e57ed666d8f84ac2d";
nixos-hardware.url = "github:nixos/nixos-hardware";
2022-03-29 17:57:45 +00:00
# my-nixpkgs.url = "github:ModdedGamers/nixpkgs/python-gasp-init";
2022-03-16 10:43:27 +00:00
agenix.url = "github:ryantm/agenix";
agenix.inputs.nixpkgs.follows = "nixpkgs";
alejandra.url = "github:kamadorueda/alejandra";
alejandra.inputs.nixpkgs.follows = "nixpkgs";
doom-emacs.url = "github:nix-community/nix-doom-emacs";
doom-emacs.inputs.nixpkgs.follows = "nixpkgs";
emacs.url = "github:nix-community/emacs-overlay?rev=f920a177e299989ddcdda5d4875879cf0301c96c";
emacs.inputs.nixpkgs.follows = "nixos";
home.url = "github:nix-community/home-manager";
home.inputs.nixpkgs.follows = "nixpkgs";
neovim.url = "github:nix-community/neovim-nightly-overlay";
neovim.inputs.nixpkgs.follows = "nixpkgs";
nixgl.url = "github:guibou/nixGL";
nixgl.inputs.nixpkgs.follows = "nixpkgs";
nixpkgs-update.url = "github:ryantm/nixpkgs-update";
nur.url = "github:nix-community/nur";
nur.inputs.nixpkgs.follows = "nixpkgs";
statix.url = "github:NerdyPepper/statix";
statix.inputs.nixpkgs.follows = "nixpkgs";
2022-03-24 22:03:59 +00:00
tokyo-night-ff.url = "github:rototrash/tokyo-night-fox";
tokyo-night-ff.flake = false;
2022-03-16 10:43:27 +00:00
vim-plugins.url = "github:m15a/nixpkgs-vim-extra-plugins";
vim-plugins.inputs.nixpkgs.follows = "nixpkgs";
wayland.url = "github:nix-community/nixpkgs-wayland";
wayland.inputs.nixpkgs.url = "nixpkgs";
};
#+END_SRC
** The outputs block
This is fairly simple. The outputs block is simply a block that takes in the outputs and makes them into variables in the context of the flake. the =inputs @= at the beginning means that all of these variables should be addressed as both =<variable>= or =inputs.<variable>=, such as =inputs.nixpkgs= or simply =nixpkgs=. This syntax allows you to import either a few or all of the variables into a lower-level file easily.
#+BEGIN_SRC nix :tangle flake.nix
outputs = inputs @ {
self,
nixpkgs,
nixos,
nixos-hardware,
2022-03-29 17:57:45 +00:00
# my-nixpkgs,
2022-03-16 10:43:27 +00:00
agenix,
alejandra,
doom-emacs,
emacs,
home,
neovim,
nixgl,
nixpkgs-update,
nur,
statix,
2022-03-24 22:03:59 +00:00
tokyo-night-ff,
2022-03-16 10:43:27 +00:00
vim-plugins,
wayland,
}: let
#+END_SRC
** The NixOS overlay
This is an overlay of a different revision of nixpkgs, which is used so that I don't build Emacs from source when I update the overlay.
#+BEGIN_SRC nix :tangle flake.nix
nixos-overlay = final: prev: {
nixos = import nixos {
inherit system;
config.allowUnfree = true;
overlays = [
emacs.overlay
];
};
};
#+END_SRC
** Small overlays
These are some small overlays that I use only for one or 2 packages. The =my-nixpkgs-overlay= overlay is my own mirror of nixpkgs that I use to get my custom packages before they're added to stable nixpkgs. Each of the other ones is only used for 1 package, except for the =my-pkgs= overlay, which contains packages defined inside this flake.
#+BEGIN_SRC nix :tangle flake.nix
alejandra-overlay = final: prev: {alejandra = alejandra.defaultPackage.${prev.system};};
my-nixpkgs-overlay = final: prev: { my-nixpkgs = import my-nixpkgs { inherit system;};};
nixpkgs-update-overlay = final: prev: {nixpkgs-update = nixpkgs-update.defaultPackage.${prev.system};};
my-pkgs = final: prev: {my-pkgs = self.packages."${prev.system}";};
#+END_SRC
** System archictecture
Pretty simple, it's the architectures that I run this on. x86 only for the forseeable future(until I get a *PinePhone*.)
#+BEGIN_SRC nix :tangle flake.nix
system = "x86_64-linux";
#+END_SRC
** My =pkgs= definition
This is the heart of the customization for my flake. This defines which repo I use as my source of truth, then adds all of the overlays from earlier to it, as well as some extra package overlays(anything in parentheses), as well as allowing unfree packages.
#+BEGIN_SRC nix :tangle flake.nix
pkgs = import nixpkgs {
inherit system;
config = {
allowUnfree = true;
input-fonts.acceptLicense = true;
};
overlays = [
(import ./pkgs/default.nix {inherit inputs;})
(import ./overlays/gopass-jsonapi.nix {inherit pkgs;})
2022-03-29 17:57:45 +00:00
# my-nixpkgs-overlay
2022-03-16 10:43:27 +00:00
my-pkgs
alejandra-overlay
nixos-overlay
neovim.overlay
nixgl.overlay
nixpkgs-update-overlay
nur.overlay
statix.overlay
vim-plugins.overlay
wayland.overlay
];
};
#+END_SRC
** Custom package definitions
These are my custom package definitions that are added in the =my-pkgs= overlay.
#+BEGIN_SRC nix :tangle flake.nix
in {
packages.${system} = {
"sway-launcher-desktop" = pkgs.callPackage ./pkgs/sway-launcher-desktop.nix {};
"taskwarrior-tui" = pkgs.callPackage ./pkgs/taskwarrior-tui.nix {};
2022-03-24 22:03:59 +00:00
"tokyo-night-gtk" = pkgs.callPackage ./pkgs/tokyo-night-gtk.nix {};
2022-03-16 10:43:27 +00:00
};
#+END_SRC
** NixOS configurations
*** CURRENTLY UNUSED
These are configurations for NixOS-based machines, and can't be used outside of NixOS.
#+BEGIN_SRC nix :tangle flake.nix
# nixosConfigurations.zaphod = import ./hosts/zaphod {
# inherit nixpkgs pkgs inputs system;
# };
#+END_SRC
** Home-manager configurations
These are the configurations for the [[github:nix-community/home-manager][home-manager]] tool. =home-manager= is an incredible part of the NixOS ecosystem, and allows you to build your =~= configurations declaratively, and outside of NixOS.
#+BEGIN_SRC nix :tangle flake.nix
homeConfigurations.mrhedgehog = home.lib.homeManagerConfiguration {
inherit pkgs system;
username = "mrhedgehog";
stateVersion = "22.05";
homeDirectory = "/home/mrhedgehog";
configuration.imports = [./home.nix doom-emacs.hmModule];
};
#+END_SRC
** Colmena
This is my configuration for [[github:zhaofengli/colmena][colmena]], a stateless NixOS deplyment tool. It allows you to remotely deploy all of your NixOS-based machines.
#+BEGIN_SRC nix :tangle flake.nix
colmena = import ./hosts/default.nix;
};
}
#+END_SRC