Skip to content

Commit fdd37ed

Browse files
authored
[feat] add nixos primitives and configuration (#4)
* add base nixos config * extend lib * add nixos inputs * add base machine profile * update pass * use primitive * refactor darwin system configurations * extract config * rm duplicate * refacotr * fix typo * add nixos settings * refactor * reset version * push * empty system * fix server profile * update nixpkgs * get rid of attribute * fix * fix * define * rm hostplatform * try again * add package * mod packages * test stable * add pkgs * update package descriptions * update package descriptions * add util to fetch package descriptions * add config * fix deprecation msg * fix samba config * fix whitespace * update lockfile * fix label * cleanup * fix state version * update * reset lockfile * revert state version * remove nixos hardware input * use stable instead of unstable * update snowflake config * revert mknixos change * fix formatting * add homes config * update gitignore * update readme * update * update readme * update readme
1 parent 961a68d commit fdd37ed

File tree

18 files changed

+770
-157
lines changed

18 files changed

+770
-157
lines changed

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ node_modules/
55
logs/
66
*.log
77

8+
# nix builds
9+
**/result
10+
811
core/.config/alacritty/themes/.selected_theme
912
core/.config/alacritty/alacritty.theme-switch-backup.yml
10-
nix/result
13+

README.md

Lines changed: 121 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,147 @@
11
# dotfiles
22

3-
> [!NOTE]
4-
> Old config can be found in legacy branch
5-
6-
### Installation
7-
8-
1. Install [nix](https://nixos.org/download)
9-
2. Install [homebrew](https://brew.sh)
10-
3. Ensure Xcode command line tools are installed (setting up brew should already do this)
11-
4. Ensure you are signed into the App Store (when providing appids for `mas`)
12-
5. Clone this repository
13-
14-
```sh
15-
git clone [email protected]:ecklf/dotfiles.git
16-
```
3+
## Darwin
174

18-
### Fresh Install
5+
### Setup
196

207
> [!TIP]
21-
> The macOS dock can be wiped with:
8+
> The Dock can be wiped with:
229
> ```sh
2310
> defaults write com.apple.dock persistent-apps -array && killall Dock
2411
> ```
2512
13+
**1: Install [nix](https://nixos.org/download) and [homebrew](https://brew.sh)**
14+
15+
**2: Ensure Xcode command line tools are installed (setting up _homebrew_ should have already done this)**
16+
17+
**3: Ensure you are signed into the App Store (if using app ids in `mas` configuration)**
18+
19+
### Using this repository
20+
2621
> [!IMPORTANT]
27-
> For the very first run, `darwin-rebuild` won't be installed in your path.
22+
> For the very first run, `darwin-rebuild` won't be installed in your path
2823
> ```sh
2924
> nix run nix-darwin --extra-experimental-features flakes --extra-experimental-features nix-command -- switch --flake ~/dotfiles/nix#omega
3025
> ```
3126
32-
### Usage
33-
3427
```sh
3528
# Build the flake `omega` (see flake.nix)
3629
darwin-rebuild build --flake ~/dotfiles/nix#omega
3730
# Switch to `omega` (see flake.nix)
3831
darwin-rebuild switch --flake ~/dotfiles/nix#omega
3932
```
4033
34+
## NixOS
35+
36+
> [!NOTE]
37+
> Also see the official guide:
38+
> https://nixos.wiki/wiki/NixOS_Installation_Guide
39+
40+
### Setup
41+
42+
**1: Download [ISO image](https://nixos.org/download/#nixos-iso), flash it to USB, and boot**
43+
44+
**2: Setup Wireless (optional)**
45+
```sh
46+
sudo systemctl start wpa_supplicant
47+
wpa_cli
48+
> scan
49+
> scan_results
50+
> add_network
51+
> 0
52+
> set_network 0 ssid "NETWORK_SSID"
53+
> set_network 0 psk "NETWORK_SECRET"
54+
> enable_network 0
55+
> quit
56+
ip a
57+
ping google.com
58+
```
59+
60+
**3: Partition Disks**
61+
62+
These steps are for a UEFI system with GPT partitioning. Adjust as needed.
63+
64+
> [!IMPORTANT]
65+
> Ensure the label steps for `NIXROOT` and `NIXBOOT` are not skipped as they are used in the configuration.
66+
67+
```sh
68+
# Identify disk
69+
lsblk # identify disk
70+
# Partition disk
71+
sudo fdisk /dev/sdX
72+
> g (gpt disk label)
73+
> n
74+
> 1 (partition number [1/128])
75+
> 2048 first sector
76+
> +500M last sector (boot sector size)
77+
> t
78+
> 1 (EFI System)
79+
> n
80+
> 2
81+
> default (fill up partition)
82+
> default (fill up partition)
83+
> w (write)
84+
# Identify partitions, label and make fs
85+
lsblk
86+
sudo mkfs.fat -F 32 /dev/sdX1
87+
sudo fatlabel /dev/sdX1 NIXBOOT
88+
sudo mkfs.ext4 /dev/sdX2 -L NIXROOT
89+
sudo mount /dev/disk/by-label/NIXROOT /mnt
90+
sudo mkdir -p /mnt/boot
91+
sudo mount /dev/disk/by-label/NIXBOOT /mnt/boot
92+
# Create swap file
93+
sudo dd if=/dev/zero of=/mnt/.swapfile bs=1024 count=2097152 (2GB size)
94+
sudo chmod 600 /mnt/.swapfile
95+
sudo mkswap /mnt/.swapfile
96+
sudo swapon /mnt/.swapfile
97+
```
98+
99+
**4: Installation**
100+
```sh
101+
sudo nixos-generate-config --root /mnt
102+
cd /mnt
103+
sudo nixos-install
104+
```
105+
106+
**5: Add nix channels**
107+
```sh
108+
# Add home-manager channel (update version if needed)
109+
sudo nix-channel --add https://github.com/nix-community/home-manager/archive/release-24.05.tar.gz home-manager
110+
sudo nix-channel --update
111+
```
112+
113+
### Using this repository
114+
```sh
115+
# Build the flake `snowflake` (see flake.nix)
116+
sudo nixos-rebuild build --flake '~/dotfiles/nix#snowflake'
117+
# Switch to `snowflake` (see flake.nix)
118+
sudo nixos-rebuild switch --flake '~/dotfiles/nix#snowflake'
119+
```
120+
121+
### Post Install
122+
123+
> [!IMPORTANT]
124+
> Update your user password
125+
> ```sh
126+
> sudo passwd
127+
> ```
128+
129+
Set up Samba if used by configuration:
130+
131+
```sh
132+
# See user info
133+
sudo pdbedit -L -v
134+
# Add samba password
135+
sudo smbpasswd -a $(whoami)
136+
# Debug samba issues
137+
sudo systemctl status mnt-share.mount
138+
```
139+
140+
## Updating inputs
141+
41142
```sh
42143
# Upgrading nix — https://nix.dev/manual/nix/2.22/installation/upgrading
43-
# Updating inputs
144+
# Updating flake inputs
44145
nix flake lock --update-all
45146
nix flake lock --update-input <input>
46147
```

nix/fetch-nixpkgs-descriptions.mjs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
const IDENTIFIERS = [
2+
"pkgs.master.go-task",
3+
"pkgs.goreleaser",
4+
"pkgs.aws-iam-authenticator",
5+
"pkgs.lua51Packages.busted",
6+
"pkgs.lua51Packages.lua",
7+
"pkgs.lua51Packages.luacheck",
8+
"pkgs.lua51Packages.luafilesystem",
9+
"pkgs.lua51Packages.luarocks",
10+
];
11+
12+
const fetchHits = async (identifier) => {
13+
const segments = identifier.split(".");
14+
const pkgName = segments[segments.length - 1];
15+
16+
const result = await fetch(
17+
"https://search.nixos.org/backend/latest-42-nixos-24.05/_search",
18+
{
19+
headers: {
20+
accept: "*/*",
21+
"accept-language": "en-US,en;q=0.9,zh-CN;q=0.8,zh;q=0.7",
22+
authorization: "Basic YVdWU0FMWHBadjpYOGdQSG56TDUyd0ZFZWt1eHNmUTljU2g=",
23+
"content-type": "application/json",
24+
priority: "u=1, i",
25+
"sec-ch-ua":
26+
'"Chromium";v="130", "Google Chrome";v="130", "Not?A_Brand";v="99"',
27+
"sec-ch-ua-mobile": "?0",
28+
"sec-ch-ua-platform": '"macOS"',
29+
"sec-fetch-dest": "empty",
30+
"sec-fetch-mode": "cors",
31+
"sec-fetch-site": "same-origin",
32+
Referer:
33+
"https://search.nixos.org/packages?channel=24.05&from=0&size=50&sort=relevance&type=packages&query=graphviz",
34+
"Referrer-Policy": "strict-origin-when-cross-origin",
35+
},
36+
body: `{"from":0,"size":50,"sort":[{"_score":"desc","package_attr_name":"desc","package_pversion":"desc"}],"aggs":{"package_attr_set":{"terms":{"field":"package_attr_set","size":20}},"package_license_set":{"terms":{"field":"package_license_set","size":20}},"package_maintainers_set":{"terms":{"field":"package_maintainers_set","size":20}},"package_platforms":{"terms":{"field":"package_platforms","size":20}},"all":{"global":{},"aggregations":{"package_attr_set":{"terms":{"field":"package_attr_set","size":20}},"package_license_set":{"terms":{"field":"package_license_set","size":20}},"package_maintainers_set":{"terms":{"field":"package_maintainers_set","size":20}},"package_platforms":{"terms":{"field":"package_platforms","size":20}}}}},"query":{"bool":{"filter":[{"term":{"type":{"value":"package","_name":"filter_packages"}}},{"bool":{"must":[{"bool":{"should":[]}},{"bool":{"should":[]}},{"bool":{"should":[]}},{"bool":{"should":[]}}]}}],"must":[{"dis_max":{"tie_breaker":0.7,"queries":[{"multi_match":{"type":"cross_fields","query":"${pkgName}","analyzer":"whitespace","auto_generate_synonyms_phrase_query":false,"operator":"and","_name":"multi_match_graphviz","fields":["package_attr_name^9","package_attr_name.*^5.3999999999999995","package_programs^9","package_programs.*^5.3999999999999995","package_pname^6","package_pname.*^3.5999999999999996","package_description^1.3","package_description.*^0.78","package_longDescription^1","package_longDescription.*^0.6","flake_name^0.5","flake_name.*^0.3"]}},{"wildcard":{"package_attr_name":{"value":"*graphviz*","case_insensitive":true}}}]}}]}}}`,
37+
method: "POST",
38+
},
39+
);
40+
const json = await result.json();
41+
const packageDescription =
42+
json.hits.hits.at(0)._source.package_description ?? "";
43+
return `${identifier} # ${packageDescription}`;
44+
};
45+
46+
IDENTIFIERS.forEach(async (identifier) => {
47+
console.log(await fetchHits(identifier));
48+
});

nix/flake.nix

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,24 @@
11
{
2-
description = "macOS";
2+
description = "NixOS and Darwin flakes";
33
inputs = {
44
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
55
nixpkgs-stable.url = "github:nixos/nixpkgs";
66
nixpkgs-master.url = "github:nixos/nixpkgs/master";
77
nur.url = "github:nix-community/NUR";
88
# Controls macOS system level software and settings including fonts
9-
darwin.url = "github:lnl7/nix-darwin";
10-
darwin.inputs.nixpkgs.follows = "nixpkgs";
9+
darwin = {
10+
url = "github:lnl7/nix-darwin";
11+
inputs.nixpkgs.follows = "nixpkgs";
12+
};
1113
# Manages configs links and home directory
12-
home-manager.url = "github:nix-community/home-manager/master";
13-
home-manager.inputs.nixpkgs.follows = "nixpkgs";
14+
home-manager = {
15+
url = "github:nix-community/home-manager/master";
16+
inputs.nixpkgs.follows = "nixpkgs";
17+
};
1418
};
1519

1620
outputs =
17-
{ self
21+
inputs @ { self
1822
, nixpkgs
1923
, nixpkgs-stable
2024
, nixpkgs-master
@@ -24,9 +28,20 @@
2428
}:
2529
let
2630
mkDarwin = import ./lib/mkdarwin.nix;
31+
mkNixOS = import ./lib/mknixos.nix;
2732
overlays = [ ];
2833
in
2934
{
35+
nixosConfigurations = {
36+
snowflake = mkNixOS "snowflake" {
37+
inherit inputs nixpkgs nixpkgs-stable nixpkgs-master overlays;
38+
system = "x86_64-linux";
39+
username = "ecklf";
40+
profile = "server";
41+
extraModules = [ ];
42+
extraHomeModules = [ ];
43+
};
44+
};
3045
darwinConfigurations = {
3146
omega = mkDarwin "omega" {
3247
inherit self nixpkgs nixpkgs-stable nixpkgs-master nur darwin home-manager overlays;

nix/lib/mkdarwin.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ darwin.lib.darwinSystem {
5454
programs.zsh.enable = true;
5555
})
5656

57-
../darwin
57+
../os/darwin
5858
../machines/${hostname}
5959

6060
] ++ extraModules ++ [

nix/lib/mknixos.nix

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
hostname:
2+
{ inputs
3+
, nixpkgs
4+
, nixpkgs-stable
5+
, nixpkgs-master
6+
, system
7+
, username
8+
, profile
9+
, overlays
10+
, extraModules ? [ ]
11+
, extraHomeModules ? [ ]
12+
, efiSysMountPoint ? "/boot"
13+
, timezone ? "Europe/Berlin"
14+
}:
15+
let
16+
systemSpecificOverlays = [
17+
(final: prev: {
18+
stable = import nixpkgs-stable {
19+
system = system;
20+
config.allowUnfree = true;
21+
};
22+
master = import nixpkgs-master {
23+
system = system;
24+
config.allowUnfree = true;
25+
};
26+
})
27+
];
28+
inherit (nixpkgs) lib;
29+
in
30+
lib.nixosSystem {
31+
inherit system;
32+
specialArgs = { inherit system username profile hostname timezone; };
33+
modules =
34+
[
35+
{
36+
nixpkgs.overlays = systemSpecificOverlays ++ overlays;
37+
nixpkgs.config.allowUnfree = true;
38+
}
39+
../os/nixos
40+
({ config, ... }: {
41+
home-manager.sharedModules = [ ] ++ extraHomeModules;
42+
})
43+
] ++ extraModules ++ [
44+
../machines/${hostname}
45+
inputs.home-manager.nixosModules.home-manager
46+
{
47+
home-manager = {
48+
useGlobalPkgs = true;
49+
useUserPackages = true;
50+
extraSpecialArgs = {
51+
inherit inputs username profile hostname timezone;
52+
};
53+
users."${username}".imports = [
54+
../profiles/${profile}
55+
];
56+
};
57+
}
58+
];
59+
}
60+

0 commit comments

Comments
 (0)