-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflake.nix
More file actions
117 lines (114 loc) · 3.49 KB
/
Copy pathflake.nix
File metadata and controls
117 lines (114 loc) · 3.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
{
description = "lemtoc's dotfiles";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
nix-darwin = {
url = "github:LnL7/nix-darwin";
inputs.nixpkgs.follows = "nixpkgs";
};
home-manager = {
url = "github:nix-community/home-manager";
inputs.nixpkgs.follows = "nixpkgs";
};
nova = {
url = "github:lemtoc-labs/nova";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs =
inputs@{
nixpkgs,
nix-darwin,
...
}:
let
system = "aarch64-darwin";
pkgs = nixpkgs.legacyPackages.${system};
nixGithubTokenHelpers = ''
export_nix_github_token() {
local github_token
case "''${NIX_CONFIG-}" in
*"github.com="*)
return
;;
esac
if ! github_token=$(${pkgs.gh}/bin/gh auth token 2>/dev/null) || [ -z "$github_token" ]; then
return
fi
if [ -n "''${NIX_CONFIG-}" ]; then
export NIX_CONFIG="$(printf '%s\n%s' "$NIX_CONFIG" "extra-access-tokens = github.com=$github_token")"
else
export NIX_CONFIG="extra-access-tokens = github.com=$github_token"
fi
}
'';
mkDarwinConfig =
{ hostName, username }:
nix-darwin.lib.darwinSystem {
specialArgs = { inherit inputs username; };
modules = [
{
networking.hostName = hostName;
networking.computerName = hostName;
nixpkgs.hostPlatform = system;
}
./hosts/common
./hosts/${hostName}
];
};
in
{
darwinConfigurations."M4Pro" = mkDarwinConfig {
hostName = "M4Pro";
username = "t1190078";
};
darwinConfigurations."M4Air" = mkDarwinConfig {
hostName = "M4Air";
username = "lemtoc";
};
formatter.${system} = pkgs.nixfmt-tree;
apps.${system} = {
update = {
type = "app";
program = toString (
pkgs.writeShellScript "flake-update" ''
set -e
${nixGithubTokenHelpers}
export_nix_github_token
echo "Updating flake.lock..."
nix flake update --flake "$HOME/.dotfiles"
echo "Done! Run 'nix run .#switch' to apply changes."
''
);
};
switch = {
type = "app";
program = toString (
pkgs.writeShellScript "darwin-switch" ''
set -eo pipefail
HOST_NAME=$(scutil --get LocalHostName)
echo "Updating Homebrew..."
/opt/homebrew/bin/brew update
echo "Building and switching to darwin configuration for $HOST_NAME..."
${nixGithubTokenHelpers}
export_nix_github_token
sudo -H --preserve-env=NIX_CONFIG nix run nix-darwin -- switch --flake "$HOME/.dotfiles#$HOST_NAME"
echo "Done!"
''
);
};
build = {
type = "app";
program = toString (
pkgs.writeShellScript "darwin-build" ''
set -e
HOST_NAME=$(scutil --get LocalHostName)
echo "Building darwin configuration for $HOST_NAME..."
${pkgs.nix-output-monitor}/bin/nom build "$HOME/.dotfiles#darwinConfigurations.$HOST_NAME.system"
echo "Build successful! Run 'nix run .#switch' to apply."
''
);
};
};
};
}