mirror of
https://github.com/harivansh-afk/nix.git
synced 2026-04-15 17:01:01 +00:00
flake parts
This commit is contained in:
parent
6dfef30594
commit
9a13c35acd
7 changed files with 144 additions and 90 deletions
|
|
@ -52,6 +52,8 @@ just fmt
|
|||
hosts/darwin/ - macOS host entrypoint
|
||||
hosts/netty/ - NixOS VPS entrypoint (disko + hardware)
|
||||
modules/ - shared system modules + devshells
|
||||
modules/hosts/ - flake-parts host output definitions
|
||||
modules/nixpkgs.nix - shared flake context (hosts, args, pkgs helpers)
|
||||
home/ - Home Manager modules
|
||||
lib/hosts.nix - host metadata used by the flake
|
||||
lib/ - shared package sets and theme system
|
||||
|
|
|
|||
93
flake.nix
93
flake.nix
|
|
@ -45,98 +45,13 @@
|
|||
};
|
||||
|
||||
outputs =
|
||||
inputs@{
|
||||
self,
|
||||
flake-parts,
|
||||
nixpkgs,
|
||||
nix-darwin,
|
||||
home-manager,
|
||||
nix-homebrew,
|
||||
...
|
||||
}:
|
||||
let
|
||||
username = "rathi";
|
||||
hosts = import ./lib/hosts.nix { inherit username; };
|
||||
|
||||
mkPkgs =
|
||||
system:
|
||||
import nixpkgs {
|
||||
inherit system;
|
||||
config.allowUnfree = true;
|
||||
};
|
||||
|
||||
mkHomeManagerModule =
|
||||
host:
|
||||
{
|
||||
home-manager.useGlobalPkgs = true;
|
||||
home-manager.useUserPackages = true;
|
||||
home-manager.extraSpecialArgs = {
|
||||
inherit inputs self username;
|
||||
hostname = host.hostname;
|
||||
};
|
||||
home-manager.backupFileExtension = "hm-bak";
|
||||
home-manager.users.${username} = import host.homeModule;
|
||||
};
|
||||
in
|
||||
inputs@{ flake-parts, ... }:
|
||||
flake-parts.lib.mkFlake { inherit inputs; } {
|
||||
systems = [
|
||||
hosts.darwin.system
|
||||
hosts.netty.system
|
||||
];
|
||||
|
||||
imports = [
|
||||
./modules/nixpkgs.nix
|
||||
./modules/devshells.nix
|
||||
./modules/hosts/darwin.nix
|
||||
./modules/hosts/netty.nix
|
||||
];
|
||||
|
||||
flake = {
|
||||
darwinConfigurations.${hosts.darwin.name} = nix-darwin.lib.darwinSystem {
|
||||
system = hosts.darwin.system;
|
||||
specialArgs = {
|
||||
inherit inputs self username;
|
||||
hostname = hosts.darwin.hostname;
|
||||
};
|
||||
modules = [
|
||||
./hosts/${hosts.darwin.name}
|
||||
home-manager.darwinModules.home-manager
|
||||
nix-homebrew.darwinModules.nix-homebrew
|
||||
{
|
||||
users.users.${username}.home = hosts.darwin.homeDirectory;
|
||||
|
||||
nix-homebrew = {
|
||||
enable = true;
|
||||
enableRosetta = true;
|
||||
user = username;
|
||||
autoMigrate = true;
|
||||
};
|
||||
}
|
||||
(mkHomeManagerModule hosts.darwin)
|
||||
];
|
||||
};
|
||||
|
||||
nixosConfigurations.${hosts.netty.name} = nixpkgs.lib.nixosSystem {
|
||||
system = hosts.netty.system;
|
||||
specialArgs = {
|
||||
inherit inputs self username;
|
||||
hostname = hosts.netty.hostname;
|
||||
};
|
||||
modules = [
|
||||
inputs.disko.nixosModules.disko
|
||||
./hosts/${hosts.netty.name}/configuration.nix
|
||||
home-manager.nixosModules.home-manager
|
||||
(mkHomeManagerModule hosts.netty)
|
||||
];
|
||||
};
|
||||
|
||||
homeConfigurations.${hosts.netty.name} = home-manager.lib.homeManagerConfiguration {
|
||||
pkgs = mkPkgs hosts.netty.system;
|
||||
extraSpecialArgs = {
|
||||
inherit inputs self username;
|
||||
hostname = hosts.netty.hostname;
|
||||
};
|
||||
modules = [
|
||||
hosts.netty.standaloneHomeModule
|
||||
];
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
|
|||
3
justfile
3
justfile
|
|
@ -17,7 +17,8 @@ switch config='darwin':
|
|||
if [[ "{{config}}" == "darwin" ]]; then
|
||||
sudo env PATH="$PATH" nix --extra-experimental-features 'nix-command flakes' run github:nix-darwin/nix-darwin/master#darwin-rebuild -- switch --flake path:.#{{config}}
|
||||
else
|
||||
nix --extra-experimental-features 'nix-command flakes' run github:nix-community/home-manager -- switch --flake path:.#{{config}} -b hm-bak
|
||||
backup_ext="hm-bak-$(date +%Y%m%d-%H%M%S)"
|
||||
nix --extra-experimental-features 'nix-command flakes' run github:nix-community/home-manager -- switch --flake path:.#{{config}} -b "$backup_ext"
|
||||
fi
|
||||
|
||||
fmt:
|
||||
|
|
|
|||
33
modules/hosts/darwin.nix
Normal file
33
modules/hosts/darwin.nix
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
{
|
||||
hosts,
|
||||
inputs,
|
||||
username,
|
||||
mkSpecialArgs,
|
||||
mkHomeManagerModule,
|
||||
...
|
||||
}:
|
||||
let
|
||||
host = hosts.darwin;
|
||||
in
|
||||
{
|
||||
flake.darwinConfigurations.${host.name} = inputs.nix-darwin.lib.darwinSystem {
|
||||
system = host.system;
|
||||
specialArgs = mkSpecialArgs host;
|
||||
modules = [
|
||||
../../hosts/${host.name}
|
||||
inputs.home-manager.darwinModules.home-manager
|
||||
inputs.nix-homebrew.darwinModules.nix-homebrew
|
||||
{
|
||||
users.users.${username}.home = host.homeDirectory;
|
||||
|
||||
nix-homebrew = {
|
||||
enable = true;
|
||||
enableRosetta = true;
|
||||
user = username;
|
||||
autoMigrate = true;
|
||||
};
|
||||
}
|
||||
(mkHomeManagerModule host)
|
||||
];
|
||||
};
|
||||
}
|
||||
33
modules/hosts/netty.nix
Normal file
33
modules/hosts/netty.nix
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
{
|
||||
hosts,
|
||||
inputs,
|
||||
mkPkgs,
|
||||
mkSpecialArgs,
|
||||
mkHomeManagerModule,
|
||||
...
|
||||
}:
|
||||
let
|
||||
host = hosts.netty;
|
||||
in
|
||||
{
|
||||
flake = {
|
||||
nixosConfigurations.${host.name} = inputs.nixpkgs.lib.nixosSystem {
|
||||
system = host.system;
|
||||
specialArgs = mkSpecialArgs host;
|
||||
modules = [
|
||||
inputs.disko.nixosModules.disko
|
||||
../../hosts/${host.name}/configuration.nix
|
||||
inputs.home-manager.nixosModules.home-manager
|
||||
(mkHomeManagerModule host)
|
||||
];
|
||||
};
|
||||
|
||||
homeConfigurations.${host.name} = inputs.home-manager.lib.homeManagerConfiguration {
|
||||
pkgs = mkPkgs host.system;
|
||||
extraSpecialArgs = mkSpecialArgs host;
|
||||
modules = [
|
||||
host.standaloneHomeModule
|
||||
];
|
||||
};
|
||||
};
|
||||
}
|
||||
45
modules/nixpkgs.nix
Normal file
45
modules/nixpkgs.nix
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
{
|
||||
self,
|
||||
inputs,
|
||||
lib,
|
||||
...
|
||||
}:
|
||||
let
|
||||
username = "rathi";
|
||||
hosts = import ../lib/hosts.nix { inherit username; };
|
||||
|
||||
mkPkgs =
|
||||
system:
|
||||
import inputs.nixpkgs {
|
||||
inherit system;
|
||||
config.allowUnfree = true;
|
||||
};
|
||||
|
||||
mkSpecialArgs = host: {
|
||||
inherit inputs self username;
|
||||
hostname = host.hostname;
|
||||
};
|
||||
|
||||
mkHomeManagerModule =
|
||||
host:
|
||||
{
|
||||
home-manager.useGlobalPkgs = true;
|
||||
home-manager.useUserPackages = true;
|
||||
home-manager.extraSpecialArgs = mkSpecialArgs host;
|
||||
home-manager.backupCommand = "bash ${../scripts/home-manager-backup.sh}";
|
||||
home-manager.users.${username} = import host.homeModule;
|
||||
};
|
||||
in
|
||||
{
|
||||
systems = lib.unique (map (host: host.system) (builtins.attrValues hosts));
|
||||
|
||||
_module.args = {
|
||||
inherit
|
||||
username
|
||||
hosts
|
||||
mkPkgs
|
||||
mkSpecialArgs
|
||||
mkHomeManagerModule
|
||||
;
|
||||
};
|
||||
}
|
||||
25
scripts/home-manager-backup.sh
Normal file
25
scripts/home-manager-backup.sh
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
if [[ $# -eq 0 ]]; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
target_path="${1:?expected target path}"
|
||||
base_backup="${target_path}.hm-bak"
|
||||
|
||||
if [[ ! -e "$base_backup" ]]; then
|
||||
mv "$target_path" "$base_backup"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
timestamp="$(date +%Y%m%d-%H%M%S)"
|
||||
backup_path="${base_backup}.${timestamp}"
|
||||
suffix=0
|
||||
|
||||
while [[ -e "$backup_path" ]]; do
|
||||
suffix=$((suffix + 1))
|
||||
backup_path="${base_backup}.${timestamp}.${suffix}"
|
||||
done
|
||||
|
||||
mv "$target_path" "$backup_path"
|
||||
Loading…
Add table
Add a link
Reference in a new issue