mirror of
https://github.com/ryan4yin/nix-config.git
synced 2026-04-23 09:18:35 +02:00
feat: simplify flake.nix
This commit is contained in:
345
flake.nix
345
flake.nix
@@ -2,15 +2,15 @@
|
||||
description = "NixOS & macOS configuration of Ryan Yin";
|
||||
|
||||
##################################################################################################################
|
||||
#
|
||||
#
|
||||
# Want to know Nix in details? Looking for a beginner-friendly tutorial?
|
||||
# Check out https://github.com/ryan4yin/nixos-and-flakes-book !
|
||||
#
|
||||
#
|
||||
##################################################################################################################
|
||||
|
||||
# the nixConfig here only affects the flake itself, not the system configuration!
|
||||
nixConfig = {
|
||||
experimental-features = [ "nix-command" "flakes" ];
|
||||
experimental-features = ["nix-command" "flakes"];
|
||||
|
||||
substituters = [
|
||||
# replace official cache with a mirror located in China
|
||||
@@ -30,7 +30,6 @@
|
||||
];
|
||||
};
|
||||
|
||||
|
||||
# This is the standard format for flake.nix. `inputs` are the dependencies of the flake,
|
||||
# Each item in `inputs` will be passed as a parameter to the `outputs` function after being pulled and built.
|
||||
inputs = {
|
||||
@@ -43,7 +42,7 @@
|
||||
|
||||
# for macos
|
||||
nixpkgs-darwin.url = "github:nixos/nixpkgs/nixpkgs-23.05-darwin";
|
||||
darwin = {
|
||||
nix-darwin = {
|
||||
url = "github:lnl7/nix-darwin";
|
||||
inputs.nixpkgs.follows = "nixpkgs-darwin";
|
||||
};
|
||||
@@ -58,7 +57,7 @@
|
||||
};
|
||||
|
||||
# modern window compositor
|
||||
hyprland.url = "github:hyprwm/Hyprland/v0.27.0";
|
||||
hyprland.url = "github:hyprwm/Hyprland/v0.27.2";
|
||||
# community wayland nixpkgs
|
||||
nixpkgs-wayland.url = "github:nix-community/nixpkgs-wayland";
|
||||
|
||||
@@ -72,216 +71,156 @@
|
||||
agenix.url = "github:ryantm/agenix/0d8c5325fc81daf00532e3e26c6752f7bcde1143";
|
||||
|
||||
# AstroNvim is an aesthetic and feature-rich neovim config.
|
||||
astronvim = { url = "github:AstroNvim/AstroNvim/v3.33.3"; flake = false; };
|
||||
astronvim = {
|
||||
url = "github:AstroNvim/AstroNvim/v3.33.3";
|
||||
flake = false;
|
||||
};
|
||||
|
||||
# my private secrets, it's a private repository, you need to replace it with your own.
|
||||
# use ssh protocol to authenticate via ssh-agent/ssh-key, and shallow clone to save time
|
||||
mysecrets = { url = "git+ssh://git@github.com/ryan4yin/nix-secrets.git?shallow=1"; flake = false; };
|
||||
mysecrets = {
|
||||
url = "git+ssh://git@github.com/ryan4yin/nix-secrets.git?shallow=1";
|
||||
flake = false;
|
||||
};
|
||||
};
|
||||
|
||||
# The `outputs` function will return all the build results of the flake.
|
||||
# The `outputs` function will return all the build results of the flake.
|
||||
# A flake can have many use cases and different types of outputs,
|
||||
# parameters in `outputs` are defined in `inputs` and can be referenced by their names.
|
||||
# parameters in `outputs` are defined in `inputs` and can be referenced by their names.
|
||||
# However, `self` is an exception, this special parameter points to the `outputs` itself (self-reference)
|
||||
# The `@` syntax here is used to alias the attribute set of the inputs's parameter, making it convenient to use inside the function.
|
||||
outputs =
|
||||
inputs@{ self
|
||||
, nixpkgs
|
||||
, darwin
|
||||
, home-manager
|
||||
, nixos-generators
|
||||
, ...
|
||||
}:
|
||||
|
||||
let
|
||||
x64_system = "x86_64-linux";
|
||||
x64_specialArgs = {
|
||||
# use unstable branch for some packages to get the latest updates
|
||||
pkgs-unstable = import inputs.nixpkgs-unstable {
|
||||
system = x64_system; # refer the `system` parameter form outer scope recursively
|
||||
# To use chrome, we need to allow the installation of non-free software
|
||||
config.allowUnfree = true;
|
||||
};
|
||||
} // inputs;
|
||||
# 星野 アイ, Hoshino Ai
|
||||
idol_ai_modules_i3 = [
|
||||
outputs = inputs @ {
|
||||
self,
|
||||
nixpkgs,
|
||||
nixpkgs-unstable,
|
||||
nix-darwin,
|
||||
home-manager,
|
||||
nixos-generators,
|
||||
...
|
||||
}: let
|
||||
username = "ryan";
|
||||
x64_system = "x86_64-linux";
|
||||
x64_darwin = "x86_64-darwin";
|
||||
allSystems = [x64_system x64_darwin];
|
||||
|
||||
nixosSystem = import ./lib/nixosSystem.nix;
|
||||
macosSystem = import ./lib/macosSystem.nix;
|
||||
|
||||
# 星野 アイ, Hoshino Ai
|
||||
idol_ai_modules_i3 = {
|
||||
nixos-modules = [
|
||||
./hosts/idols/ai
|
||||
./modules/nixos/i3.nix
|
||||
|
||||
home-manager.nixosModules.home-manager
|
||||
{
|
||||
home-manager.useGlobalPkgs = true;
|
||||
home-manager.useUserPackages = true;
|
||||
|
||||
home-manager.extraSpecialArgs = x64_specialArgs;
|
||||
home-manager.users.ryan = import ./home/linux/desktop-i3.nix;
|
||||
}
|
||||
];
|
||||
idol_ai_modules_hyprland = [
|
||||
home-module = import ./home/linux/desktop-i3.nix;
|
||||
};
|
||||
idol_ai_modules_hyprland = {
|
||||
nixos-modules = [
|
||||
./hosts/idols/ai
|
||||
./modules/nixos/hyprland.nix
|
||||
|
||||
home-manager.nixosModules.home-manager
|
||||
{
|
||||
home-manager.useGlobalPkgs = true;
|
||||
home-manager.useUserPackages = true;
|
||||
|
||||
home-manager.extraSpecialArgs = x64_specialArgs;
|
||||
home-manager.users.ryan = import ./home/linux/desktop-hyprland.nix;
|
||||
}
|
||||
];
|
||||
# 星野 愛久愛海, Hoshino Akuamarin
|
||||
idol_aquamarine_modules = [
|
||||
./hosts/idols/aquamarine
|
||||
|
||||
home-manager.nixosModules.home-manager
|
||||
{
|
||||
home-manager.useGlobalPkgs = true;
|
||||
home-manager.useUserPackages = true;
|
||||
|
||||
home-manager.extraSpecialArgs = x64_specialArgs;
|
||||
home-manager.users.ryan = import ./home/linux/server.nix;
|
||||
}
|
||||
];
|
||||
# 星野 瑠美衣, Hoshino Rubii
|
||||
idol_ruby_modules = [
|
||||
./hosts/idols/ruby
|
||||
|
||||
home-manager.nixosModules.home-manager
|
||||
{
|
||||
home-manager.useGlobalPkgs = true;
|
||||
home-manager.useUserPackages = true;
|
||||
|
||||
home-manager.extraSpecialArgs = x64_specialArgs;
|
||||
home-manager.users.ryan = import ./home/linux/server.nix;
|
||||
}
|
||||
];
|
||||
# 有馬 かな, Arima Kana
|
||||
idol_kana_modules = [
|
||||
./hosts/idols/kana
|
||||
|
||||
home-manager.nixosModules.home-manager
|
||||
{
|
||||
home-manager.useGlobalPkgs = true;
|
||||
home-manager.useUserPackages = true;
|
||||
|
||||
home-manager.extraSpecialArgs = x64_specialArgs;
|
||||
home-manager.users.ryan = import ./home/linux/server.nix;
|
||||
}
|
||||
];
|
||||
in {
|
||||
nixosConfigurations = let system = x64_system; specialArgs = x64_specialArgs; in {
|
||||
ai_i3 = nixpkgs.lib.nixosSystem { # ai with i3 window manager
|
||||
inherit system specialArgs;
|
||||
modules = idol_ai_modules_i3;
|
||||
};
|
||||
ai_hyprland = nixpkgs.lib.nixosSystem { # ai with hyprland compositor
|
||||
inherit system specialArgs;
|
||||
modules = idol_ai_modules_hyprland;
|
||||
};
|
||||
|
||||
aquamarine = nixpkgs.lib.nixosSystem {
|
||||
inherit system specialArgs;
|
||||
modules = idol_aquamarine_modules;
|
||||
};
|
||||
|
||||
ruby = nixpkgs.lib.nixosSystem {
|
||||
inherit system specialArgs;
|
||||
modules = idol_ruby_modules;
|
||||
};
|
||||
|
||||
kana = nixpkgs.lib.nixosSystem {
|
||||
inherit system specialArgs;
|
||||
modules = idol_kana_modules;
|
||||
};
|
||||
};
|
||||
|
||||
# macOS's configuration, for work.
|
||||
darwinConfigurations."harmonica" = let
|
||||
system = "x86_64-darwin";
|
||||
specialArgs = {
|
||||
# use unstable branch for some packages to get the latest updates
|
||||
pkgs-unstable = import inputs.nixpkgs-unstable {
|
||||
inherit system; # refer the `system` parameter form outer scope recursively
|
||||
# To use chrome, we need to allow the installation of non-free software
|
||||
config.allowUnfree = true;
|
||||
};
|
||||
} // inputs;
|
||||
in
|
||||
darwin.lib.darwinSystem {
|
||||
inherit system specialArgs;
|
||||
modules = [
|
||||
./hosts/harmonica
|
||||
|
||||
home-manager.darwinModules.home-manager
|
||||
{
|
||||
home-manager.useGlobalPkgs = true;
|
||||
home-manager.useUserPackages = true;
|
||||
|
||||
home-manager.extraSpecialArgs = specialArgs;
|
||||
home-manager.users.ryan = import ./home/darwin;
|
||||
}
|
||||
];
|
||||
};
|
||||
|
||||
formatter = {
|
||||
# format the nix code in this flake
|
||||
# alejandra is a nix formatter with a beautiful output
|
||||
x86_64-linux = nixpkgs.legacyPackages.x86_64-linux.alejandra;
|
||||
x86_64-darwin = nixpkgs.legacyPackages.x86_64-darwin.alejandra;
|
||||
};
|
||||
|
||||
packages.x86_64-linux =
|
||||
# take images for idols
|
||||
# https://github.com/nix-community/nixos-generators
|
||||
let system = x64_system; specialArgs = x64_specialArgs; in {
|
||||
# Hoshino Ai is a physical machine, so we need to generate an iso image for it.
|
||||
ai_i3 = nixos-generators.nixosGenerate { # ai with i3 window manager
|
||||
inherit system specialArgs;
|
||||
modules = idol_ai_modules_i3;
|
||||
format = "iso";
|
||||
};
|
||||
ai_hyprland = nixos-generators.nixosGenerate { # ai with hyprland compositor
|
||||
inherit system specialArgs;
|
||||
modules = idol_ai_modules_hyprland;
|
||||
format = "iso";
|
||||
};
|
||||
# Hoshino Aquamarine is a virtual machine running on Proxmox VE.
|
||||
aquamarine = nixos-generators.nixosGenerate {
|
||||
inherit system specialArgs;
|
||||
modules = idol_aquamarine_modules ++ [
|
||||
({config, ...}: {
|
||||
proxmox.qemuConf.name = "aquamarine-nixos-${config.system.nixos.label}";
|
||||
})
|
||||
];
|
||||
|
||||
# proxmox's configuration:
|
||||
# https://github.com/NixOS/nixpkgs/blob/nixos-unstable/nixos/modules/virtualisation/proxmox-image.nix
|
||||
#
|
||||
# after resize the disk, it will grow partition automatically.
|
||||
# and it alse had qemu-guest-agent installed by default.
|
||||
format = "proxmox";
|
||||
};
|
||||
# Hoshino Rubii is a vm too.
|
||||
ruby = nixos-generators.nixosGenerate {
|
||||
inherit system specialArgs;
|
||||
modules = idol_ruby_modules ++ [
|
||||
({config, ...}: {
|
||||
proxmox.qemuConf.name = "ruby-nixos-${config.system.nixos.label}";
|
||||
})
|
||||
];
|
||||
format = "proxmox";
|
||||
};
|
||||
# Kana is a vm too.
|
||||
kana = nixos-generators.nixosGenerate {
|
||||
inherit system specialArgs;
|
||||
modules = idol_kana_modules ++ [
|
||||
({config, ...}: {
|
||||
proxmox.qemuConf.name = "kana-nixos-${config.system.nixos.label}";
|
||||
})
|
||||
];
|
||||
format = "proxmox";
|
||||
};
|
||||
};
|
||||
home-module = import ./home/linux/desktop-hyprland.nix;
|
||||
};
|
||||
|
||||
# 星野 愛久愛海, Hoshino Akuamarin
|
||||
idol_aquamarine_modules = {
|
||||
nixos-modules = [
|
||||
./hosts/idols/aquamarine
|
||||
];
|
||||
home-module = import ./home/linux/server.nix;
|
||||
};
|
||||
|
||||
# 星野 瑠美衣, Hoshino Rubii
|
||||
idol_ruby_modules = {
|
||||
nixos-modules = [
|
||||
./hosts/idols/ruby
|
||||
];
|
||||
home-module = import ./home/linux/server.nix;
|
||||
};
|
||||
|
||||
# 有馬 かな, Arima Kana
|
||||
idol_kana_modules = {
|
||||
nixos-modules = [
|
||||
./hosts/idols/kana
|
||||
];
|
||||
home-module = import ./home/linux/server.nix;
|
||||
};
|
||||
in {
|
||||
nixosConfigurations = let
|
||||
system = x64_system;
|
||||
specialArgs =
|
||||
{
|
||||
inherit username;
|
||||
# use unstable branch for some packages to get the latest updates
|
||||
pkgs-unstable = import nixpkgs-unstable {
|
||||
system = x64_system; # refer the `system` parameter form outer scope recursively
|
||||
# To use chrome, we need to allow the installation of non-free software
|
||||
config.allowUnfree = true;
|
||||
};
|
||||
}
|
||||
// inputs;
|
||||
base_args = {
|
||||
inherit home-manager nixos-generators system specialArgs;
|
||||
};
|
||||
stable_args = base_args // {inherit nixpkgs;};
|
||||
unstable_args = base_args // {nixpkgs = nixpkgs-unstable;};
|
||||
in {
|
||||
# ai with i3 window manager
|
||||
ai_i3 = nixosSystem (idol_ai_modules_i3 // stable_args);
|
||||
# ai with hyprland compositor
|
||||
ai_hyprland = nixosSystem (idol_ai_modules_hyprland // stable_args);
|
||||
|
||||
aquamarine = nixosSystem (idol_aquamarine_modules // unstable_args);
|
||||
ruby = nixosSystem (idol_ruby_modules // unstable_args);
|
||||
kana = nixosSystem (idol_kana_modules // unstable_args);
|
||||
};
|
||||
|
||||
# take images for idols
|
||||
# https://github.com/nix-community/nixos-generators
|
||||
packages."${x64_system}" =
|
||||
nixpkgs.lib.genAttrs [
|
||||
"ai_i3"
|
||||
"ai_hyprland"
|
||||
] (
|
||||
host:
|
||||
self.nixosConfigurations.${host}.config.formats.iso
|
||||
)
|
||||
// nixpkgs.lib.genAttrs [
|
||||
"aquamarine"
|
||||
"ruby"
|
||||
"kana"
|
||||
] (
|
||||
host:
|
||||
self.nixosConfigurations.${host}.config.formats.proxmox
|
||||
);
|
||||
|
||||
# macOS's configuration, for work.
|
||||
darwinConfigurations."harmonica" = let
|
||||
system = x64_darwin;
|
||||
specialArgs =
|
||||
{
|
||||
# use unstable branch for some packages to get the latest updates
|
||||
pkgs-unstable = import nixpkgs-unstable {
|
||||
inherit system; # refer the `system` parameter form outer scope recursively
|
||||
# To use chrome, we need to allow the installation of non-free software
|
||||
config.allowUnfree = true;
|
||||
};
|
||||
}
|
||||
// inputs;
|
||||
in
|
||||
macosSystem {
|
||||
inherit nix-darwin home-manager system specialArgs;
|
||||
darwin-modules = [
|
||||
./hosts/harmonica
|
||||
];
|
||||
home-module = import ./home/darwin;
|
||||
};
|
||||
|
||||
# format the nix code in this flake
|
||||
# alejandra is a nix formatter with a beautiful output
|
||||
formatter = nixpkgs.lib.genAttrs allSystems (
|
||||
system:
|
||||
nixpkgs.legacyPackages.${system}.alejandra
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user