mirror of
https://github.com/ryan4yin/nix-config.git
synced 2026-04-23 01:08:32 +02:00
feat: add distributed-builds & many hosts
feat: remove nur & devenv feat: adjust the structure to make it suitable for servers feat: add iso/proxmox generators and add docs about it feat: update ryan's openssh keys & add hashedPassword feat: add proxmox's nodes into ssh_config, with alias
This commit is contained in:
237
flake.nix
237
flake.nix
@@ -1,5 +1,12 @@
|
||||
{
|
||||
description = "NixOS configuration of Ryan Yin";
|
||||
description = "NixOS & macOS configuration of Ryan Yin";
|
||||
|
||||
##################################################################################################################
|
||||
#
|
||||
# Want to know Nix in details? Looking for a beginner-friendly tutorial?
|
||||
# Check out [NixOS & Nix Flakes - A Guide for Beginners](https://thiscute.world/en/posts/nixos-and-flake-basics/)!
|
||||
#
|
||||
##################################################################################################################
|
||||
|
||||
# the nixConfig here only affects the flake itself, not the system configuration!
|
||||
nixConfig = {
|
||||
@@ -16,19 +23,16 @@
|
||||
extra-substituters = [
|
||||
"https://nix-community.cachix.org"
|
||||
"https://nixpkgs-wayland.cachix.org"
|
||||
"https://xddxdd.cachix.org"
|
||||
];
|
||||
extra-trusted-public-keys = [
|
||||
"cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY="
|
||||
"nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs="
|
||||
"nixpkgs-wayland.cachix.org-1:3lwxaILxMRkVhehr5StQprHdEo4IrE8sRho9R9HOLYA="
|
||||
"xddxdd.cachix.org-1:ay1HJyNDYmlSwj5NXQG065C8LfoqqKaTNCyzeixGjf8="
|
||||
];
|
||||
};
|
||||
|
||||
|
||||
# This is the standard format for flake.nix. `inputs` are the dependencies of the flake,
|
||||
# and `outputs` function will return all the build results of the flake.
|
||||
# Each item in `inputs` will be passed as a parameter to the `outputs` function after being pulled and built.
|
||||
inputs = {
|
||||
# There are many ways to reference flake inputs. The most widely used is github:owner/name/reference,
|
||||
@@ -45,11 +49,6 @@
|
||||
inputs.nixpkgs.follows = "nixpkgs-darwin";
|
||||
};
|
||||
|
||||
# nix users repository
|
||||
# used to install some packages not in nixpkgs
|
||||
# e.g. wechat-uos/qqmusic/dingtalk
|
||||
nur.url = "github:nix-community/NUR";
|
||||
|
||||
# home-manager, used for managing user configuration
|
||||
home-manager = {
|
||||
url = "github:nix-community/home-manager/release-23.05";
|
||||
@@ -70,9 +69,6 @@
|
||||
inputs.nixpkgs.follows = "nixpkgs";
|
||||
};
|
||||
|
||||
# use devenv to manage my development environment
|
||||
devenv.url = "github:cachix/devenv/v0.6.2";
|
||||
|
||||
# secrets management, lock with git commit at 2023/5/15
|
||||
agenix.url = "github:ryantm/agenix/db5637d10f797bb251b94ef9040b237f4702cde3";
|
||||
|
||||
@@ -80,91 +76,104 @@
|
||||
nil.url = "github:oxalica/nil/2023-05-09";
|
||||
};
|
||||
|
||||
# `outputs` are all the build result of the flake.
|
||||
# A flake can have many use cases and different types of outputs.
|
||||
# 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.
|
||||
# However, `self` is an exception, This special parameter points to the `outputs` itself (self-reference)
|
||||
# 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
|
||||
, ...
|
||||
}: {
|
||||
nixosConfigurations = {
|
||||
# By default, NixOS will try to refer the nixosConfiguration with its hostname.
|
||||
# so the system named `msi-rtx4090` will use this configuration.
|
||||
# However, the configuration name can also be specified using `sudo nixos-rebuild switch --flake /path/to/flakes/directory#<name>`.
|
||||
# The `nixpkgs.lib.nixosSystem` function is used to build this configuration, the following attribute set is its parameter.
|
||||
# Run `sudo nixos-rebuild switch --flake .#msi-rtx4090` in the flake's directory to deploy this configuration on any NixOS system
|
||||
msi-rtx4090 = nixpkgs.lib.nixosSystem rec {
|
||||
system = "x86_64-linux";
|
||||
}:
|
||||
|
||||
let
|
||||
x64_system = "x86_64-linux";
|
||||
x64_specialArgs = {
|
||||
pkgs-stable = import inputs.nixpkgs-stable {
|
||||
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;
|
||||
ai_modules = [
|
||||
./hosts/idols/ai
|
||||
|
||||
# The Nix module system can modularize configurations, improving the maintainability of configurations.
|
||||
#
|
||||
# Each parameter in the `modules` is a Nix Module, and there is a partial introduction to it in the nixpkgs manual:
|
||||
# <https://nixos.org/manual/nixpkgs/unstable/#module-system-introduction>
|
||||
# It is said to be partial because the documentation is not complete, only some simple introductions
|
||||
# (such is the current state of Nix documentation...)
|
||||
# A Nix Module can be an attribute set, or a function that returns an attribute set.
|
||||
# If a Module is a function, according to the Nix Wiki description, this function can have up to four parameters:
|
||||
#
|
||||
# config: The configuration of the entire system
|
||||
# options: All option declarations refined with all definition and declaration references.
|
||||
# pkgs: The attribute set extracted from the Nix package collection and enhanced with the nixpkgs.config option.
|
||||
# modulesPath: The location of the module directory of Nix.
|
||||
#
|
||||
# Only these four parameters can be passed by default.
|
||||
# If you need to pass other parameters, you must use `specialArgs` by uncomment the following line
|
||||
specialArgs = {
|
||||
pkgs-stable = import inputs.nixpkgs-stable {
|
||||
system = 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;
|
||||
modules = [
|
||||
./hosts/msi-rtx4090
|
||||
home-manager.nixosModules.home-manager
|
||||
{
|
||||
home-manager.useGlobalPkgs = true;
|
||||
home-manager.useUserPackages = true;
|
||||
|
||||
# make home-manager as a module of nixos
|
||||
# so that home-manager configuration will be deployed automatically when executing `nixos-rebuild switch`
|
||||
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/x11.nix;
|
||||
}
|
||||
];
|
||||
aquamarine_modules = [
|
||||
./hosts/idols/aquamarine
|
||||
|
||||
# pass all inputs into home manager's all sub modules
|
||||
home-manager.extraSpecialArgs = specialArgs;
|
||||
home-manager.users.ryan = import ./home/linux/x11.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/server.nix;
|
||||
}
|
||||
];
|
||||
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;
|
||||
}
|
||||
];
|
||||
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 {
|
||||
# 星野 アイ, Hoshino Ai
|
||||
ai = nixpkgs.lib.nixosSystem {
|
||||
inherit system specialArgs;
|
||||
modules = ai_modules;
|
||||
};
|
||||
|
||||
nixos-test = nixpkgs.lib.nixosSystem rec {
|
||||
system = "x86_64-linux";
|
||||
specialArgs = {
|
||||
pkgs-stable = import inputs.nixpkgs-stable {
|
||||
system = system;
|
||||
config.allowUnfree = true;
|
||||
};
|
||||
} // inputs;
|
||||
modules = [
|
||||
./hosts/nixos-test
|
||||
# 星野 愛久愛海, Hoshino Aquamarine
|
||||
aquamarine = nixpkgs.lib.nixosSystem {
|
||||
inherit system specialArgs;
|
||||
modules = aquamarine_modules;
|
||||
};
|
||||
|
||||
home-manager.nixosModules.home-manager
|
||||
{
|
||||
home-manager.useGlobalPkgs = true;
|
||||
home-manager.useUserPackages = true;
|
||||
# 星野 瑠美衣, Hoshino Rubii
|
||||
ruby = nixpkgs.lib.nixosSystem {
|
||||
inherit system specialArgs;
|
||||
modules = ruby_modules;
|
||||
};
|
||||
|
||||
home-manager.extraSpecialArgs = specialArgs;
|
||||
home-manager.users.ryan = import ./home/linux/wayland.nix;
|
||||
}
|
||||
];
|
||||
kana = nixpkgs.lib.nixosSystem {
|
||||
inherit system specialArgs;
|
||||
modules = kana_modules;
|
||||
};
|
||||
};
|
||||
|
||||
# configurations for MacOS
|
||||
# macOS's configuration, for work.
|
||||
darwinConfigurations."harmonica" = darwin.lib.darwinSystem {
|
||||
system = "x86_64-darwin";
|
||||
|
||||
@@ -188,30 +197,52 @@
|
||||
x86_64-darwin = nixpkgs.legacyPackages.x86_64-darwin.nixpkgs-fmt;
|
||||
};
|
||||
|
||||
# generate qcow2 & iso image from nixos configuration
|
||||
# https://github.com/nix-community/nixos-generators
|
||||
# packages.x86_64-linux = {
|
||||
# qcow2 = nixos-generators.nixosGenerate {
|
||||
# system = "x86_64-linux";
|
||||
# modules = [
|
||||
# # you can include your own nixos configuration here, i.e.
|
||||
# # ./configuration.nix
|
||||
# ];
|
||||
# format = "qcow";
|
||||
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 = nixos-generators.nixosGenerate {
|
||||
inherit system specialArgs;
|
||||
modules = ai_modules;
|
||||
format = "iso";
|
||||
};
|
||||
# Hoshino Aquamarine is a virtual machine running on Proxmox VE.
|
||||
aquamarine = nixos-generators.nixosGenerate {
|
||||
inherit system specialArgs;
|
||||
modules = aquamarine_modules ++ [
|
||||
({config, ...}: {
|
||||
proxmox.qemuConf.name = "aquamarine-nixos-${config.system.nixos.label}";
|
||||
})
|
||||
];
|
||||
|
||||
# # you can also define your own custom formats
|
||||
# # customFormats = { "myFormat" = <myFormatModule>; ... };
|
||||
# # format = "myFormat";
|
||||
# };
|
||||
|
||||
# iso = nixos-generators.nixosGenerate {
|
||||
# system = "x86_64-linux";
|
||||
# modules = [
|
||||
# # you can include your own nixos configuration here, i.e.
|
||||
# # ./configuration.nix
|
||||
# ];
|
||||
# format = "iso";
|
||||
# };
|
||||
# };
|
||||
# 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 = 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 = kana_modules ++ [
|
||||
({config, ...}: {
|
||||
proxmox.qemuConf.name = "kana-nixos-${config.system.nixos.label}";
|
||||
})
|
||||
];
|
||||
format = "proxmox";
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user