refactor: Move nix outside of .config dir

Technically not a config but a compose file, so I think it's better to
have outside of `.config` dir
This commit is contained in:
Ahmad Ansori Palembani 2024-11-05 13:53:13 +07:00
parent 3484b4154a
commit 93a26accd1
Signed by: null2264
GPG key ID: BA64F8B60AF3EFB6
22 changed files with 0 additions and 0 deletions

1
nix/.gitignore vendored Normal file
View file

@ -0,0 +1 @@
result

97
nix/README.md Normal file
View file

@ -0,0 +1,97 @@
# `null2264`'s Nix Setup
You need to install Nix before following this guide: `sh <(curl -L https://nixos.org/nix/install)` and symlink this dir to `~/.config/nix`
## Structure
```
├── flake.lock
├── flake.nix
├── lib # Self-explanatory, it contains helper functions
│   ├── mkCommon.nix
│   └── mkSystem.nix
├── modules # Contains shared configuration across system, across user
│   └── home-manager
│   └── floorp.nix
├── systems # Contains configurations depending on what type OS nix is being used in
│   ├── darwin # macOS
│   │   ├── configuration.nix
│   │   └── default.nix
│   └── nix # Linux-alike
│   ├── default.nix
│   └── potato
│   └── default.nix
└── users # Contains configurations for multi-user setup
├── default.nix
└── ziro
├── darwin.nix
├── default.nix
└── linux.nix
```
## Setup
### macOS
> [!NOTE]
> If you're using Alfred, to make Applications installed via Nix to appear on Alfred:
> - Open Alfred Preferences
> - General > Default Results > Extras > Click `Advanced`
> - Add `com.apple.alias-file`
Nix in macOS is handled by [nix-darwin](https://github.com/LnL7/nix-darwin).
#### Initial
This is done because nix-darwin commands is not yet added to PATH, should be a one-time thing
```zsh
nix-env -iA nixpkgs.git
# Run `sudo chown $USER /nix/var/nix/profiles/per-user/$USER` if that returns error
nix build .#darwinConfigurations.<host>.system
./result/sw/bin/darwin-rebuild switch --flake .#<host>
# or
nix run nix-darwin -- switch --flake .#<host>
```
#### Rebuild
After initial setup, you should now be able to use the command directly:
```sh
darwin-rebuild build --flake . # or you can specify the hostname with `--flake . #<hostname>`
# or if you're feeling lucky
darwin-rebuild switch --flake .
```
### Other
Nix in non-NixOS Linux is handled by [system-manager](https://github.com/numtide/system-manager).
#### Rebuild
Unfortunately, root access is required in order to use system-manager.
```sh
sudo -i nix run 'github:numtide/system-manager' --extra-experimental-features "nix-command flakes" -- switch --flake $PWD
```
### Home
This is for per-user setup. Instead of managing the entire system, you're
managing one user at a time. This is handled by
[home-manager](https://github.com/nix-community/home-manager)
#### Rebuild
```sh
home-manager build --flake . # or you can specify the user with `--flake . #<username>@<hostname>`
# or if you're feeling lucky
home-manager switch --flake .
```

View file

@ -0,0 +1,97 @@
/**
* Better Floorp vertical tabs
*
* This makes Floorp's (expanded) vertical tabs not affecting sites' width,
* which can cause lag on heavy websites like Twitch and YouTube.
*
* This also fixed vertical tabs' width breaking when some preference related
* to browser's "head" is changed
*
* Based on my changes for Pulse, but Pulse is dead.
* REF: https://github.com/null2264/pulse/commit/fce966a110c2987b08d35bcd04c5992655b24b13
*/
:root {
/* from Floorp source code, too big for me */
/*--default-verticaltab-width: 45px;*/
/*--hoverd-verticaltab-width: 20em;*/
--default-verticaltab-width: 4.125em !important;
--hoverd-verticaltab-width: /*ZI:VERTICAL-TAB-HOVER-WIDTH-IN-EM*/ !important;
}
@charset "UTF-8";
@-moz-document url(chrome://browser/content/browser.xhtml) {
.browserContainer {
border-inline-width: 0 !important;
}
/* >> Fix height being inconsistent on hover */
.tab-icon-stack,
.tab-label-container {
height: 2.7em !important;
}
.tab-icon-stack {
align-items: center;
}
/* << Fix height being inconsistent on hover */
/* >> Fix vertical bar icon inconsistency */
/* FIXME: Tabs become inconsistent if one of them is pinned */
#tabbrowser-tabs {
margin-right: 0px !important;
}
#TabsToolbar .toolbarbutton-icon {
padding: 1em !important;
height: 3.5em !important;
width: 3.5em !important;
}
#TabsToolbar .toolbarbutton-badge-stack {
width: 3.5em !important;
}
.sidepanel-icon, .sidepanel-browser-icon {
padding: 0px !important;
height: 3.5em !important;
width: 3.5em !important;
}
#TabsToolbar .tab-throbber,
#TabsToolbar .tab-icon-pending,
#TabsToolbar .tab-icon-image,
#TabsToolbar .tab-sharing-icon-overlay,
#TabsToolbar .tab-icon-overlay {
margin-left: 0.5em !important;
margin-inline-end: 1.9em !important;
}
/* << Fix vertical bar icon inconsistency */
#sidebar-select-box {
width: var(--default-verticaltab-width) !important;
min-width: var(--default-verticaltab-width) !important;
max-width: var(--default-verticaltab-width) !important;
}
#TabsToolbar {
position: relative !important;
transition: all 300ms !important;
width: calc(var(--default-verticaltab-width) + 0.125em) !important;
min-width: calc(var(--default-verticaltab-width) + 0.125em) !important;
max-width: calc(var(--default-verticaltab-width) + 0.125em) !important;
z-index: 1; /* Probably not needed, since Floorp already handle this */
}
#TabsToolbar:not(:hover) {
scrollbar-width: none !important;
}
#TabsToolbar:hover {
transition: all 300ms !important;
width: var(--hoverd-verticaltab-width) !important;
min-width: var(--hoverd-verticaltab-width) !important;
max-width: var(--hoverd-verticaltab-width) !important;
z-index: 2; /* Probably not needed, since Floorp already handle this */
margin-right: calc((var(--hoverd-verticaltab-width) - var(--default-verticaltab-width) - 0.125em) * -1) !important;
}
}

415
nix/flake.lock generated Normal file
View file

@ -0,0 +1,415 @@
{
"nodes": {
"brew-api": {
"flake": false,
"locked": {
"lastModified": 1730777121,
"narHash": "sha256-VDIOrP02gNp8F/3C/eEI0kv9lkzzFAA/UtS+do9oOOg=",
"owner": "null2264",
"repo": "brew-api",
"rev": "9a1133bd9756788415ef3180d646bb6eb0f766fd",
"type": "github"
},
"original": {
"owner": "null2264",
"repo": "brew-api",
"type": "github"
}
},
"crane": {
"locked": {
"lastModified": 1728776144,
"narHash": "sha256-fROVjMcKRoGHofDm8dY3uDUtCMwUICh/KjBFQnuBzfg=",
"owner": "ipetkov",
"repo": "crane",
"rev": "f876e3d905b922502f031aeec1a84490122254b7",
"type": "github"
},
"original": {
"owner": "ipetkov",
"repo": "crane",
"type": "github"
}
},
"devshell": {
"inputs": {
"nixpkgs": [
"system-manager",
"nixpkgs"
]
},
"locked": {
"lastModified": 1728330715,
"narHash": "sha256-xRJ2nPOXb//u1jaBnDP56M7v5ldavjbtR6lfGqSvcKg=",
"owner": "numtide",
"repo": "devshell",
"rev": "dd6b80932022cea34a019e2bb32f6fa9e494dfef",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "devshell",
"type": "github"
}
},
"firefox-darwin": {
"inputs": {
"nixpkgs": [
"nixpkgs-stable"
]
},
"locked": {
"lastModified": 1730768115,
"narHash": "sha256-BbEg1w+y4+CrS5gFiR6YPGrXN0OvdyfOI8p1SgNnSzg=",
"owner": "bandithedoge",
"repo": "nixpkgs-firefox-darwin",
"rev": "4eb20be71869d6314ce7b383b63064140851d87a",
"type": "github"
},
"original": {
"owner": "bandithedoge",
"repo": "nixpkgs-firefox-darwin",
"type": "github"
}
},
"flake-compat": {
"flake": false,
"locked": {
"lastModified": 1696426674,
"narHash": "sha256-kvjfFW7WAETZlt09AgDn1MrtKzP7t90Vf7vypd3OL1U=",
"owner": "edolstra",
"repo": "flake-compat",
"rev": "0f9255e01c2351cc7d116c072cb317785dd33b33",
"type": "github"
},
"original": {
"owner": "edolstra",
"repo": "flake-compat",
"type": "github"
}
},
"flake-utils": {
"inputs": {
"systems": "systems"
},
"locked": {
"lastModified": 1726560853,
"narHash": "sha256-X6rJYSESBVr3hBoH0WbKE5KvhPU5bloyZ2L4K60/fPQ=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "c1dfcf08411b08f6b8615f7d8971a2bfa81d5e8a",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"flake-utils_2": {
"inputs": {
"systems": "systems_2"
},
"locked": {
"lastModified": 1726560853,
"narHash": "sha256-X6rJYSESBVr3hBoH0WbKE5KvhPU5bloyZ2L4K60/fPQ=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "c1dfcf08411b08f6b8615f7d8971a2bfa81d5e8a",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"gitignore": {
"inputs": {
"nixpkgs": [
"system-manager",
"pre-commit-hooks",
"nixpkgs"
]
},
"locked": {
"lastModified": 1709087332,
"narHash": "sha256-HG2cCnktfHsKV0s4XW83gU3F57gaTljL9KNSuG6bnQs=",
"owner": "hercules-ci",
"repo": "gitignore.nix",
"rev": "637db329424fd7e46cf4185293b9cc8c88c95394",
"type": "github"
},
"original": {
"owner": "hercules-ci",
"repo": "gitignore.nix",
"type": "github"
}
},
"home-manager": {
"inputs": {
"nixpkgs": [
"nixpkgs-unstable"
]
},
"locked": {
"lastModified": 1728791962,
"narHash": "sha256-nr5QiXwQcZmf6/auC1UpX8iAtINMtdi2mH+OkqJQVmU=",
"owner": "nix-community",
"repo": "home-manager",
"rev": "64c6325b28ebd708653dd41d88f306023f296184",
"type": "github"
},
"original": {
"owner": "nix-community",
"repo": "home-manager",
"rev": "64c6325b28ebd708653dd41d88f306023f296184",
"type": "github"
}
},
"nix-darwin": {
"inputs": {
"nixpkgs": [
"nixpkgs-stable"
]
},
"locked": {
"lastModified": 1730698801,
"narHash": "sha256-sq68bCmk4tCXSt5CoRNimfigIZSLJSpNi/gjFtNLjRE=",
"owner": "LnL7",
"repo": "nix-darwin",
"rev": "189d2d422c773fa065cc9c72e6806f007ebb9be0",
"type": "github"
},
"original": {
"owner": "LnL7",
"repo": "nix-darwin",
"rev": "189d2d422c773fa065cc9c72e6806f007ebb9be0",
"type": "github"
}
},
"nix-vm-test": {
"inputs": {
"nixpkgs": [
"system-manager",
"nixpkgs"
]
},
"locked": {
"lastModified": 1728287388,
"narHash": "sha256-hVqENyulDYzKT+UNLckXZnqGA8TgXZXQnCOdL2GbZoo=",
"owner": "numtide",
"repo": "nix-vm-test",
"rev": "aa5b18bb52d6cdfdfbfccfc4ddd8810f50608da3",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "nix-vm-test",
"type": "github"
}
},
"nixpkgs-stable": {
"locked": {
"lastModified": 1730765555,
"narHash": "sha256-yqWnDR56NbsXV3ojJRqR3u0Tzhz7PqE9/eX1nS+bQIE=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "20638fc713eba0765ede79a2dcedb414187c9343",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "release-24.05",
"repo": "nixpkgs",
"type": "github"
}
},
"nixpkgs-stable_2": {
"locked": {
"lastModified": 1720386169,
"narHash": "sha256-NGKVY4PjzwAa4upkGtAMz1npHGoRzWotlSnVlqI40mo=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "194846768975b7ad2c4988bdb82572c00222c0d7",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixos-24.05",
"repo": "nixpkgs",
"type": "github"
}
},
"nixpkgs-unstable": {
"locked": {
"lastModified": 1730272153,
"narHash": "sha256-B5WRZYsRlJgwVHIV6DvidFN7VX7Fg9uuwkRW9Ha8z+w=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "2d2a9ddbe3f2c00747398f3dc9b05f7f2ebb0f53",
"type": "github"
},
"original": {
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "2d2a9ddbe3f2c00747398f3dc9b05f7f2ebb0f53",
"type": "github"
}
},
"nur": {
"locked": {
"lastModified": 1730779796,
"narHash": "sha256-5J3jgJ923OdtEjyt3xFLyLkxGqGdn6oYUiC+dDCDL44=",
"owner": "nix-community",
"repo": "NUR",
"rev": "d17cb4d177a40e5cedc04719af56571e7ef643a7",
"type": "github"
},
"original": {
"owner": "nix-community",
"repo": "NUR",
"type": "github"
}
},
"pre-commit-hooks": {
"inputs": {
"flake-compat": "flake-compat",
"gitignore": "gitignore",
"nixpkgs": [
"system-manager",
"nixpkgs"
],
"nixpkgs-stable": "nixpkgs-stable_2"
},
"locked": {
"lastModified": 1728778939,
"narHash": "sha256-WybK5E3hpGxtCYtBwpRj1E9JoiVxe+8kX83snTNaFHE=",
"owner": "cachix",
"repo": "pre-commit-hooks.nix",
"rev": "ff68f91754be6f3427e4986d7949e6273659be1d",
"type": "github"
},
"original": {
"owner": "cachix",
"repo": "pre-commit-hooks.nix",
"type": "github"
}
},
"root": {
"inputs": {
"brew-api": "brew-api",
"firefox-darwin": "firefox-darwin",
"flake-utils": "flake-utils",
"home-manager": "home-manager",
"nix-darwin": "nix-darwin",
"nixpkgs-stable": "nixpkgs-stable",
"nixpkgs-unstable": "nixpkgs-unstable",
"nur": "nur",
"system-manager": "system-manager"
}
},
"rust-overlay": {
"inputs": {
"nixpkgs": [
"system-manager",
"nixpkgs"
]
},
"locked": {
"lastModified": 1728873041,
"narHash": "sha256-e4jz7yFADiZjMhv+iQwYtAN8AOUlOpbNQYnbwUFLjeM=",
"owner": "oxalica",
"repo": "rust-overlay",
"rev": "bdbe1611c2029de90bca372ce0b1e3b4fa65f55a",
"type": "github"
},
"original": {
"owner": "oxalica",
"repo": "rust-overlay",
"type": "github"
}
},
"system-manager": {
"inputs": {
"crane": "crane",
"devshell": "devshell",
"flake-utils": "flake-utils_2",
"nix-vm-test": "nix-vm-test",
"nixpkgs": [
"nixpkgs-stable"
],
"pre-commit-hooks": "pre-commit-hooks",
"rust-overlay": "rust-overlay",
"treefmt-nix": "treefmt-nix"
},
"locked": {
"lastModified": 1729365827,
"narHash": "sha256-VpLPjIS7F2/HyS6FVIXq4b9rtYV9Ab+4MmwRcJEjjjo=",
"owner": "numtide",
"repo": "system-manager",
"rev": "c93e62f2e962b54fd961798731d25eaa5778dbe2",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "system-manager",
"rev": "c93e62f2e962b54fd961798731d25eaa5778dbe2",
"type": "github"
}
},
"systems": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
},
"systems_2": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
},
"treefmt-nix": {
"inputs": {
"nixpkgs": [
"system-manager",
"nixpkgs"
]
},
"locked": {
"lastModified": 1727984844,
"narHash": "sha256-xpRqITAoD8rHlXQafYZOLvUXCF6cnZkPfoq67ThN0Hc=",
"owner": "numtide",
"repo": "treefmt-nix",
"rev": "4446c7a6fc0775df028c5a3f6727945ba8400e64",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "treefmt-nix",
"type": "github"
}
}
},
"root": "root",
"version": 7
}

66
nix/flake.nix Normal file
View file

@ -0,0 +1,66 @@
{
description = "null2264's Nix Setup";
outputs = inputs@{ self, nix-darwin, brew-api, nixpkgs-stable, nixpkgs-unstable, home-manager, system-manager, nur, ... }:
let
vars = {
floorp = {
verticalTabHoverWidthInEm = 18;
};
rev = self.rev or self.dirtyRev or null;
};
in
{
darwinConfigurations = (
import ./systems/darwin {
inherit (nixpkgs-unstable) lib;
inherit inputs nixpkgs-stable nixpkgs-unstable nix-darwin brew-api home-manager nur vars;
}
);
systemConfigs = ( # sudo is required, sadly
import ./systems/nix {
inherit (nixpkgs-unstable) lib;
inherit inputs nixpkgs-stable nixpkgs-unstable system-manager home-manager nur vars;
}
);
homeConfigurations = (
import ./users {
inherit (nixpkgs-unstable) lib;
inherit inputs nixpkgs-stable nixpkgs-unstable home-manager nur vars;
}
);
};
inputs = {
nixpkgs-stable.url = "github:NixOS/nixpkgs/release-24.05";
nixpkgs-unstable.url = "github:NixOS/nixpkgs/2d2a9ddbe3f2c00747398f3dc9b05f7f2ebb0f53";
flake-utils.url = "github:numtide/flake-utils";
nix-darwin = {
url = "github:LnL7/nix-darwin/189d2d422c773fa065cc9c72e6806f007ebb9be0";
inputs.nixpkgs.follows = "nixpkgs-stable";
};
firefox-darwin = {
url = "github:bandithedoge/nixpkgs-firefox-darwin";
inputs.nixpkgs.follows = "nixpkgs-stable";
};
brew-api = {
url = "github:null2264/brew-api";
flake = false;
};
home-manager = {
url = "github:nix-community/home-manager/64c6325b28ebd708653dd41d88f306023f296184";
inputs.nixpkgs.follows = "nixpkgs-unstable"; # we need unstable (24.11) for programs.floorp. FIXME: switch to stable once 24.11 become stable
};
system-manager = {
url = "github:numtide/system-manager/c93e62f2e962b54fd961798731d25eaa5778dbe2";
inputs.nixpkgs.follows = "nixpkgs-stable";
};
nur.url = "github:nix-community/NUR";
};
}

View file

@ -0,0 +1,10 @@
{ package, runCommandLocal, name }:
runCommandLocal "${name}-symlink" {}
''
dest="/usr/local/opt/${name}"
mkdir -p $dest
ln -sf "${package.out}/lib/" "$dest" && mkdir -p "$out" && touch "$out/${name}-done"
''

22
nix/lib/darwin/mkApp.nix Normal file
View file

@ -0,0 +1,22 @@
# REF: https://github.com/bandithedoge/nixpkgs-firefox-darwin/blob/ceaca2359e5371ccef3f92a36baf7c438b354afb/overlay.nix
{ stdenv, undmg, _7zz, pname, version, sourceRoot ? ".", appFileName, src, meta
, nativeBuildInputs ? [ undmg _7zz ]
, unpackPhase ? "undmg $src || 7zz x -snld $src"
, installPhase ? ''
mkdir -p $out/Applications
cp -R ${appFileName} "$out/Applications/"
''
}:
stdenv.mkDerivation rec {
inherit pname version;
inherit src nativeBuildInputs;
inherit sourceRoot;
phases = [ "unpackPhase" "installPhase" ];
inherit unpackPhase installPhase;
inherit meta;
}

21
nix/lib/mkCommon.nix Normal file
View file

@ -0,0 +1,21 @@
{ pkgs, pkgs-unstable, ... }:
let
custom = {
python = (pkgs.python312Full.withPackages (py: [
py.pip
py.tkinter
py.dnspython
]));
};
custom.inkscape = if pkgs.stdenv.isDarwin then pkgs.casks.inkscape else (pkgs.inkscape.override { python3 = custom.python; });
in {
inherit custom;
packages = [
pkgs.zsh
pkgs.home-manager
pkgs.zoxide
pkgs.ruby
pkgs._7zz
];
}

29
nix/lib/mkSystem.nix Normal file
View file

@ -0,0 +1,29 @@
{ arch, stable, unstable, nur, extraOverlays ? [] }:
let
overlays = [
(import ../overlays/python.nix)
] ++ extraOverlays;
# Placed here so that we don't need to specify hash for fetchTarball
packageOverrides = pkgs: {
nur = import nur {
nurpkgs = pkgs;
inherit pkgs;
};
};
in {
system = arch;
pkgs = import stable {
system = arch;
inherit overlays;
config.allowUnfree = true;
config.packageOverrides = packageOverrides;
};
pkgs-unstable = import unstable {
system = arch;
inherit overlays;
config.allowUnfree = true;
# config.packageOverrides = packageOverrides;
};
}

View file

@ -0,0 +1,13 @@
{ pkgs, config, vars, ... }:
{
programs.floorp = {
enable = true;
# REF: https://github.com/nix-community/home-manager/blob/342a1d682386d3a1d74f9555cb327f2f311dda6e/modules/programs/firefox/mkFirefoxModule.nix#L264
package = null; # we only want the config
profiles.${config.home.username} = {
id = 0;
isDefault = true;
};
};
}

View file

@ -0,0 +1,105 @@
# Modified version of brew-nix/casks.nix
#
# REF: https://github.com/BatteredBunny/brew-nix/blob/9dfab294afea5029922bbc59a10ae487c7318d59/casks.nix
{ system, mac-version ? "ventura", nixpkgs, brew-api, ... }:
let
pkgs = import nixpkgs {
inherit system;
};
hasBinary = cask: pkgs.lib.hasAttr "binary" (getArtifacts cask);
hasApp = cask: pkgs.lib.hasAttr "app" (getArtifacts cask);
hasPkg = cask: pkgs.lib.hasAttr "pkg" (getArtifacts cask);
getName = cask: builtins.elemAt cask.name 0;
getBinary = cask: builtins.elemAt (getArtifacts cask).binary 0;
getApp = cask: builtins.elemAt (getArtifacts cask).app 0;
getArtifacts = cask: pkgs.lib.mergeAttrsList cask.artifacts;
getUrl = cask: (cask.variations.${mac-version} or cask).url;
getHash = cask: (cask.variations.${mac-version} or cask).sha256; # TODO: convert it to SRI
caskToDerivation = cask: pkgs.stdenv.mkDerivation rec {
pname = cask.token;
version = cask.version;
src = pkgs.fetchurl {
url = (getUrl cask);
sha256 = pkgs.lib.optionalString ((getHash cask) != "no_check") (getHash cask);
};
nativeBuildInputs = with pkgs; [
undmg
unzip
gzip
_7zz
makeWrapper
] ++ pkgs.lib.optional (hasPkg cask) (with pkgs; [
xar
cpio
]);
unpackPhase =
if (hasPkg cask) then ''
xar -xf $src
for pkg in $(cat Distribution | grep -oE "#.+\.pkg" | sed -e "s/^#//" -e "s/$/\/Payload/"); do
zcat $pkg | cpio -i
done
'' else if (hasApp cask) then ''
undmg $src || 7zz x -snld $src
'' else if (hasBinary cask) then ''
if [ "$(file --mime-type -b "$src")" == "application/gzip" ]; then
gunzip $src -c > ${getBinary cask}
elif [ "$(file --mime-type -b "$src")" == "application/x-mach-binary" ]; then
cp $src ${getBinary cask}
fi
'' else "";
sourceRoot = pkgs.lib.optionalString (hasApp cask) (getApp cask);
installPhase =
if (hasPkg cask) then ''
mkdir -p $out/Applications
cp -R Applications/* $out/Applications/
if [ -d "Resources" ]; then
mkdir -p $out/Resources
cp -R Resources/* $out/Resources/
fi
if [ -d "Library" ]; then
mkdir -p $out/Library
cp -R Library/* $out/Library/
fi
'' else if (hasApp cask) then ''
mkdir -p "$out/Applications/${sourceRoot}"
cp -R . "$out/Applications/${sourceRoot}"
if [[ -e "$out/Applications/${sourceRoot}/Contents/MacOS/${getName cask}" ]]; then
makeWrapper "$out/Applications/${sourceRoot}/Contents/MacOS/${getName cask}" $out/bin/${cask.token}
elif [[ -e "$out/Applications/${sourceRoot}/Contents/MacOS/${pkgs.lib.removeSuffix ".app" sourceRoot}" ]]; then
makeWrapper "$out/Applications/${sourceRoot}/Contents/MacOS/${pkgs.lib.removeSuffix ".app" sourceRoot}" $out/bin/${cask.token}
fi
'' else if (hasBinary cask && !hasApp cask) then ''
mkdir -p $out/bin
cp -R ./* $out/bin
'' else "";
meta = {
homepage = cask.homepage;
description = cask.desc;
platforms = pkgs.lib.platforms.darwin;
mainProgram = if (hasBinary cask && !hasApp cask) then (getBinary cask) else (cask.token);
};
};
casks = builtins.fromJSON (builtins.readFile (brew-api + "/cask.json"));
in final: prev: {
casks = builtins.listToAttrs (builtins.map
(cask: {
name = cask.token;
value = caskToDerivation cask;
})
casks);
}

View file

@ -0,0 +1,28 @@
# REF: https://github.com/bandithedoge/nixpkgs-firefox-darwin/blob/ceaca2359e5371ccef3f92a36baf7c438b354afb/overlay.nix
final: prev:
let
mkApp = import ../../lib/darwin/mkApp.nix;
version = "1.5.0";
in {
heliport = mkApp {
inherit (final) stdenv undmg _7zz;
pname = "HeliPort";
appFileName = "HeliPort.app";
inherit version;
src = final.fetchurl {
url = "https://github.com/OpenIntelWireless/HeliPort/releases/download/v${version}/HeliPort.dmg";
sha256 = "49cbe7abea742a3c662a836f14c05b79b3e6e6577c897b57101f5bd0a086eec8";
};
meta = with final.lib; {
description = "Intel WiFi Client for itlwm";
homepage = "https://github.com/OpenIntelWireless/HeliPort";
license = licenses.bsd3;
platforms = platforms.darwin;
sourceProvenance = with sourceTypes; [ binaryNativeCode ];
};
};
}

View file

@ -0,0 +1,28 @@
# REF: https://github.com/bandithedoge/nixpkgs-firefox-darwin/blob/ceaca2359e5371ccef3f92a36baf7c438b354afb/overlay.nix
final: prev:
let
mkApp = import ../../lib/darwin/mkApp.nix;
version = "1.5.3";
in {
vesktop = mkApp {
inherit (final) stdenv undmg _7zz;
pname = "Vesktop";
appFileName = "Vesktop*.app";
inherit version;
src = final.fetchurl {
url = "https://github.com/Vencord/Vesktop/releases/download/v${version}/Vesktop-${version}-universal.dmg";
hash = "sha256-ceOUNHSOaEqCbzkM64RtUu0Yhrq4tThcXZTDd+OsEXI";
};
meta = with final.lib; {
description = "An alternate client for Discord with Vencord built-in";
homepage = "https://github.com/Vencord/Vesktop";
license = licenses.gpl3Only;
platforms = platforms.darwin;
sourceProvenance = with sourceTypes; [ binaryNativeCode ];
};
};
}

21
nix/overlays/python.nix Normal file
View file

@ -0,0 +1,21 @@
final: prev:
let
disablePyChecks = pkg: pkg.overridePythonAttrs (old: {
doCheck = false;
doInstallCheck = false;
dontCheck = true;
});
in {
pythonPackagesExtensions = prev.pythonPackagesExtensions ++ [
(pyfinal: pyprev: {
dnspython = (disablePyChecks pyprev.dnspython).overridePythonAttrs (old: {
disabledTests = [
"test_resolver" # Relying too much on internet connection, Indonesian internet couldn't cope with it
] ++ old.disabledTests;
});
pillow = disablePyChecks pyprev.pillow; # Inconsistent test result
cherrypy = disablePyChecks pyprev.cherrypy; # Inconsistent test result
})
];
}

View file

@ -0,0 +1,105 @@
{ pkgs, pkgs-unstable, config, vars, common, inputs, ... }:
let
libFixup = import ../../lib/darwin/libFixup.nix;
in {
# I don't want to risk breaking my hackintosh setup in case Apple decided to
# turn on auto install by default.
system.defaults.SoftwareUpdate.AutomaticallyInstallMacOSUpdates = false;
# NOTE: List packages installed in system profile. To search by name, run:
# `nix-env -qaP | grep wget`
environment.systemPackages =
common.packages ++ [
pkgs.git
pkgs.vim
pkgs.neovim
pkgs.htop-vim
pkgs.wget
pkgs.eza
pkgs.coreutils-full
pkgs.rclone
pkgs.fastfetch
pkgs.casks.iterm2
pkgs.nmap
pkgs.cargo
pkgs.android-tools
pkgs.duti
pkgs.undmg
pkgs.mkalias
pkgs.jq
# lan-mouse deps
(libFixup { package = pkgs.libadwaita; inherit (pkgs) runCommandLocal; name = "libadwaita"; })
(libFixup { package = pkgs.gtk4; inherit (pkgs) runCommandLocal; name = "gtk4"; })
(libFixup { package = pkgs.pango; inherit (pkgs) runCommandLocal; name = "pango"; })
(libFixup { package = pkgs.harfbuzz; inherit (pkgs) runCommandLocal; name = "harfbuzz"; })
(libFixup { package = pkgs.gdk-pixbuf; inherit (pkgs) runCommandLocal; name = "gdk-pixbuf"; })
(libFixup { package = pkgs.cairo; inherit (pkgs) runCommandLocal; name = "cairo"; })
(libFixup { package = pkgs.graphene; inherit (pkgs) runCommandLocal; name = "graphene"; })
(libFixup { package = pkgs.glib; inherit (pkgs) runCommandLocal; name = "glib"; })
(libFixup { package = pkgs.gettext; inherit (pkgs) runCommandLocal; name = "gettext"; })
pkgs.pass
pkgs.passExtensions.pass-otp
pkgs.gnupg
pkgs.pinentry_mac
common.custom.python
#(pkgs.poetry.override { python3 = common.custom.python; })
pkgs.wimlib
pkgs.google-cloud-sdk
(pkgs.yt-dlp.override { withAlias = true; })
pkgs.iina
pkgs.floorp-bin
common.custom.inkscape
pkgs.casks.zotero
# pkgs.casks.lulu # Doesn't work, it needs to be installed on /Applications/
# pkgs.heliport # FIXME: https://github.com/matthewbauer/undmg/issues/2
pkgs.vesktop
pkgs.lf
pkgs.yazi # lf replacement, need further testing
];
# Auto upgrade nix package and the daemon service.
services.nix-daemon.enable = true;
nix = {
package = pkgs.nix;
settings.experimental-features = "nix-command flakes"; # stopping nix from crying about using experimental features flakes and nix-command
};
# Create /etc/zshrc that loads the nix-darwin environment.
programs.zsh.enableCompletion = false; # causing "insecure directories and files" error if user doesn't have configured zsh
# Set Git commit hash for darwin-version.
system.configurationRevision = vars.rev or null;
# Used for backwards compatibility, please read the changelog before changing.
# $ darwin-rebuild changelog
system = {
stateVersion = 4;
# Nix-darwin does not link installed applications to the user environment. This means apps will not show up
# in spotlight, and when launched through the dock they come with a terminal window. This is a workaround.
# Upstream issue: https://github.com/LnL7/nix-darwin/issues/214
# Original code: https://github.com/IvarWithoutBones/dotfiles/commit/0b3faad8bd1d0e1af6103caf59b206666ab742f4
activationScripts.applications.text = let
env = pkgs.buildEnv {
name = "system-applications";
paths = config.environment.systemPackages;
pathsToLink = "/Applications";
};
in pkgs.lib.mkForce ''
echo "setting up /Applications..." >&2
rm -rf "/Applications/Nix Apps"
mkdir -p "/Applications/Nix Apps"
find ${env}/Applications -maxdepth 1 -type l -exec readlink '{}' + |
while read src; do
app_name=$(basename "$src")
echo "copying $src" >&2
${pkgs.mkalias}/bin/mkalias "$src" "/Applications/Nix Apps/$app_name"
done
'';
};
}

View file

@ -0,0 +1,68 @@
{ inputs, nixpkgs-stable, nixpkgs-unstable, nix-darwin, brew-api, nur, vars, ... }:
let
mkCommon = import ../../lib/mkCommon.nix;
mkSystem = import ../../lib/mkSystem.nix;
mkBrew = import ../../overlays/darwin/brew.nix;
in
{
# Host list
# Build with darwin flake: `darwin-rebuild build --flake .#<host>`
# e.g. `darwin-rebuild build --flake .#"ThiccBook-Pro"`
# Switch to current build: `darwin-rebuild switch --flake .#<host>`
# Lenovo ThinkPad L460; Intel Core i5-6300U
"ThiccBook-Pro" =
let
system = "x86_64-darwin";
inherit (
mkSystem {
arch = system;
stable = nixpkgs-stable;
unstable = nixpkgs-unstable;
extraOverlays = [
inputs.firefox-darwin.overlay
(mkBrew { inherit system brew-api; nixpkgs = nixpkgs-stable; })
(import ../../overlays/darwin/heliport.nix)
(import ../../overlays/darwin/vesktop.nix)
];
nur = nur;
}
) pkgs pkgs-unstable;
common = (mkCommon { inherit pkgs pkgs-unstable; });
in
nix-darwin.lib.darwinSystem {
inherit system;
specialArgs = { inherit inputs pkgs pkgs-unstable vars common; };
modules = [
./configuration.nix
];
};
# Imaginary M1, just for reference
MacBookProM1 =
let
system = "aarch64-darwin";
inherit (
mkSystem {
arch = system;
stable = nixpkgs-stable;
unstable = nixpkgs-unstable;
extraOverlays = [
inputs.firefox-darwin.overlay
(mkBrew { inherit system brew-api; nixpkgs = nixpkgs-stable; })
(import ../../overlays/darwin/vesktop.nix)
];
nur = nur;
}
) pkgs pkgs-unstable;
common = (mkCommon { inherit pkgs pkgs-unstable; });
in
nix-darwin.lib.darwinSystem {
inherit system;
specialArgs = { inherit inputs pkgs pkgs-unstable vars common; };
modules = [
./configuration.nix
];
};
}

View file

@ -0,0 +1,26 @@
{ inputs, nixpkgs-stable, nixpkgs-unstable, system-manager, nur, vars, ... }:
let
mkCommon = import ../../lib/mkCommon.nix;
mkSystem = import ../../lib/mkSystem.nix;
in
{
"potato" =
let
inherit (
mkSystem {
arch = "x86_64-linux";
stable = nixpkgs-stable;
unstable = nixpkgs-unstable;
nur = nur;
}
) system pkgs pkgs-unstable;
common = (mkCommon { inherit pkgs pkgs-unstable; });
in
system-manager.lib.makeSystemConfig {
extraSpecialArgs = { inherit inputs pkgs pkgs-unstable vars common; };
modules = [
./potato
];
};
}

View file

@ -0,0 +1,25 @@
{ pkgs, pkgs-unstable, config, vars, common, ... }:
{
config = {
system-manager.allowAnyDistro = true;
# NOTE: List packages installed in system profile. To search by name, run:
# `nix-env -qaP | grep wget`
environment = {
etc = {
"nix/nix.conf".text =
''
trusted-users = [ root @wheel ]
experimental-features = nix-command flakes
build-users-group = nixbld
'';
};
systemPackages =
common.packages ++ [
];
};
nixpkgs.hostPlatform = pkgs.system;
};
}

67
nix/users/default.nix Normal file
View file

@ -0,0 +1,67 @@
{ inputs, nixpkgs-stable, nixpkgs-unstable, home-manager, nur, vars, ... }:
let
mkSystem = import ../lib/mkSystem.nix;
mkBrew = import ../overlays/darwin/brew.nix;
in
{
# Host list
# Build with: `home-manager build --flake .#<user>@<host>`
# e.g. `home-manager build --flake .#"ziro@ThiccBook-Pro"`
# Switch to current build: `home-manager switch --flake .#<user>@<host>`
#
# If you're feeling lucky `home-manager build --flake .` or
# `home-manager switch --flake .` should be enough, since home-manager will
# search the correct <user>@<host> on its own.
#
# You may need to run `scutil --set HostName <host>` if home-manager can't
# find your <user>@<host>.
"ziro@ThiccBook-Pro" =
let
system = "x86_64-darwin";
inherit (
mkSystem {
arch = system;
stable = nixpkgs-stable;
unstable = nixpkgs-unstable;
extraOverlays = [
inputs.firefox-darwin.overlay
(mkBrew { inherit system; brew-api = inputs.brew-api; nixpkgs = nixpkgs-stable; })
];
nur = nur;
}
) pkgs pkgs-unstable;
vars.floorp.verticalTabHoverWidthInEm = 28;
in
home-manager.lib.homeManagerConfiguration {
pkgs = pkgs-unstable; # FIXME: switch to stable when 24.11 become stable
extraSpecialArgs = { inherit inputs pkgs pkgs-unstable home-manager vars; };
modules = [
./ziro
./ziro/darwin.nix
../modules/home-manager/floorp.nix
];
};
"ziro@potato" =
let
inherit (
mkSystem {
arch = "x86_64-linux";
stable = nixpkgs-stable;
unstable = nixpkgs-unstable;
nur = nur;
}
) system pkgs pkgs-unstable;
in
home-manager.lib.homeManagerConfiguration {
pkgs = pkgs-unstable; # FIXME: switch to stable when 24.11 become stable
extraSpecialArgs = { inherit inputs pkgs pkgs-unstable home-manager vars; };
modules = [
./ziro
./ziro/linux.nix
../modules/home-manager/floorp.nix
];
};
}

50
nix/users/ziro/darwin.nix Normal file
View file

@ -0,0 +1,50 @@
{ pkgs, pkgs-unstable, config, vars, lib, ... }:
{
home.homeDirectory = "/Users/ziro";
home.packages = lib.mkAfter
[
pkgs.casks.vscodium
];
programs.browserpass = {
enable = true;
browsers = [ "brave" "chrome" ]; # Arc and Chrome share the same `Application Support` dir, not sure why tbh.
};
home.file."Library/Application Support/Floorp/native-messaging-hosts/passff.json".source = "${pkgs.passff-host}/share/passff-host/passff.json";
# Swap CapsLock with Esc for better vi-mode experience.
launchd.agents.CapsEscSwap = {
enable = true;
config = {
ProgramArguments = [
"/usr/bin/hidutil"
"property"
"--set"
''{"UserKeyMapping":[{"HIDKeyboardModifierMappingSrc":0x700000039,"HIDKeyboardModifierMappingDst":0x700000029},{"HIDKeyboardModifierMappingSrc":0x700000029,"HIDKeyboardModifierMappingDst":0x700000039}]}''
];
RunAtLoad = true;
};
};
home.sessionVariables.MOZ_LEGACY_PROFILES = 1;
home.activation.applications = let
env = pkgs.buildEnv {
name = "home-applications";
paths = config.home.packages;
pathsToLink = "/Applications";
};
in lib.hm.dag.entryAfter [ "writeBoundary" ] ''
echo "setting up ${config.home.homeDirectory}/Applications..." >&2
rm -rf "${config.home.homeDirectory}/Applications/Nix Home Manager Apps"
mkdir -p "${config.home.homeDirectory}/Applications/Nix Home Manager Apps"
find ${env}/Applications -maxdepth 1 -type l -exec readlink '{}' + |
while read src; do
app_name=$(basename "$src")
echo "copying $src" >&2
${pkgs.mkalias}/bin/mkalias "$src" "${config.home.homeDirectory}/Applications/Nix Home Manager Apps/$app_name"
done
'';
}

View file

@ -0,0 +1,48 @@
{ pkgs, pkgs-unstable, config, vars, ... }:
let
username = "ziro";
userChrome = builtins.replaceStrings ["/*ZI:VERTICAL-TAB-HOVER-WIDTH-IN-EM*/"] ["${builtins.toString vars.floorp.verticalTabHoverWidthInEm}em"] (builtins.readFile ../../files/floorp/ziro-userChrome.css);
settings = {
"browser.toolbars.bookmarks.visibility" = "newtab";
"floorp.browser.sidebar.is.displayed" = false;
"floorp.browser.tabbar.settings" = 2;
"floorp.browser.tabs.verticaltab" = true;
"floorp.verticaltab.hover.enabled" = true;
"floorp.tabbar.style" = 2;
"network.dns.disableIPv6" = true;
"sidebar.position_start" = false;
"signon.management.page.breach-alerts.enabled" = false;
"signon.rememberSignons" = false;
"extensions.autoDisableScopes" = 0; # Auto enable extensions
};
extensions = with pkgs.nur.repos.rycee.firefox-addons; [
passff
ublock-origin
];
in {
home = {
inherit username;
packages =
[
pkgs.passff-host
];
};
programs.floorp.profiles.${username} = {
inherit userChrome settings extensions;
};
programs.floorp.profiles.null = {
id = 1;
inherit userChrome settings extensions;
};
xdg.configFile = {
"nix/nix.conf".text =
''
experimental-features = nix-command flakes
'';
};
home.stateVersion = "24.11";
}

7
nix/users/ziro/linux.nix Normal file
View file

@ -0,0 +1,7 @@
{ pkgs, pkgs-unstable, config, vars, ... }:
{
home.homeDirectory = "/home/ziro";
home.file.".floorp/native-messaging-hosts/passff.json".source = "${pkgs.passff-host}/share/passff-host/passff.json";
}