2024-05-04 23:15:57 +03:00
# This is a configuration entry-point called "Flake".
# Here you define your inputs (dependencies) and outputs (hosts).
2024-03-04 00:34:39 +03:00
{
2024-05-04 23:15:57 +03:00
# Those are external dependencies.
2024-03-04 00:34:39 +03:00
inputs = {
2024-05-04 23:15:57 +03:00
# Core system.
# Homepage: https://github.com/NixOS/nixpkgs
# Manual: https://nixos.org/manual/nixos/stable
# Search: https://search.nixos.org/packages and https://search.nixos.org/options
2024-06-20 22:13:59 +03:00
nixpkgs . url = " g i t h u b : n i x o s / n i x p k g s / n i x o s - u n s t a b l e " ;
2024-06-21 10:50:04 +03:00
nixpkgsStable . url = " g i t h u b : n i x o s / n i x p k g s / n i x o s - 2 4 . 0 5 " ;
2024-06-20 22:13:59 +03:00
nixpkgsMaster . url = " g i t h u b : n i x o s / n i x p k g s / m a s t e r " ;
2024-05-04 23:15:57 +03:00
# This thing manages user's /home directroies. Because NixOS only manages system itself.
# Homepage: https://github.com/nix-community/home-manager
# Manual: https://nix-community.github.io/home-manager
# Search: https://home-manager-options.extranix.com
2024-03-04 00:34:39 +03:00
home-manager = {
url = " g i t h u b : n i x - c o m m u n i t y / h o m e - m a n a g e r " ;
2024-05-04 23:15:57 +03:00
# This means that home-manager and our Flake both depend on the same nixpkgs version.
2024-03-04 00:34:39 +03:00
inputs . nixpkgs . follows = " n i x p k g s " ;
} ;
2024-05-04 23:15:57 +03:00
# This allows automatic styling based on active Wallpaper.
# Homepage: https://github.com/danth/stylix
# Manual: https://danth.github.io/stylix
stylix . url = " g i t h u b : d a n t h / s t y l i x " ;
2024-06-09 23:35:53 +03:00
# I use this for a single container called jobber.
# You likely won't need this one, so just skip it for now.
poetry2nixJobber . url = " g i t h u b : n i x - c o m m u n i t y / p o e t r y 2 n i x / 3 0 4 f 8 2 3 5 f b 0 7 2 9 f d 4 8 5 6 7 a f 3 4 f c d 1 b 5 8 d 1 8 f 9 b 9 5 " ;
nixpkgsJobber . url = " g i t h u b : n i x o s / n i x p k g s / 0 5 1 f 9 2 0 6 2 5 a b 5 a a b e 3 7 c 9 2 0 3 4 6 e 3 e 6 9 d 7 d 3 4 4 0 0 e " ;
2024-05-04 23:15:57 +03:00
# Nix on Android (inside Termux). It has no NixOS modules, but still allows the use of Nixpkgs arm packages with Home-Manager configurations.
# Homepage: https://github.com/nix-community/nix-on-droid
# Manual: https://github.com/nix-community/nix-on-droid/blob/master/README.md
2024-03-04 00:34:39 +03:00
nix-on-droid = {
2024-06-21 14:34:40 +03:00
url = " g i t h u b : t 1 8 4 2 5 6 / n i x - o n - d r o i d / r e l e a s e - 2 3 . 1 1 " ;
2024-03-04 23:11:23 +03:00
inputs . nixpkgs . follows = " n i x p k g s " ;
inputs . home-manager . follows = " h o m e - m a n a g e r " ;
2024-03-04 00:34:39 +03:00
} ;
2024-05-04 23:15:57 +03:00
# Those are Nvim plugins. I do not use package managers like Packer or Lazy, instead I use Nix to download them and later configure in [Neovim module](module/common/Nvim.nix).
2024-03-04 00:34:39 +03:00
nvimAlign = {
2024-04-03 07:34:36 +03:00
url = " g i t h u b : e c h a s n o v s k i / m i n i . a l i g n " ;
2024-03-04 00:34:39 +03:00
flake = false ;
} ;
nvimAutoclose = {
2024-04-03 07:34:36 +03:00
url = " g i t h u b : m 4 x s h e n / a u t o c l o s e . n v i m " ;
2024-03-04 00:34:39 +03:00
flake = false ;
} ;
nvimBufferline = {
2024-04-03 07:34:36 +03:00
url = " g i t h u b : a k i n s h o / b u f f e r l i n e . n v i m " ;
2024-03-04 00:34:39 +03:00
flake = false ;
} ;
nvimCloseBuffers = {
2024-04-03 07:34:36 +03:00
url = " g i t h u b : k a z h a l a / c l o s e - b u f f e r s . n v i m " ;
2024-03-04 00:34:39 +03:00
flake = false ;
} ;
2024-04-04 04:02:29 +03:00
nvimColorizer = {
url = " g i t h u b : b r e n o p r a t a 1 0 / n v i m - h i g h l i g h t - c o l o r s " ;
flake = false ;
} ;
2024-03-04 00:34:39 +03:00
nvimDevicons = {
2024-04-03 07:34:36 +03:00
url = " g i t h u b : n v i m - t r e e / n v i m - w e b - d e v i c o n s " ;
2024-03-04 00:34:39 +03:00
flake = false ;
} ;
nvimGitsigns = {
2024-04-03 07:34:36 +03:00
url = " g i t h u b : l e w i s 6 9 9 1 / g i t s i g n s . n v i m " ;
2024-03-04 00:34:39 +03:00
flake = false ;
} ;
2024-03-05 22:25:23 +03:00
nvimGruvboxMaterial = {
2024-04-03 07:34:36 +03:00
url = " g i t h u b : s a i n n h e / g r u v b o x - m a t e r i a l " ;
2024-03-04 00:34:39 +03:00
flake = false ;
} ;
nvimIndentoMatic = {
2024-04-03 07:34:36 +03:00
url = " g i t h u b : D a r a z a k i / i n d e n t - o - m a t i c " ;
2024-03-04 00:34:39 +03:00
flake = false ;
} ;
nvimLspconfig = {
2024-04-03 07:34:36 +03:00
url = " g i t h u b : n e o v i m / n v i m - l s p c o n f i g " ;
2024-03-04 00:34:39 +03:00
flake = false ;
} ;
nvimOllama = {
2024-04-03 07:34:36 +03:00
url = " g i t h u b : n o m n i v o r e / o l l a m a . n v i m " ;
2024-03-04 00:34:39 +03:00
flake = false ;
} ;
nvimPlenary = {
2024-04-03 07:34:36 +03:00
url = " g i t h u b : n v i m - l u a / p l e n a r y . n v i m " ;
2024-03-04 00:34:39 +03:00
flake = false ;
} ;
nvimSingleComment = {
2024-04-03 07:34:36 +03:00
url = " g i t h u b : L u c a s T a v a r e s A / s i n g l e c o m m e n t . n v i m " ;
2024-03-04 00:34:39 +03:00
flake = false ;
} ;
nvimTelescope = {
2024-04-03 07:34:36 +03:00
url = " g i t h u b : n v i m - t e l e s c o p e / t e l e s c o p e . n v i m " ;
2024-03-04 00:34:39 +03:00
flake = false ;
} ;
nvimTodo = {
2024-04-03 07:34:36 +03:00
url = " g i t h u b : f o l k e / t o d o - c o m m e n t s . n v i m " ;
2024-03-04 00:34:39 +03:00
flake = false ;
} ;
nvimTokyonight = {
2024-04-03 07:34:36 +03:00
url = " g i t h u b : f o l k e / t o k y o n i g h t . n v i m " ;
2024-03-04 00:34:39 +03:00
flake = false ;
} ;
nvimTree = {
2024-04-03 07:34:36 +03:00
url = " g i t h u b : n v i m - t r e e / n v i m - t r e e . l u a " ;
2024-03-04 00:34:39 +03:00
flake = false ;
} ;
nvimTreesitter = {
2024-04-03 07:34:36 +03:00
url = " g i t h u b : n v i m - t r e e s i t t e r / n v i m - t r e e s i t t e r " ;
2024-03-04 00:34:39 +03:00
flake = false ;
} ;
nvimTrouble = {
2024-04-03 07:34:36 +03:00
url = " g i t h u b : f o l k e / t r o u b l e . n v i m " ;
2024-03-04 00:34:39 +03:00
flake = false ;
} ;
nvimWhichKey = {
2024-04-03 07:34:36 +03:00
url = " g i t h u b : f o l k e / w h i c h - k e y . n v i m " ;
2024-03-04 00:34:39 +03:00
flake = false ;
} ;
} ;
2024-05-04 23:15:57 +03:00
# Those are outputs (hosts, configurations) that can be produced by this whole config.
# Here you see a set of inputs we defined above, like nixpkgs, home-manager and so on.
# `...` at the end of a set means "ignore other arguments provided to this function".
# @inputs means aliasing all the inputs to the `inputs` name, so we can pass them all at once later.
2024-06-20 22:13:59 +03:00
outputs = { self , nixpkgs , nixpkgsStable , nixpkgsMaster , nix-on-droid , home-manager , stylix , poetry2nixJobber , nixpkgsJobber , . . . } @ inputs : {
2024-03-04 00:34:39 +03:00
# Constant values.
2024-04-15 00:41:40 +03:00
const = {
2024-06-21 14:34:40 +03:00
droidStateVersion = " 2 3 . 1 1 " ;
2024-06-01 10:37:49 +03:00
stateVersion = " 2 4 . 0 5 " ;
2024-03-26 06:36:00 +03:00
timeZone = " E u r o p e / M o s c o w " ;
2024-04-14 19:44:38 +03:00
url = " h t t p s : / / g i t . v o r o n i n d . c o m / v o r o n i n d / n i x o s . g i t " ;
2024-03-04 00:34:39 +03:00
} ;
2024-05-04 23:15:57 +03:00
# Common modules used across all the hosts.
2024-04-15 00:30:57 +03:00
nixosModules . common = let
2024-05-04 23:15:57 +03:00
# This function allows me to get the list of all the files from the directories I need.
# It differs from the util.ls function because it also filters out all the directories.
2024-04-28 21:24:49 +03:00
lsFiles = path : map ( f : " ${ path } / ${ f } " ) (
2024-04-15 11:28:52 +03:00
builtins . filter ( i : builtins . readFileType " ${ path } / ${ i } " == " r e g u l a r " ) (
builtins . attrNames ( builtins . readDir path )
)
) ;
2024-04-15 00:30:57 +03:00
in {
2024-05-04 23:15:57 +03:00
# Here I import everything from those directories.
2024-04-28 21:24:49 +03:00
imports = ( lsFiles ./module/common ) ++ ( lsFiles ./overlay ) ++ [ ./user/Root.nix ] ;
2024-04-15 00:30:57 +03:00
} ;
2024-03-04 00:34:39 +03:00
2024-05-04 23:15:57 +03:00
# Function to create a host. It does basic setup, like adding common modules.
2024-04-06 03:03:58 +03:00
mkHost = { system , hostname , modules } @ args : nixpkgs . lib . nixosSystem {
2024-05-04 23:15:57 +03:00
# `Inherit` is just an alias for `system = system;`, which means that
# keep the `system` argument as a property in a resulting set.
2024-03-04 00:34:39 +03:00
inherit system ;
2024-05-04 23:15:57 +03:00
# List of modules to use by defualt for all the hosts.
2024-03-04 00:34:39 +03:00
modules = [
2024-05-04 23:15:57 +03:00
# There I put host-specific configurations.
./host / $ { hostname }
# Make a device hostname match the one from this config.
2024-03-04 00:34:39 +03:00
{ networking . hostName = hostname ; }
2024-05-04 23:15:57 +03:00
# Specify current release version.
2024-04-15 00:41:40 +03:00
{ system . stateVersion = self . const . stateVersion ; }
2024-05-04 23:15:57 +03:00
# Add common modules.
2024-03-04 00:34:39 +03:00
inputs . self . nixosModules . common
2024-05-04 23:15:57 +03:00
# Add Home Manager module.
2024-03-04 00:34:39 +03:00
home-manager . nixosModules . home-manager
2024-05-04 23:15:57 +03:00
# Add Stylix module.
2024-04-03 00:23:03 +03:00
stylix . nixosModules . stylix
2024-05-04 23:15:57 +03:00
]
# Also add host-specific modules from mkHost args.
++ modules ;
2024-03-04 00:34:39 +03:00
2024-05-04 23:15:57 +03:00
# SpecialArgs allows you to pass objects down to other NixOS modules.
2024-04-06 03:03:58 +03:00
specialArgs = let
pkgs = nixpkgs . legacyPackages . ${ system } . pkgs ;
2024-05-12 02:40:37 +03:00
lib = nixpkgs . lib ;
2024-04-06 03:03:58 +03:00
config = self . nixosConfigurations . ${ hostname } . config ;
2024-06-09 23:35:53 +03:00
pkgsJobber = nixpkgsJobber . legacyPackages . ${ system } . pkgs ;
2024-06-20 22:13:59 +03:00
pkgsStable = nixpkgsJobber . legacyPackages . ${ system } . pkgs ;
pkgsMaster = nixpkgsJobber . legacyPackages . ${ system } . pkgs ;
2024-04-06 03:03:58 +03:00
in {
2024-05-04 23:15:57 +03:00
const = self . const ; # Constant values.
flake = self ; # This Flake itself.
inputs = inputs ; # Our dependencies.
secret = import ./part/Secret.nix { } ; # Secrets (public keys).
setting = import ./part/Setting.nix { } ; # My own global settings.
2024-05-12 02:40:37 +03:00
style = import ./part/Style.nix { inherit config ; } ; # Style abstraction.
util = import ./part/Util.nix { inherit pkgs lib ; } ; # Util functions.
wallpaper = import ./part/Wallpaper.nix { inherit pkgs ; } ; # Wallpaper.
2024-06-09 23:35:53 +03:00
2024-06-20 22:13:59 +03:00
# Stable and Master pkgs.
inherit pkgsStable pkgsMaster ;
2024-06-09 23:35:53 +03:00
# Stuff for Jobber container, skip this part.
inherit poetry2nixJobber pkgsJobber ;
2024-03-31 22:34:21 +03:00
} ;
2024-03-04 00:34:39 +03:00
} ;
2024-05-04 23:15:57 +03:00
# Bellow is the list of all the hosts I currently use.
# They call the `mkHost` function that I defined above
# with their specific parameters.
# You might be interested in `live` and `nixOnDroidConfiguration`
# for Live ISO and Android configurations respectively.
2024-04-10 14:52:37 +03:00
nixosConfigurations . basic = self . mkHost {
2024-05-04 23:15:57 +03:00
hostname = " b a s i c " ; # Hostname to use.
system = " x 8 6 _ 6 4 - l i n u x " ; # System architecture.
# Host-specific modules.
2024-04-10 14:52:37 +03:00
modules = [
2024-05-04 23:15:57 +03:00
# Force LTS kernel.
2024-04-10 14:52:37 +03:00
( { pkgs , . . . }: { boot . kernelPackages = nixpkgs . lib . mkForce pkgs . linuxPackages ; } )
] ;
} ;
2024-03-04 00:34:39 +03:00
nixosConfigurations . dasha = self . mkHost {
hostname = " d a s h a " ;
system = " x 8 6 _ 6 4 - l i n u x " ;
modules = [
./module/AmdGpu.nix
2024-05-04 23:15:57 +03:00
./module/CapsToggle.nix
2024-03-04 00:34:39 +03:00
./module/Gnome.nix
./module/IntelCpu.nix
./module/PowersaveIntel.nix
./module/Print.nix
2024-03-09 20:42:25 +03:00
./module/RemoteBuild.nix
2024-05-04 23:15:57 +03:00
./module/StrongSwan.nix
./module/Tablet.nix
2024-03-04 00:34:39 +03:00
./user/Dasha.nix
] ;
} ;
nixosConfigurations . desktop = self . mkHost {
hostname = " d e s k t o p " ;
system = " x 8 6 _ 6 4 - l i n u x " ;
modules = [
2024-03-20 22:54:40 +03:00
./module/AmdCompute.nix
2024-03-04 00:34:39 +03:00
./module/AmdCpu.nix
./module/AmdGpu.nix
2024-06-21 10:50:04 +03:00
./module/DockerRootless.nix
./module/Ollama.nix
2024-03-04 00:34:39 +03:00
./module/PowersaveAmd.nix
./module/Print.nix
2024-03-09 20:19:48 +03:00
./module/RemoteBuild.nix
2024-03-28 08:57:07 +03:00
./module/Sway.nix
2024-03-04 00:34:39 +03:00
./module/VirtManager.nix
./user/Voronind.nix
] ;
} ;
nixosConfigurations . fsight = self . mkHost {
hostname = " f s i g h t " ;
system = " x 8 6 _ 6 4 - l i n u x " ;
modules = [
./module/Docker.nix
] ;
} ;
nixosConfigurations . home = self . mkHost {
hostname = " h o m e " ;
system = " x 8 6 _ 6 4 - l i n u x " ;
modules = [
./module/AmdCpu.nix
./module/AmdGpu.nix
./module/Ftpd.nix
2024-03-09 20:19:48 +03:00
./module/RemoteBuilder.nix
2024-03-28 08:45:55 +03:00
./module/Sway.nix
2024-03-04 00:34:39 +03:00
./user/Voronind.nix
] ;
} ;
nixosConfigurations . laptop = self . mkHost {
hostname = " l a p t o p " ;
system = " x 8 6 _ 6 4 - l i n u x " ;
modules = [
./module/AmdCpu.nix
2024-03-04 21:19:30 +03:00
./module/AmdGpu.nix
2024-05-04 23:15:57 +03:00
./module/CapsToggle.nix
2024-03-04 00:34:39 +03:00
./module/Gnome.nix
./module/PowersaveAmd.nix
./module/Print.nix
2024-03-09 20:42:25 +03:00
./module/RemoteBuild.nix
2024-05-04 23:15:57 +03:00
./module/StrongSwan.nix
./module/Tablet.nix
2024-03-04 00:34:39 +03:00
./user/Dasha.nix
./user/Voronind.nix
] ;
} ;
2024-05-04 23:15:57 +03:00
# Live ISO configuration.
2024-03-04 00:34:39 +03:00
nixosConfigurations . live = self . mkHost {
hostname = " l i v e " ;
system = " x 8 6 _ 6 4 - l i n u x " ;
modules = [
2024-05-04 23:15:57 +03:00
# Those are basic modules for Live ISO image.
# You can discover other possible base images here:
# https://github.com/NixOS/nixpkgs/tree/master/nixos/modules/installer/cd-dvd
2024-03-04 00:34:39 +03:00
" ${ nixpkgs } / n i x o s / m o d u l e s / i n s t a l l e r / c d - d v d / i n s t a l l a t i o n - c d - m i n i m a l . n i x "
" ${ nixpkgs } / n i x o s / m o d u l e s / i n s t a l l e r / c d - d v d / c h a n n e l . n i x "
2024-05-04 23:15:57 +03:00
# This is required for Live ISO in my case because I use NetworkManager,
# but base Live images require this.
{ networking . wireless . enable = nixpkgs . lib . mkForce false ; }
# Override my settings to allow SSH logins using root password.
2024-03-10 08:04:23 +03:00
{ services . openssh . settings . PasswordAuthentication = nixpkgs . lib . mkForce true ; }
{ services . openssh . settings . PermitRootLogin = nixpkgs . lib . mkForce " y e s " ; }
2024-05-04 23:15:57 +03:00
# Disable auto-updates as they are not possible for Live ISO.
{ systemd . services . autoupdate . enable = nixpkgs . lib . mkForce false ; }
2024-06-18 10:35:42 +03:00
{ systemd . timers . autoupdate . enable = nixpkgs . lib . mkForce false ; }
2024-05-04 23:15:57 +03:00
# Base Live images also require the LTS kernel.
( { pkgs , . . . }: { boot . kernelPackages = nixpkgs . lib . mkForce pkgs . linuxPackages ; } )
2024-03-04 00:34:39 +03:00
] ;
} ;
nixosConfigurations . work = self . mkHost {
hostname = " w o r k " ;
system = " x 8 6 _ 6 4 - l i n u x " ;
modules = [
./module/IntelCpu.nix
2024-05-04 23:15:57 +03:00
./module/PowerlimitThinkpad.nix
2024-03-04 00:34:39 +03:00
./module/PowersaveIntel.nix
./module/Print.nix
2024-03-09 20:42:25 +03:00
./module/RemoteBuild.nix
2024-03-28 04:27:37 +03:00
./module/Sway.nix
2024-03-04 00:34:39 +03:00
./user/Voronind.nix
] ;
} ;
# Android.
nixOnDroidConfigurations . default = nix-on-droid . lib . nixOnDroidConfiguration {
modules = [
2024-05-04 23:15:57 +03:00
# Android release version.
2024-04-15 00:41:40 +03:00
{ system . stateVersion = inputs . self . const . droidStateVersion ; }
2024-05-04 23:15:57 +03:00
# I put all my Android configuration there.
2024-06-24 01:37:19 +03:00
./android
2024-03-04 00:34:39 +03:00
] ;
2024-04-06 03:03:58 +03:00
2024-05-04 23:15:57 +03:00
# SpecialArgs allows you to pass objects down to other configuration.
2024-04-06 03:03:58 +03:00
extraSpecialArgs = let
2024-05-04 23:15:57 +03:00
# We want arm64 packages for Android.
2024-04-06 03:03:58 +03:00
pkgs = nixpkgs . legacyPackages . " a a r c h 6 4 - l i n u x " . pkgs ;
2024-05-12 02:40:37 +03:00
lib = nixpkgs . lib ;
2024-04-06 03:03:58 +03:00
in {
2024-05-04 23:15:57 +03:00
const = self . const ; # Constant values.
flake = self ; # This Flake itself.
inputs = inputs ; # Our dependencies.
secret = import ./part/Secret.nix { } ; # Secrets (public keys).
setting = import ./part/Setting.nix { } ; # My own global settings.
style = import ./part/Style.nix { config = import ./part/style/Gruvbox.nix { } ; } ; # Style abstraction. Stylix is not available for Android so I provide static Gruvbox style.
2024-05-12 02:40:37 +03:00
util = import ./part/Util.nix { inherit pkgs lib ; } ; # Util functions.
2024-03-31 22:34:21 +03:00
} ;
2024-03-04 00:34:39 +03:00
} ;
} ;
}
2024-05-04 23:15:57 +03:00
# That's it!