nix/flake.org
2022-03-30 08:43:56 -04:00

7.5 KiB

Nix Config

Mr Hedgehog's Nix Config

This is a declarative Nix config, built in Emacs' Org Mode. This uses 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 Nix Flakes, these are git repositories that are locked in the 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 immutable, and they will not change.

{
  description = "Mr Hedgehog's Nix config with flakes";
  inputs = {
    nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
    nixos.url = "github:nixos/nixpkgs?rev=7f9b6e2babf232412682c09e57ed666d8f84ac2d";
    nixos-unstable.url = "github:nixos/nixpkgs/nixos-unstable";
    nixos-hardware.url = "github:nixos/nixos-hardware";
    # my-nixpkgs.url = "github:ModdedGamers/nixpkgs/python-gasp-init";
    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-manager.url = "github:nix-community/home-manager";
    home-manager.inputs.nixpkgs.follows = "nixpkgs";
    home-manager-nixos.url = "github:nix-community/home-manager";
    home-manager-nixos.inputs.nixpkgs.follows = "nixos-unstable";
    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";
    tokyo-night-ff.url = "github:rototrash/tokyo-night-fox";
    tokyo-night-ff.flake = false;
    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";
  };

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.

outputs = inputs @ {
  self,
  nixpkgs,
  nixos,
  nixos-unstable,
  nixos-hardware,
  # my-nixpkgs,
  agenix,
  alejandra,
  doom-emacs,
  emacs,
  home-manager,
  home-manager-nixos,
  neovim,
  nixgl,
  nixpkgs-update,
  nur,
  statix,
  tokyo-night-ff,
  vim-plugins,
  wayland,
}: let

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.

  nixos-overlay = final: prev: {
    nixos = import nixos {
      inherit system;
      config.allowUnfree = true;
      overlays = [
        emacs.overlay
      ];
    };
  };

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.

  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}";};

System archictecture

Pretty simple, it's the architectures that I run this on. x86 only for the forseeable future(until I get a PinePhone.)

  system = "x86_64-linux";

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.

  pkgs = import nixpkgs {
    # inherit system;
    localSystem = "x86_64-linux";
    config = {
      allowUnfree = true;
      input-fonts.acceptLicense = true;
    };
    overlays = [
      (import ./pkgs/default.nix {inherit inputs;})
      (import ./overlays/gopass-jsonapi.nix {inherit pkgs;})
      # my-nixpkgs-overlay
      my-pkgs
      alejandra-overlay
      nixos-overlay
      neovim.overlay
      nixgl.overlay
      nixpkgs-update-overlay
      nur.overlay
      statix.overlay
      vim-plugins.overlay
      wayland.overlay
    ];
  };

Custom package definitions

These are my custom package definitions that are added in the my-pkgs overlay.

in {
  packages.${system} = {
    "sway-launcher-desktop" = pkgs.callPackage ./pkgs/sway-launcher-desktop.nix {};
    "taskwarrior-tui" = pkgs.callPackage ./pkgs/taskwarrior-tui.nix {};
    "tokyo-night-gtk" = pkgs.callPackage ./pkgs/tokyo-night-gtk.nix {};
  };

NixOS configurations

CURRENTLY UNUSED

These are configurations for NixOS-based machines, and can't be used outside of NixOS.

nixosConfigurations.zaphod = nixpkgs.lib.nixosSystem {
  system = "x86_64-linux";
  modules = [
    ./hosts/zaphod/configuration.nix
    inputs.home-manager-nixos.nixosModules.home-manager
    {
      home-manager.useGlobalPkgs = true;
      home-manager.useUserPackages = true;
      home-manager.users.mrhedgehog = import ./home.nix;
      home-manager.extraSpecialArgs = { inherit inputs pkgs doom-emacs; };
    }
    doom-emacs.hmModule
  ];
};

Home-manager configurations

These are the configurations for the 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.

  homeConfigurations.mrhedgehog = home-manager.lib.homeManagerConfiguration {
    inherit pkgs system;
    username = "mrhedgehog";
    stateVersion = "22.05";
    homeDirectory = "/home/mrhedgehog";
    configuration.imports = [./home.nix];
  };
};
}