-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathflake.nix
More file actions
108 lines (100 loc) · 2.9 KB
/
flake.nix
File metadata and controls
108 lines (100 loc) · 2.9 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
{
description = "Scotty's Darwin system flake.";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
nix-darwin.url = "github:nix-darwin/nix-darwin/master";
nix-darwin.inputs.nixpkgs.follows = "nixpkgs";
flake-utils.url = "github:numtide/flake-utils";
nix-homebrew.url = "github:zhaofengli-wip/nix-homebrew";
homebrew-core = {
url = "github:homebrew/homebrew-core";
flake = false;
};
homebrew-cask = {
url = "github:homebrew/homebrew-cask";
flake = false;
};
homebrew-bundle = {
url = "github:homebrew/homebrew-bundle";
flake = false;
};
};
outputs =
{ ... }@inputs:
with inputs;
let
configuration =
{ pkgs, ... }:
{
nix.settings.experimental-features = "nix-command flakes";
system.configurationRevision = self.rev or self.dirtyRev or null;
system.stateVersion = 6;
nixpkgs.hostPlatform = "aarch64-darwin";
};
hostname =
let
h = builtins.getEnv "HOSTNAME";
in
if h == "" then "zmbp" else h;
username =
let
u = builtins.getEnv "USERNAME";
in
if u == "" then "scta" else u;
in
{
darwinConfigurations."${hostname}" = nix-darwin.lib.darwinSystem {
modules = [
configuration
./nix/darwin.nix
./nix/homebrew.nix
./nix/pkgs.nix
];
specialArgs = {
inherit
homebrew-bundle
homebrew-core
homebrew-cask
hostname
nix-homebrew
username
;
};
};
}
// flake-utils.lib.eachDefaultSystem (system: {
apps.install = {
type = "app";
program = toString (
nixpkgs.legacyPackages.${system}.writeShellScript "install" ''
# Set defaults from system
HOSTNAME=$(hostname | cut -d. -f1)
USERNAME=$(whoami)
# Optionally override with command line arguments
if [[ $# -gt 0 ]]; then
case $1 in
--hostname=*)
HOSTNAME="''${1#*=}"
shift
;;
esac
fi
if [[ $# -gt 0 ]]; then
case $1 in
--username=*)
USERNAME="''${1#*=}"
shift
;;
esac
fi
# Export variables for the flake
export HOSTNAME
export USERNAME
sudo --preserve-env=HOSTNAME,USERNAME \
${nix-darwin.packages.${system}.darwin-rebuild}/bin/darwin-rebuild \
switch --flake .#"$HOSTNAME"
''
);
};
});
}