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-10-11 23:27:07 +03:00
# Those are external dependencies.
inputs = {
# 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
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 " ;
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 " ;
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 " ;
# 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
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 " ;
# This means that home-manager and our Flake both depend on the same nixpkgs version.
inputs . nixpkgs . follows = " n i x p k g s " ;
} ;
# 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 " ;
# I use this for a single container called jobber. WARN: Do not update.
# 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 " ;
# 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
nix-on-droid = {
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 " ;
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 " ;
} ;
# 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).
nvimAlign = {
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 " ;
flake = false ;
} ;
nvimAutoclose = {
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 " ;
flake = false ;
} ;
nvimBufferline = {
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 " ;
flake = false ;
} ;
nvimCloseBuffers = {
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 " ;
flake = false ;
} ;
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 ;
} ;
nvimDevicons = {
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 " ;
flake = false ;
} ;
nvimGitsigns = {
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 " ;
flake = false ;
} ;
nvimGruvboxMaterial = {
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 " ;
flake = false ;
} ;
nvimIndentoMatic = {
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 " ;
flake = false ;
} ;
nvimLspconfig = {
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 " ;
flake = false ;
} ;
2024-10-23 19:21:14 +03:00
nvimOllama = {
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 " ;
flake = false ;
} ;
2024-10-11 23:27:07 +03:00
nvimPlenary = {
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 " ;
flake = false ;
} ;
nvimTelescope = {
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 " ;
flake = false ;
} ;
nvimTodo = {
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 " ;
flake = false ;
} ;
nvimTree = {
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 " ;
flake = false ;
} ;
nvimTreesitter = {
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 " ;
flake = false ;
} ;
nvimTrouble = {
url = " g i t h u b : f o l k e / t r o u b l e . n v i m " ;
flake = false ;
} ;
} ;
# 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.
outputs =
{
self ,
nixpkgs ,
nixpkgsStable ,
nixpkgsMaster ,
nix-on-droid ,
home-manager ,
stylix ,
poetry2nixJobber ,
nixpkgsJobber ,
. . .
} @ inputs :
{
# Constant values.
const = {
droidStateVersion = " 2 3 . 1 1 " ;
stateVersion = " 2 4 . 0 5 " ;
timeZone = " E u r o p e / M o s c o w " ;
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 . g i t " ;
} ;
# 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.
findFiles =
path :
map ( f : " ${ path } / ${ f } " ) (
builtins . filter ( i : builtins . readFileType " ${ path } / ${ i } " == " r e g u l a r " ) (
builtins . attrNames ( builtins . readDir path )
)
) ;
# Dev shell for this repo.
devShells =
let
system = " x 8 6 _ 6 4 - l i n u x " ;
lib = nixpkgs . lib ;
pkgs = nixpkgs . legacyPackages . ${ system } ;
in
{
$ { system } . default = pkgs . mkShell {
nativeBuildInputs = with pkgs ; [
nixd
nixfmt-rfc-style
treefmt
] ;
# buildInputs = with pkgs; [ ];
# LD_LIBRARY_PATH = "${lib.makeLibraryPath buildInputs}";
# SOURCE_DATE_EPOCH = "${toString self.lastModified}";
} ;
} ;
# Nixos systems.
nixosConfigurations =
let
# Function to create a host. It does basic setup, like adding common modules.
mkHost =
{ system , hostname }:
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 =
[
# Make a device hostname match the one from this config.
{ networking . hostName = hostname ; }
# Specify current release version.
{ system . stateVersion = self . const . stateVersion ; }
# Add Home Manager module.
home-manager . nixosModules . home-manager
# Add Stylix module.
stylix . nixosModules . stylix
# HM config.
./home/NixOs.nix
]
++ ( self . findFiles ./host / $ { system } / $ { hostname } )
++ ( self . findFiles ./config )
++ ( self . findFiles ./container )
++ ( self . findFiles ./module )
++ ( self . findFiles ./system )
++ ( self . findFiles ./overlay ) ;
# 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 ;
in
{
inherit inputs self ;
inherit ( self ) const __findFile ;
pkgsJobber = nixpkgsJobber . legacyPackages . ${ system } . pkgs ;
pkgsStable = nixpkgsStable . legacyPackages . ${ system } . pkgs ;
pkgsMaster = nixpkgsMaster . legacyPackages . ${ system } . pkgs ;
secret = import ./secret { } ; # Secrets (public keys).
container = import ./lib/Container.nix {
inherit lib pkgs config ;
inherit ( self ) const ;
} ; # Container utils.
util = import ./lib/Util.nix { inherit lib ; } ; # Util functions.
# Stuff for Jobber container, skip this part.
inherit poetry2nixJobber ;
} ;
} ;
2024-10-14 04:51:19 +03:00
mkSystem = system : hostname : { " ${ hostname } " = mkHost { inherit system hostname ; } ; } ;
2024-10-11 23:27:07 +03:00
in
nixpkgs . lib . foldl' ( acc : h : acc // h ) { } (
map (
system :
nixpkgs . lib . foldl' ( acc : h : acc // h ) { } (
map ( host : mkSystem system host ) ( builtins . attrNames ( builtins . readDir ./host / $ { system } ) )
)
) ( builtins . attrNames ( builtins . readDir ./host ) )
) ;
# 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 ;
} ;
modules = [
./home/HomeManager.nix
{
home . hm = {
inherit username homeDirectory ;
enable = true ;
package = {
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
] ++ modules ++ ( self . findFiles ./config ) ;
} ;
} ;
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 " [
{
home . hm . package = {
common . enable = true ;
} ;
}
] )
] ;
# Android.
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 = [
# Android release version.
{ system . stateVersion = self . const . droidStateVersion ; }
# I put all my Android configuration there.
./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 ; }
# Some common modules.
./config/Setting.nix
./config/Wallpaper.nix
( import ./config/Style.nix {
inherit ( config . home-manager ) config ;
inherit ( self ) __findFile ;
inherit lib pkgs ;
} )
] ;
# SpecialArgs allows you to pass objects down to other configuration.
extraSpecialArgs = {
inherit inputs self ;
inherit ( self ) const __findFile ;
secret = import ./secret { } ; # Secrets (public keys).
util = import ./lib/Util.nix { inherit lib ; } ; # Util functions.
} ;
} ;
} ;
2024-03-04 00:34:39 +03:00
}
2024-05-04 23:15:57 +03:00
# That's it!