[nix] Redo and restructure the entire config

Thanks @KaitlynEthylia :)
This commit is contained in:
Alyxia Sother 2024-07-11 19:07:47 +02:00
parent 19b92cd8fd
commit 2daf5f1b05
No known key found for this signature in database
GPG Key ID: 01E16C4E775A37E4
13 changed files with 378 additions and 302 deletions

View File

@ -30,12 +30,45 @@
"revCount": 473, "revCount": 473,
"submodules": true, "submodules": true,
"type": "git", "type": "git",
"url": "https://github.com/keanuplayz/dotfiles" "url": "https://github.com/lexisother/dotfiles"
}, },
"original": { "original": {
"submodules": true, "submodules": true,
"type": "git", "type": "git",
"url": "https://github.com/keanuplayz/dotfiles" "url": "https://github.com/lexisother/dotfiles"
}
},
"flake-utils": {
"inputs": {
"systems": "systems"
},
"locked": {
"lastModified": 1710146030,
"narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"flakey-profile": {
"locked": {
"lastModified": 1712898590,
"narHash": "sha256-FhGIEU93VHAChKEXx905TSiPZKga69bWl1VB37FK//I=",
"owner": "lf-",
"repo": "flakey-profile",
"rev": "243c903fd8eadc0f63d205665a92d4df91d42d9d",
"type": "github"
},
"original": {
"owner": "lf-",
"repo": "flakey-profile",
"type": "github"
} }
}, },
"home-manager": { "home-manager": {
@ -59,6 +92,43 @@
"type": "github" "type": "github"
} }
}, },
"lix": {
"inputs": {
"flake-utils": "flake-utils",
"flakey-profile": "flakey-profile",
"lix": "lix_2",
"nixpkgs": [
"nixpkgs"
]
},
"locked": {
"lastModified": 1719353937,
"narHash": "sha256-86NBqDxAP20ET/UoKX0WvSItblNQ97czXb2q7lkMrwk=",
"ref": "refs/heads/main",
"rev": "5d9d94089fb1ca96222a34bfe245ef5c5ebefd37",
"revCount": 92,
"type": "git",
"url": "https://git.lix.systems/lix-project/nixos-module"
},
"original": {
"type": "git",
"url": "https://git.lix.systems/lix-project/nixos-module"
}
},
"lix_2": {
"flake": false,
"locked": {
"lastModified": 1718767907,
"narHash": "sha256-gpd+mGQxqVHw2kO6rSPQel8TkChHh9UpqxjsmQi0QJM=",
"rev": "85f282ef572577899b3d80ba8def1b920a386218",
"type": "tarball",
"url": "https://git.lix.systems/api/v1/repos/lix-project/lix/archive/85f282ef572577899b3d80ba8def1b920a386218.tar.gz"
},
"original": {
"type": "tarball",
"url": "https://git.lix.systems/lix-project/lix/archive/main.tar.gz"
}
},
"nixpkgs": { "nixpkgs": {
"locked": { "locked": {
"lastModified": 1720492477, "lastModified": 1720492477,
@ -80,8 +150,24 @@
"darwin": "darwin", "darwin": "darwin",
"dotfiles": "dotfiles", "dotfiles": "dotfiles",
"home-manager": "home-manager", "home-manager": "home-manager",
"lix": "lix",
"nixpkgs": "nixpkgs" "nixpkgs": "nixpkgs"
} }
},
"systems": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
} }
}, },
"root": "root", "root": "root",

View File

@ -4,26 +4,52 @@
inputs = { inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-24.05-darwin"; nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-24.05-darwin";
home-manager.url = "github:nix-community/home-manager/release-24.05"; home-manager.url = "github:nix-community/home-manager/release-24.05";
home-manager.inputs.nixpkgs.follows = "nixpkgs";
# nix will normally use the nixpkgs defined in home-managers inputs, we only want one copy of nixpkgs though
darwin.url = "github:lnl7/nix-darwin"; darwin.url = "github:lnl7/nix-darwin";
darwin.inputs.nixpkgs.follows = "nixpkgs"; # ... lix.url = "git+https://git.lix.systems/lix-project/nixos-module";
dotfiles = { dotfiles = {
url = "https://github.com/keanuplayz/dotfiles"; url = "https://github.com/lexisother/dotfiles";
type = "git"; type = "git";
submodules = true; submodules = true;
flake = false; flake = false;
}; };
home-manager.inputs.nixpkgs.follows = "nixpkgs";
darwin.inputs.nixpkgs.follows = "nixpkgs";
lix.inputs.nixpkgs.follows = "nixpkgs";
}; };
# add the inputs declared above to the argument attribute set # add the inputs declared above to the argument attribute set
outputs = { self, nixpkgs, home-manager, dotfiles, darwin }: { outputs = { self, nixpkgs, lix, home-manager, dotfiles, darwin }: let
system = "x86_64-darwin";
importAll = path: map
(p: import (path + ("/" + p)))
(builtins.attrNames (builtins.readDir path));
pkgs = import nixpkgs {
inherit system;
overlays = importAll ./overlays;
};
libs = with builtins; listToAttrs (map
(path: {
name = replaceStrings [".nix"] [""] path;
value = (import (pkgs.lib.path.append ./lib path)) { inherit pkgs; };
})
(attrNames (readDir ./lib)));
in {
darwinConfigurations."alymac" = darwin.lib.darwinSystem { darwinConfigurations."alymac" = darwin.lib.darwinSystem {
system = "x86_64-darwin"; inherit system;
specialArgs = { inherit self; inherit dotfiles; }; specialArgs = libs;
modules = [ modules = [
./system
lix.nixosModules.default
home-manager.darwinModules.home-manager home-manager.darwinModules.home-manager
./hosts/alymac/default.nix {
home-manager = {
extraSpecialArgs = { inherit self; inherit dotfiles; } // libs;
useGlobalPkgs = true;
useUserPackages = true;
users.alyxia.imports = [ ./home ];
};
}
]; ];
}; };
}; };

7
nix/home/default.nix Normal file
View File

@ -0,0 +1,7 @@
{ importAll, ... }:
{
imports = importAll [] ./.;
home.stateVersion = "24.05";
}

93
nix/home/packages.nix Normal file
View File

@ -0,0 +1,93 @@
{ pkgs, ... }:
let
packageSets = with pkgs; {
system = [
gnutls
gsasl
libtool
patchelf
pcre
pkg-config
];
base = [
act
bat
bitwarden-cli
cloudflared
delta
eza
ffmpeg
fzf
gh
git-crypt
gitui
gnupg
jq
kubectl
kubelogin-oidc
mosh
nixpkgs-fmt
pandoc
ripgrep
sops
stylua
texlive.combined.scheme-small
typst
vim
wget
# Fyra
glib-networking
meson
ninja
vala
desktop-file-utils
];
languages = [
crystal
dhall
dhall-json
dhall-lsp-server
go
jdk
kotlin
kotlin-language-server
lua-language-server
nil
nodejs_20
python2
ruby_3_1
sbcl
shards
zig
];
programs = [
rectangle
tailscale
];
multimedia = [
ffmpeg
];
fonts = [
nerdfonts
ibm-plex
];
python = with python311Packages; [
colorama
psutil
distro
];
};
everything = builtins.concatLists (builtins.attrValues packageSets);
in
{
home.packages = everything;
}

View File

@ -10,8 +10,11 @@
[[ -d "$HOME/.local/bin" ]] || mkdir "$HOME/.local/bin" [[ -d "$HOME/.local/bin" ]] || mkdir "$HOME/.local/bin"
export PATH="/Library/Developer/CommandLineTools/usr/bin:$PATH"
export PATH="$PATH:$HOME/.local/bin" export PATH="$PATH:$HOME/.local/bin"
export PATH="$PATH:$HOME/.npm-packages/bin" export PATH="$PATH:$HOME/.npm-packages/bin"
export PATH="$PATH:$HOME/.dotnet/tools"
export PATH="$PATH:$HOME/.config/composer/vendor/bin"
export FRENYARD_SCALE=2.40 export FRENYARD_SCALE=2.40
export RETHINK_API="https://rethink.alyxia.dev" export RETHINK_API="https://rethink.alyxia.dev"
export KUBECONFIG="$HOME/.kube/config.yaml" export KUBECONFIG="$HOME/.kube/config.yaml"

View File

@ -1,292 +0,0 @@
{ self, pkgs, lib, dotfiles, ... }:
with lib;
let
textEditor = "nvim";
packageSets = with pkgs; rec {
system = [
gnutls
gsasl
libtool
patchelf
pcre
pkg-config
];
base = [
act
bat
bitwarden-cli
cloudflared
delta
eza
ffmpeg
fzf
gh
git-crypt
gitui
gnupg
jq
kubectl
kubelogin-oidc
mosh
nixpkgs-fmt
pandoc
ripgrep
sops
stylua
texlive.combined.scheme-small
typst
vim
wget
# Fyra
glib-networking
meson
ninja
vala
desktop-file-utils
];
languages = [
crystal
dhall
dhall-json
dhall-lsp-server
go
jdk
kotlin
kotlin-language-server
lua-language-server
nil
nodejs_20
python2
ruby_3_1
sbcl
shards
zig
];
programs = [
rectangle
tailscale
];
multimedia = [
ffmpeg
];
fonts = [
nerdfonts
ibm-plex
];
python = with python311Packages; [
colorama
psutil
distro
];
everything = system ++ base ++ languages ++ programs ++ multimedia ++ fonts ++ python;
};
# Old solution kept for posterity {{{
# We've got a small issue here. I tested this in a repl, and what I've
# observed is that listFilesRecursive spits out [ /full/path/to/default.nix ],
# while builtins.readDir spits out { "default.nix" = "regular"; }
# In theory, this shouldn't be much of an issue, however, when using readDir
# I would be able to do `map (n: "${./.}/${n}"), while when using
# listFilesRecursive I have to use `map (n: "${n}").
# The difference here is that when using listFilesRecursive, `n` becomes
# `/nix/store/<ID>-default.nix`, meaning it can be used as-is, but when using
# `readDir` it becomes `default.nix`, meaning the string used in the map
# callback must be `"${./.}/${n}"` to get a path to the current derivation
# where the nix file lives in.
# Currently, I am unsure of the implications of having all files separately.
# To do it "the right way" I'd obviously prefer the nix files to be children
# of the alymac derivation, but it seems that if I want my map of imports to
# be generated from the entire directory listing, it isn't going to work out.
# The solution was slightly modified from this Reddit answer:
# <https://www.reddit.com/r/NixOS/comments/j5pa9o/comment/g81dvop/>
# importMap = map
# (n: "${n}")
# (lib.filesystem.listFilesRecursive ./.);
# importsFiltered =
# builtins.filter
# (x: !lib.strings.hasInfix "default" x)
# importMap;
# }}}
getDir = dir: mapAttrs
(file: type:
if type == "directory" then getDir "${dir}/${file}" else type
)
(builtins.readDir dir);
files = dir: collect isString (mapAttrsRecursive
(path: type: concatStringsSep "/" path)
(getDir dir));
validFiles = dir: map
(file: ./. + "/${file}")
(filter
(file: hasSuffix ".nix" file && file != "default.nix")
(files dir));
in
{
nix = {
# package = pkgs.nix;
package = pkgs.lix.overrideAttrs (oldAttrs: {
postPatch = (oldAttrs.postPatch or "") + ''
substituteInPlace src/libmain/shared.cc \
--replace-fail "(Lix, like Nix)" "but for lesbians"
'';
});
settings = {
experimental-features = [ "nix-command" "flakes" ];
build-users-group = "nixbld";
};
gc = {
automatic = true;
options = "--delete-older-than 8d";
};
};
# Absolutely proprietary.
nixpkgs.config.allowUnfree = true;
nixpkgs.config.permittedInsecurePackages = [
"python-2.7.18.8"
];
# Make sure the nix daemon always runs
services.nix-daemon.enable = true;
# enable the gpg agent by default
programs.gnupg.agent.enable = true;
# if you use zsh (the default on new macOS installations),
# you'll need to enable this so nix-darwin creates a zshrc sourcing needed environment changes
programs.zsh.enable = true;
# tailscaled isn't automatically registered as a service that should run on installation.
services.tailscale.enable = true;
# Make sure to set the correct values, or everything will break! (in reality,
# it will just not build)
users.users.alyxia = {
name = "alyxia";
home = "/Users/alyxia";
};
home-manager = {
useGlobalPkgs = true;
useUserPackages = true;
extraSpecialArgs = { inherit self; inherit dotfiles; };
users.alyxia = { pkgs, ... }: {
# Defined further above, generates a list of files to import.
imports = validFiles ./.;
home = {
packages = packageSets.everything;
sessionVariables = {
EDITOR = textEditor;
};
file.".npmrc".text = ''
prefix = ''${HOME}/.npm-packages
'';
};
# DO NOT CHANGE UNLESS YOU ARE ABSOLUTELY SURE ALL STATE AFFECTED BY THIS
# OPTION IS APPROPRIATELY MIGRATED!!!
home.stateVersion = "23.05"; # did you read the comment?
};
};
homebrew = {
enable = true;
onActivation = {
autoUpdate = true;
cleanup = "zap";
upgrade = true;
};
taps = [
"drud/ddev"
"homebrew/cask-versions"
"int128/kubelogin"
];
# Please do not the brew.
brews = [
"bear"
"composer"
"croc"
"ddev"
"deno"
"dotnet"
"ferium"
"gradle"
"kubelogin"
"mkcert"
"nss"
"pinentry-mac"
"pkg-config"
"poetry"
"rustup"
"sdl2"
# Fyra crap, but from Homebrew because someone doesn't know how to
# package libraries in nixpkgs
"appstream-glib"
"glib"
"gobject-introspection"
"gsettings-desktop-schemas"
"gtk4"
"gtksourceview5"
"libgee"
];
casks = [
"1password"
"1password-cli"
"alt-tab"
"android-studio"
"audacity"
"background-music"
"db-browser-for-sqlite"
"discord"
"discord-ptb"
"docker"
"firefox"
"firefox-developer-edition"
"goland"
"google-chrome"
"intellij-idea"
"itch"
"iterm2"
"lens"
"minecraft"
"obs"
"orbstack"
"phpstorm"
"plexamp"
"raycast"
"rider"
"rubymine"
"sequel-ace"
"shottr"
"slack"
"spotify"
"steam"
"texifier"
"thunderbird"
"transmit"
"visual-studio-code"
"wine-stable"
];
};
}

15
nix/lib/importAll.nix Normal file
View File

@ -0,0 +1,15 @@
{ pkgs, ... }:
exclude: cwd: with builtins; with pkgs.lib; filter
(e: !elem e exclude)
(map
(p: path.append cwd p)
(attrNames (attrsets.filterAttrs
(p: t:
let
d = t == "directory";
b = baseNameOf p;
in
d && pathExists (path.append cwd (p + "/default.nix")) ||
!d && match ''.*\.nix'' b != null && b != "default.nix")
(readDir cwd))))

8
nix/overlays/lix.nix Normal file
View File

@ -0,0 +1,8 @@
(final: prev: {
lix = prev.lix.overrideAttrs (oldAttrs: {
postPatch = (oldAttrs.postPatch or "") + ''
substituteInPlace src/libmain/shared.cc \
--replace-fail "(Lix, like Nix)" "but for lesbians"
'';
});
})

20
nix/system/default.nix Normal file
View File

@ -0,0 +1,20 @@
{ importAll, ... }:
{
imports = importAll [] ./.;
users.users.alyxia = {
name = "alyxia";
home = "/Users/alyxia";
};
# enable the gpg agent by default
programs.gnupg.agent.enable = true;
# if you use zsh (the default on new macOS installations),
# you'll need to enable this so nix-darwin creates a zshrc sourcing needed environment changes
programs.zsh.enable = true;
# tailscaled isn't automatically registered as a service that should run on installation.
services.tailscale.enable = true;
}

90
nix/system/homebrew.nix Normal file
View File

@ -0,0 +1,90 @@
{ ... }:
{
homebrew = {
enable = true;
onActivation = {
autoUpdate = true;
cleanup = "zap";
upgrade = true;
};
taps = [
"drud/ddev"
"homebrew/cask-versions"
"int128/kubelogin"
];
# Please do not the brew.
brews = [
"bear"
"composer"
"croc"
"ddev"
"deno"
"dotnet"
"ferium"
"gradle"
"kubelogin"
"mkcert"
"nss"
"pinentry-mac"
"pkg-config"
"poetry"
"rustup"
"sdl2"
# Fyra crap, but from Homebrew because someone doesn't know how to
# package libraries in nixpkgs
"appstream-glib"
"glib"
"gobject-introspection"
"gsettings-desktop-schemas"
"gtk4"
"gtksourceview5"
"libgee"
];
casks = [
"1password"
"1password-cli"
"alt-tab"
"android-studio"
"audacity"
"background-music"
"browserstacklocal"
"db-browser-for-sqlite"
"discord"
"discord-ptb"
"docker"
"firefox"
"firefox-developer-edition"
"goland"
"google-chrome"
"intellij-idea"
"itch"
"iterm2"
"lens"
"minecraft"
"obs"
"orbstack"
"phpstorm"
"plexamp"
"raycast"
"readdle-spark"
"rider"
"rubymine"
"sequel-ace"
"shottr"
"slack"
"spotify"
"steam"
"texifier"
"thunderbird"
"transmit"
"typora"
"visual-studio-code"
"wine-stable"
];
};
}

20
nix/system/nix.nix Normal file
View File

@ -0,0 +1,20 @@
{ ... }:
{
services.nix-daemon.enable = true;
nix = {
settings.experimental-features = [ "nix-command" "flakes" ];
gc = {
automatic = true;
options = "--delete-older-than 8d";
};
};
nixpkgs = {
config = {
allowUnfree = true;
permittedInsecurePackages = [ "python-2.7.18.8" ];
};
};
}