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-27 02:14:33 +03:00
# I use this for a single container called jobber. WARN: Do not update.
2024-06-09 23:35:53 +03:00
# 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-06-30 03:56:48 +03:00
# Hack to use <container/Change.nix> in other files.
# Need to add __findFile to args tho.
__findFile = _ : p : . / $ { p } ;
# List all files in a dir.
2024-08-23 05:04:17 +03:00
findFiles = path : map ( f : " ${ path } / ${ f } " ) (
2024-06-30 03:56:48 +03:00
builtins . filter ( i : builtins . readFileType " ${ path } / ${ i } " == " r e g u l a r " ) (
builtins . attrNames ( builtins . readDir path )
)
) ;
2024-06-09 23:35:53 +03:00
2024-06-30 03:56:48 +03:00
nixosConfigurations = let
2024-06-25 04:04:39 +03:00
# Function to create a host. It does basic setup, like adding common modules.
mkHost = { system , hostname , modules } @ args : nixpkgs . lib . nixosSystem {
# `Inherit` is just an alias for `system = system;`, which means that
# keep the `system` argument as a property in a resulting set.
inherit system ;
# List of modules to use by defualt for all the hosts.
modules = modules ++ [
# There I put host-specific configurations.
2024-08-23 05:04:17 +03:00
./host / $ { system } / $ { hostname }
2024-06-25 04:04:39 +03:00
# Make a device hostname match the one from this config.
{ networking . hostName = hostname ; }
# Specify current release version.
{ system . stateVersion = self . const . stateVersion ; }
# Add modules.
{ imports =
2024-08-23 05:04:17 +03:00
( self . findFiles ./config ) ++
( self . findFiles ./container ) ++
( self . findFiles ./module ) ++
( self . findFiles ./overlay ) ++
2024-06-30 03:56:48 +03:00
[ ./home/NixOs.nix ] ;
2024-06-25 04:04:39 +03:00
}
# Add Home Manager module.
home-manager . nixosModules . home-manager
# Add Stylix module.
stylix . nixosModules . stylix
] ;
# SpecialArgs allows you to pass objects down to other NixOS modules.
specialArgs = let
pkgs = nixpkgs . legacyPackages . ${ system } . pkgs ;
lib = nixpkgs . lib ;
config = self . nixosConfigurations . ${ hostname } . config ;
2024-06-30 03:56:48 +03:00
in {
inherit inputs self ;
inherit ( self ) const __findFile ;
2024-06-25 04:04:39 +03:00
pkgsJobber = nixpkgsJobber . legacyPackages . ${ system } . pkgs ;
2024-06-30 03:56:48 +03:00
pkgsStable = nixpkgsStable . legacyPackages . ${ system } . pkgs ;
pkgsMaster = nixpkgsMaster . legacyPackages . ${ system } . pkgs ;
2024-06-25 04:04:39 +03:00
secret = import ./secret { } ; # Secrets (public keys).
container = import ./lib/Container.nix { inherit lib pkgs config ; inherit ( self ) const ; } ; # Container utils.
2024-06-26 11:23:36 +03:00
util = import ./lib/Util.nix { inherit lib ; } ; # Util functions.
2024-06-25 04:04:39 +03:00
# Stuff for Jobber container, skip this part.
2024-06-30 03:56:48 +03:00
inherit poetry2nixJobber ;
2024-06-25 04:04:39 +03:00
} ;
2024-03-31 22:34:21 +03:00
} ;
2024-03-04 00:34:39 +03:00
2024-06-25 04:04:39 +03:00
mkSystem = hostname : system : modules : {
" ${ hostname } " = mkHost {
inherit hostname system modules ;
} ;
} ;
2024-03-04 00:34:39 +03:00
2024-06-25 04:04:39 +03:00
x86System = hostname : mkSystem hostname " x 8 6 _ 6 4 - l i n u x " [ ] ;
2024-08-23 05:04:17 +03:00
in nixpkgs . lib . foldl' ( acc : h : acc // h ) { } (
map ( host : x86System host ) ( builtins . attrNames ( builtins . readDir ./host/x86_64-linux ) )
) ;
2024-03-04 00:34:39 +03:00
2024-06-30 03:56:48 +03:00
# Home manager (distro-independent).
# Install nix: sh <(curl -L https://nixos.org/nix/install) --no-daemon
# Or with --daemon for multi-user (as root).
# $ nix run home-manager/master -- init --switch
# $ nix shell '<home-manager>' -A install
# Add to /etc/nix/nix.conf > experimental-features = nix-command flakes
# And then # systemctl restart nix-daemon.service
# $ home-manager switch --flake ~/hmconf
homeConfigurations = let
lib = nixpkgs . lib ;
secret = import ./secret { } ;
util = import ./lib/Util.nix { inherit lib ; } ;
mkCommonHome = username : homeDirectory : system : modules : let
pkgs = nixpkgs . legacyPackages . ${ system } ;
pkgsStable = nixpkgsStable . legacyPackages . ${ system } ;
pkgsMaster = nixpkgsMaster . legacyPackages . ${ system } ;
in {
$ { username } = home-manager . lib . homeManagerConfiguration {
inherit pkgs ;
extraSpecialArgs = {
inherit self inputs secret util pkgs pkgsStable pkgsMaster ;
inherit ( self ) const __findFile ;
} ;
2024-08-23 05:04:17 +03:00
modules = modules ++ ( self . findFiles ./config ) ++ [
2024-06-30 03:56:48 +03:00
./home/HomeManager.nix
{ home . hm . enable = true ; }
{ home . hm . username = username ; }
{ home . hm . homeDirectory = homeDirectory ; }
{ home . hm . packages . core . enable = true ; }
{ nixpkgs . config . allowUnfree = true ; }
{ nixpkgs . config . allowUnfreePredicate = ( pkg : true ) ; }
{ nix . package = pkgs . nix ; }
{ nix . settings . experimental-features = [ " n i x - c o m m a n d " " f l a k e s " ] ; }
inputs . stylix . homeManagerModules . stylix
] ;
} ;
} ;
x86LinuxHome = username : modules : mkCommonHome username " / h o m e / ${ username } " " x 8 6 _ 6 4 - l i n u x " modules ;
x86LinuxRoot = mkCommonHome " r o o t " " / r o o t " " x 8 6 _ 6 4 - l i n u x " [ ] ;
in nixpkgs . lib . foldl' ( acc : h : acc // h ) { } [
x86LinuxRoot
( x86LinuxHome " v o r o n i n d " [
2024-08-23 05:04:17 +03:00
{ home . hm . package . core . enable = true ; }
{ home . hm . package . common . enable = true ; }
2024-06-30 03:56:48 +03:00
] )
] ;
2024-03-04 00:34:39 +03:00
# Android.
2024-07-01 16:19:58 +03:00
nixOnDroidConfigurations . default = let
config = self . nixOnDroidConfigurations . default . config ;
lib = nixpkgs . lib ;
pkgs = nixpkgs . legacyPackages . " a a r c h 6 4 - l i n u x " . pkgs ;
in nix-on-droid . lib . nixOnDroidConfiguration {
modules = [
2024-05-04 23:15:57 +03:00
# Android release version.
2024-06-29 19:01:12 +03:00
{ system . stateVersion = self . const . droidStateVersion ; }
2024-05-04 23:15:57 +03:00
2024-06-24 20:30:33 +03:00
# I put all my Android configuration there.
2024-06-30 03:56:48 +03:00
./home/Android.nix
{ home . android . enable = true ; }
# { nixpkgs.config.allowUnfree = true; }
# { nixpkgs.config.allowUnfreePredicate = (pkg: true); }
{ nix . extraOptions = " e x p e r i m e n t a l - f e a t u r e s = n i x - c o m m a n d f l a k e s " ; }
{ home-manager . config . stylix . autoEnable = lib . mkForce false ; }
2024-06-29 18:05:39 +03:00
2024-06-29 23:44:54 +03:00
# Some common modules.
2024-06-30 03:56:48 +03:00
./config/Setting.nix
./config/Wallpaper.nix
2024-07-01 16:19:58 +03:00
( import ./config/Style.nix {
inherit ( config . home-manager ) config ;
inherit ( self ) __findFile ;
inherit lib pkgs ;
} )
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-07-01 16:19:58 +03:00
extraSpecialArgs = {
2024-06-30 03:56:48 +03:00
inherit inputs self ;
inherit ( self ) const __findFile ;
2024-06-29 18:05:39 +03:00
2024-06-30 03:56:48 +03:00
secret = import ./secret { } ; # Secrets (public keys).
util = import ./lib/Util.nix { inherit 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!