host/macbook-pro: init nix-darwin configuration
This commit is contained in:
parent
5bc599772d
commit
488dc5095e
7 changed files with 172 additions and 56 deletions
17
Makefile
17
Makefile
|
@ -1,4 +1,4 @@
|
|||
NIX_RUN := nix run .\#
|
||||
NIX := nix --experimental-features "nix-command flakes"
|
||||
|
||||
DEPS_EDITOR := \
|
||||
nixeovim
|
||||
|
@ -14,7 +14,8 @@ DEPS_SYSTEM := \
|
|||
|
||||
MACHINES := \
|
||||
home \
|
||||
asus-gl553vd
|
||||
asus-gl553vd \
|
||||
macbook-pro
|
||||
|
||||
VPS := \
|
||||
istal \
|
||||
|
@ -32,12 +33,12 @@ define machine_rule
|
|||
.PHONY: $(1)
|
||||
$(1): ;
|
||||
# systemctl --user reset-failed
|
||||
sudo nix run -L $(NIX_ARGS) .#switch/$(1) -- $(BUILD_ARGS)
|
||||
sudo $(NIX) run -L $(NIX_ARGS) .#switch/$(1) -- $(BUILD_ARGS)
|
||||
endef
|
||||
|
||||
define vps_rule
|
||||
.PHONY: $(1)
|
||||
$(1): ; nix run -L .#deploy/$(1) -- $(BUILD_ARGS)
|
||||
$(1): ; $(NIX) run -L .#deploy/$(1) -- $(BUILD_ARGS)
|
||||
|
||||
endef
|
||||
|
||||
|
@ -54,11 +55,11 @@ rollback:
|
|||
|
||||
.PHONY: neovim
|
||||
neovim:
|
||||
nix profile upgrade $(or $(NEOVIM_INDEX),$(shell nix profile list --json | jq '.elements | to_entries[] | select(.value.attrPath | endswith(".neovim-dev")) | .key'))
|
||||
$(NIX) profile upgrade $(or $(NEOVIM_INDEX),$(shell $(NIX) profile list --json | jq '.elements | to_entries[] | select(.value.attrPath | endswith(".neovim-dev")) | .key'))
|
||||
|
||||
.PHONY: install/neovim
|
||||
install/neovim:
|
||||
nix profile install .#neovim-dev
|
||||
$(NIX) profile install .#neovim-dev
|
||||
|
||||
################################################################################
|
||||
# Deps
|
||||
|
@ -66,11 +67,11 @@ install/neovim:
|
|||
|
||||
.PHONY: deps/editor
|
||||
deps/editor:
|
||||
nix flake update $(DEPS_EDITOR)
|
||||
$(NIX) flake update $(DEPS_EDITOR)
|
||||
|
||||
.PHONY: deps/system
|
||||
deps/system:
|
||||
nix flake update $(DEPS_SYSTEM)
|
||||
$(NIX) flake update $(DEPS_SYSTEM)
|
||||
|
||||
.PHONY: deps
|
||||
deps: deps/editor deps/system ;
|
||||
|
|
22
flake.lock
generated
22
flake.lock
generated
|
@ -255,6 +255,27 @@
|
|||
"type": "github"
|
||||
}
|
||||
},
|
||||
"nix-darwin": {
|
||||
"inputs": {
|
||||
"nixpkgs": [
|
||||
"nixpkgs"
|
||||
]
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1741126078,
|
||||
"narHash": "sha256-ng0a4cIq3c9E3iGKomlwqKzVYs2RLOzQho2U1Mc2sqU=",
|
||||
"owner": "LnL7",
|
||||
"repo": "nix-darwin",
|
||||
"rev": "c172f50b55b087f8e7801631de977461603bb976",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "LnL7",
|
||||
"ref": "nix-darwin-24.11",
|
||||
"repo": "nix-darwin",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"nix2lua": {
|
||||
"locked": {
|
||||
"lastModified": 1716215210,
|
||||
|
@ -382,6 +403,7 @@
|
|||
"impermanence": "impermanence",
|
||||
"lan-mouse": "lan-mouse",
|
||||
"nil": "nil",
|
||||
"nix-darwin": "nix-darwin",
|
||||
"nixeovim": "nixeovim",
|
||||
"nixpkgs": "nixpkgs_2",
|
||||
"nixpkgs-unstable": "nixpkgs-unstable",
|
||||
|
|
153
flake.nix
153
flake.nix
|
@ -27,6 +27,11 @@
|
|||
inputs.nixpkgs.follows = "nixpkgs";
|
||||
};
|
||||
|
||||
nix-darwin = {
|
||||
url = "github:LnL7/nix-darwin/nix-darwin-24.11";
|
||||
inputs.nixpkgs.follows = "nixpkgs";
|
||||
};
|
||||
|
||||
wired = {
|
||||
url = "github:Toqozz/wired-notify";
|
||||
inputs.nixpkgs.follows = "nixpkgs";
|
||||
|
@ -53,17 +58,75 @@
|
|||
};
|
||||
|
||||
outputs = { self, flake-utils, nixpkgs, nixeovim, ... } @ inputs:
|
||||
let inherit (flake-utils.lib) eachSystem system; in
|
||||
eachSystem [ system.x86_64-linux ]
|
||||
let
|
||||
inherit (nixpkgs) lib;
|
||||
|
||||
inherit (flake-utils.lib) eachSystem;
|
||||
inherit (flake-utils.lib.system) x86_64-linux x86_64-darwin;
|
||||
|
||||
hosts = (import ./hosts inputs);
|
||||
linuxMachines = lib.filterAttrs
|
||||
(hostname: { system, ... }: system == x86_64-linux)
|
||||
hosts;
|
||||
|
||||
darwinMachines = lib.filterAttrs
|
||||
(hostname: { system, ... }: system == x86_64-darwin)
|
||||
hosts;
|
||||
|
||||
mkDeploymentModule = targetHost: ({ lib, ... }: {
|
||||
options.deployment = with lib; {
|
||||
targetHost = mkOption {
|
||||
type = types.nullOr types.str;
|
||||
readOnly = true;
|
||||
internal = true;
|
||||
};
|
||||
};
|
||||
config.deployment = { inherit targetHost; };
|
||||
});
|
||||
|
||||
baseHomeManagerModule = ({ ... }: {
|
||||
home-manager.backupFileExtension = "backup";
|
||||
home-manager.useGlobalPkgs = true;
|
||||
home-manager.useUserPackages = true;
|
||||
home-manager.extraSpecialArgs = {
|
||||
packagesPath = ./packages;
|
||||
hostsPath = ./hosts;
|
||||
};
|
||||
home-manager.sharedModules = [
|
||||
{
|
||||
imports = [
|
||||
./modules/home-manager
|
||||
inputs.wired.homeManagerModules.default
|
||||
inputs.lan-mouse.homeManagerModules.default
|
||||
];
|
||||
}
|
||||
];
|
||||
});
|
||||
|
||||
baseDarwinModule = system: ({ ... }: {
|
||||
system.stateVersion = 5;
|
||||
system.configurationRevision = self.rev or self.dirtyRev or null;
|
||||
nixpkgs.hostPlatform = system;
|
||||
});
|
||||
in
|
||||
eachSystem [ x86_64-linux x86_64-darwin ]
|
||||
(system:
|
||||
let
|
||||
pkgs = import nixpkgs { inherit system; };
|
||||
inherit (pkgs) lib nixos-rebuild;
|
||||
|
||||
machineRebuild = { system, ...}:
|
||||
if system == x86_64-linux
|
||||
then pkgs.nixos-rebuild
|
||||
else inputs.nix-darwin.packages.${x86_64-darwin}.darwin-rebuild;
|
||||
|
||||
nixeovimPackage = config: nixeovim.lib.mkNixeovimPackage { inherit system config; };
|
||||
|
||||
localMachines = lib.filterAttrs (h: m: m.config.deployment.targetHost == null) self.nixosConfigurations;
|
||||
vpsMachines = lib.filterAttrs (h: m: m.config.deployment.targetHost != null) self.nixosConfigurations;
|
||||
localMachines = lib.filterAttrs
|
||||
(h: m: m.config.deployment.targetHost == null)
|
||||
(self.nixosConfigurations // self.darwinConfigurations);
|
||||
vpsMachines = lib.filterAttrs
|
||||
(h: m: m.config.deployment.targetHost != null)
|
||||
self.nixosConfigurations;
|
||||
in
|
||||
{
|
||||
packages = {
|
||||
|
@ -75,18 +138,20 @@
|
|||
(flake-utils.lib.flattenTree {
|
||||
deploy = lib.recurseIntoAttrs (lib.mapAttrs
|
||||
(hostname: machine: pkgs.writeShellScript "deploy/${hostname}" ''
|
||||
${nixos-rebuild}/bin/nixos-rebuild switch \
|
||||
${lib.getExe (machineRebuild machine)} switch \
|
||||
--flake .#${hostname} \
|
||||
${lib.optionalString (system != machine.system) ''--build-host root@${machine.config.deployment.targetHost} \''}
|
||||
--target-host root@${machine.config.deployment.targetHost} \
|
||||
$@
|
||||
'')
|
||||
vpsMachines);
|
||||
|
||||
switch = lib.recurseIntoAttrs (lib.mapAttrs
|
||||
(hostname: machine: pkgs.writeShellScript "switch/${hostname}" ''
|
||||
set -e
|
||||
${nixos-rebuild}/bin/nixos-rebuild switch --flake .#${hostname} $@
|
||||
'')
|
||||
(hostname: machine:
|
||||
pkgs.writeShellScript "switch/${hostname}" ''
|
||||
set -e
|
||||
${lib.getExe (machineRebuild machine)} switch --flake .#${hostname} $@
|
||||
'')
|
||||
localMachines);
|
||||
});
|
||||
|
||||
|
@ -117,7 +182,7 @@
|
|||
})
|
||||
// {
|
||||
nixosConfigurations =
|
||||
nixpkgs.lib.mapAttrs
|
||||
lib.mapAttrs
|
||||
(hostname: { system
|
||||
, specialArgs ? { }
|
||||
, extraModules ? [ ]
|
||||
|
@ -144,42 +209,46 @@
|
|||
impermanence.nixosModules.impermanence
|
||||
])
|
||||
++ [
|
||||
# deployment settings
|
||||
({ lib, ... }: {
|
||||
options.deployment = with lib; {
|
||||
targetHost = mkOption {
|
||||
type = types.nullOr types.str;
|
||||
readOnly = true;
|
||||
internal = true;
|
||||
};
|
||||
};
|
||||
config.deployment = { inherit targetHost; };
|
||||
})
|
||||
# base home manager settings
|
||||
({ ... }: {
|
||||
home-manager.backupFileExtension = "backup";
|
||||
home-manager.useGlobalPkgs = true;
|
||||
home-manager.useUserPackages = true;
|
||||
home-manager.extraSpecialArgs = {
|
||||
packagesPath = ./packages;
|
||||
hostsPath = ./hosts;
|
||||
};
|
||||
home-manager.sharedModules = [
|
||||
{
|
||||
imports = [
|
||||
./modules/home-manager
|
||||
inputs.wired.homeManagerModules.default
|
||||
inputs.lan-mouse.homeManagerModules.default
|
||||
];
|
||||
}
|
||||
];
|
||||
})
|
||||
(mkDeploymentModule targetHost)
|
||||
baseHomeManagerModule
|
||||
]
|
||||
++ extraModules
|
||||
++ [ ./modules/nixos ]
|
||||
++ [ ./hosts/${hostname}/configuration.nix ];
|
||||
})
|
||||
(import ./hosts inputs);
|
||||
linuxMachines;
|
||||
|
||||
darwinConfigurations =
|
||||
lib.mapAttrs
|
||||
(hostname: { system
|
||||
, specialArgs ? { }
|
||||
, extraModules ? [ ]
|
||||
, targetHost ? null
|
||||
}:
|
||||
inputs.nix-darwin.lib.darwinSystem {
|
||||
inputs = {
|
||||
inherit inputs;
|
||||
globalData = import ./data.nix;
|
||||
usersPath = ./users;
|
||||
hostsPath = ./hosts;
|
||||
packagesPath = ./packages;
|
||||
sharedPath = ./shared;
|
||||
} // specialArgs;
|
||||
|
||||
modules =
|
||||
(with inputs; [
|
||||
agenix.darwinModules.default
|
||||
home-manager.darwinModules.default
|
||||
])
|
||||
++ [
|
||||
(baseDarwinModule system)
|
||||
(mkDeploymentModule targetHost)
|
||||
baseHomeManagerModule
|
||||
]
|
||||
++ extraModules
|
||||
++ [ ./hosts/${hostname}/configuration.nix ];
|
||||
})
|
||||
darwinMachines;
|
||||
|
||||
diskoConfigurations = {
|
||||
asus-gl553vd = import ./hosts/asus-gl553vd/disk-config.nix;
|
||||
|
|
|
@ -2,10 +2,11 @@
|
|||
|
||||
let
|
||||
hardware = inputs.hardware.nixosModules;
|
||||
inherit (inputs.flake-utils.lib.system) x86_64-linux x86_64-darwin;
|
||||
in
|
||||
{
|
||||
home = {
|
||||
system = "x86_64-linux";
|
||||
system = x86_64-linux;
|
||||
|
||||
extraModules = [
|
||||
hardware.common-gpu-amd
|
||||
|
@ -15,7 +16,7 @@ in
|
|||
};
|
||||
|
||||
asus-gl553vd = {
|
||||
system = "x86_64-linux";
|
||||
system = x86_64-linux;
|
||||
|
||||
extraModules = [
|
||||
hardware.common-cpu-intel
|
||||
|
@ -24,8 +25,16 @@ in
|
|||
];
|
||||
};
|
||||
|
||||
macbook-pro = {
|
||||
system = x86_64-darwin;
|
||||
|
||||
extraModules = [
|
||||
# ./networking.secret.nix
|
||||
];
|
||||
};
|
||||
|
||||
istal = {
|
||||
system = "x86_64-linux";
|
||||
system = x86_64-linux;
|
||||
|
||||
extraModules = [
|
||||
../modules/vps.nix
|
||||
|
@ -35,7 +44,7 @@ in
|
|||
};
|
||||
|
||||
tatos = {
|
||||
system = "x86_64-linux";
|
||||
system = x86_64-linux;
|
||||
|
||||
extraModules = [
|
||||
../modules/vps.nix
|
||||
|
|
|
@ -18,8 +18,8 @@
|
|||
statdPort = 4000;
|
||||
exports = ''
|
||||
/export 192.168.0.0/24(rw,fsid=0,no_subtree_check)
|
||||
/export/mynix 192.168.0.0/24(rw,nohide,insecure,no_subtree_check)
|
||||
/export/projects 192.168.0.0/24(rw,nohide,insecure,no_subtree_check)
|
||||
/export/mynix 192.168.0.0/24(rw,nohide,insecure,no_subtree_check,all_squash,anonuid=502,anongid=20)
|
||||
/export/projects 192.168.0.0/24(rw,nohide,insecure,no_subtree_check,all_squash,anonuid=502,anongid=20)
|
||||
'';
|
||||
};
|
||||
networking.firewall = {
|
||||
|
|
15
hosts/macbook-pro/configuration.nix
Normal file
15
hosts/macbook-pro/configuration.nix
Normal file
|
@ -0,0 +1,15 @@
|
|||
{ pkgs, ... }:
|
||||
|
||||
{
|
||||
environment.systemPackages = with pkgs; [
|
||||
vim
|
||||
];
|
||||
|
||||
nix.settings.experimental-features = "nix-command flakes";
|
||||
|
||||
services.synergy.client = {
|
||||
enable = true;
|
||||
serverAddress = "192.168.0.153";
|
||||
screenName = "macbook-pro";
|
||||
};
|
||||
}
|
Binary file not shown.
Loading…
Add table
Reference in a new issue