add nix configuration
This commit is contained in:
parent
d6e5d2fcbe
commit
41f64cf880
9 changed files with 330 additions and 19 deletions
19
flake.lock
19
flake.lock
|
|
@ -107,6 +107,22 @@
|
||||||
"type": "github"
|
"type": "github"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"nixpkgs-stable": {
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1729691686,
|
||||||
|
"narHash": "sha256-BAuPWW+9fa1moZTU+jFh+1cUtmsuF8asgzFwejM4wac=",
|
||||||
|
"owner": "nixos",
|
||||||
|
"repo": "nixpkgs",
|
||||||
|
"rev": "32e940c7c420600ef0d1ef396dc63b04ee9cad37",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "nixos",
|
||||||
|
"ref": "nixos-24.05",
|
||||||
|
"repo": "nixpkgs",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
"root": {
|
"root": {
|
||||||
"inputs": {
|
"inputs": {
|
||||||
"disko": "disko",
|
"disko": "disko",
|
||||||
|
|
@ -114,7 +130,8 @@
|
||||||
"impermanence": "impermanence",
|
"impermanence": "impermanence",
|
||||||
"nix-index-database": "nix-index-database",
|
"nix-index-database": "nix-index-database",
|
||||||
"nixos-hardware": "nixos-hardware",
|
"nixos-hardware": "nixos-hardware",
|
||||||
"nixpkgs": "nixpkgs"
|
"nixpkgs": "nixpkgs",
|
||||||
|
"nixpkgs-stable": "nixpkgs-stable"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
||||||
17
flake.nix
17
flake.nix
|
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
inputs = {
|
inputs = {
|
||||||
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
|
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
|
||||||
|
nixpkgs-stable.url = "github:nixos/nixpkgs/nixos-24.05";
|
||||||
disko.url = "github:nix-community/disko";
|
disko.url = "github:nix-community/disko";
|
||||||
disko.inputs.nixpkgs.follows = "nixpkgs";
|
disko.inputs.nixpkgs.follows = "nixpkgs";
|
||||||
impermanence.url = "github:nix-community/impermanence";
|
impermanence.url = "github:nix-community/impermanence";
|
||||||
|
|
@ -54,20 +55,4 @@
|
||||||
inherit lib self;
|
inherit lib self;
|
||||||
nixosConfigurations = (import ./src/hosts/default.nix commonArgs);
|
nixosConfigurations = (import ./src/hosts/default.nix commonArgs);
|
||||||
};
|
};
|
||||||
|
|
||||||
# outputs = {nixpkgs, ...} @ inputs:
|
|
||||||
# {
|
|
||||||
# nixosConfigurations.pickwick = nixpkgs.lib.nixosSystem {
|
|
||||||
# specialArgs = { inherit inputs; };
|
|
||||||
# modules = [
|
|
||||||
# inputs.disko.nixosModules.default
|
|
||||||
# (import ./disko.nix { device = "/dev/nvme0n1"; })
|
|
||||||
|
|
||||||
# ./configuration.nix
|
|
||||||
#
|
|
||||||
# inputs.home-manager.nixosModules.default
|
|
||||||
# inputs.impermanence.nixosModules.impermanence
|
|
||||||
# ];
|
|
||||||
# };
|
|
||||||
# };
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,11 +8,11 @@
|
||||||
|
|
||||||
{
|
{
|
||||||
imports = [
|
imports = [
|
||||||
./bash.nix
|
|
||||||
./emacs.nix
|
./emacs.nix
|
||||||
./impermanence.nix
|
./impermanence.nix
|
||||||
./git.nix
|
./git.nix
|
||||||
./gui
|
./gui
|
||||||
|
./shell
|
||||||
./ssh.nix
|
./ssh.nix
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
|
||||||
8
src/home/shell/default.nix
Normal file
8
src/home/shell/default.nix
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
{ config, lib, pkgs, ... }:
|
||||||
|
|
||||||
|
{
|
||||||
|
imports = [
|
||||||
|
./bash.nix
|
||||||
|
./shell.nix
|
||||||
|
];
|
||||||
|
}
|
||||||
32
src/home/shell/shell.nix
Normal file
32
src/home/shell/shell.nix
Normal file
|
|
@ -0,0 +1,32 @@
|
||||||
|
{ lib, pkgs, ... }:
|
||||||
|
|
||||||
|
{
|
||||||
|
options.custom = with lib; {
|
||||||
|
shell = {
|
||||||
|
packages = mkOption {
|
||||||
|
type =
|
||||||
|
with types;
|
||||||
|
attrsOf (oneOf [
|
||||||
|
str
|
||||||
|
attrs
|
||||||
|
package
|
||||||
|
]);
|
||||||
|
default = { };
|
||||||
|
apply = custom.mkShellPackages;
|
||||||
|
description = ''
|
||||||
|
Attrset of shell packages to install and add to pkgs.custom overlay (for compatibility across multiple shells).
|
||||||
|
Both string and attr values will be passed as arguments to writeShellApplicationCompletions
|
||||||
|
'';
|
||||||
|
example = ''
|
||||||
|
shell.packages = {
|
||||||
|
myPackage1 = "echo 'Hello, World!'";
|
||||||
|
myPackage2 = {
|
||||||
|
runtimeInputs = [ pkgs.hello ];
|
||||||
|
text = "hello --greeting 'Hi'";
|
||||||
|
};
|
||||||
|
}
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
58
src/lib.nix
58
src/lib.nix
|
|
@ -1,4 +1,62 @@
|
||||||
{ lib, pkgs, ... }:
|
{ lib, pkgs, ... }:
|
||||||
|
|
||||||
lib.extend (_: libprev: {
|
lib.extend (_: libprev: {
|
||||||
|
custom = rec {
|
||||||
|
# taken from https://github.com/iynaix/dotfiles/blob/main/lib.nix
|
||||||
|
# writeShellApplication with support for completions
|
||||||
|
writeShellApplicationCompletions =
|
||||||
|
{
|
||||||
|
name,
|
||||||
|
bashCompletion ? null,
|
||||||
|
zshCompletion ? null,
|
||||||
|
fishCompletion ? null,
|
||||||
|
...
|
||||||
|
}@shellArgs:
|
||||||
|
let
|
||||||
|
inherit (pkgs) writeShellApplication writeTextFile symlinkJoin;
|
||||||
|
# get the needed arguments for writeShellApplication
|
||||||
|
app = writeShellApplication (lib.intersectAttrs (lib.functionArgs writeShellApplication) shellArgs);
|
||||||
|
completions =
|
||||||
|
lib.optional (bashCompletion != null) (writeTextFile {
|
||||||
|
name = "${name}.bash";
|
||||||
|
destination = "/share/bash-completion/completions/${name}.bash";
|
||||||
|
text = bashCompletion;
|
||||||
|
})
|
||||||
|
++ lib.optional (zshCompletion != null) (writeTextFile {
|
||||||
|
name = "${name}.zsh";
|
||||||
|
destination = "/share/zsh/site-functions/_${name}";
|
||||||
|
text = zshCompletion;
|
||||||
|
})
|
||||||
|
++ lib.optional (fishCompletion != null) (writeTextFile {
|
||||||
|
name = "${name}.fish";
|
||||||
|
destination = "/share/fish/vendor_completions.d/${name}.fish";
|
||||||
|
text = fishCompletion;
|
||||||
|
});
|
||||||
|
in
|
||||||
|
if lib.length completions == 0 then
|
||||||
|
app
|
||||||
|
else
|
||||||
|
symlinkJoin {
|
||||||
|
inherit name;
|
||||||
|
inherit (app) meta;
|
||||||
|
paths = [ app ] ++ completions;
|
||||||
|
};
|
||||||
|
|
||||||
|
# taken from https://github.com/iynaix/dotfiles/blob/main/lib.nix
|
||||||
|
# produces an attrset shell package with completions from either a string / writeShellApplication attrset / package
|
||||||
|
mkShellPackages = lib.mapAttrs (
|
||||||
|
name: value:
|
||||||
|
if lib.isString value then
|
||||||
|
pkgs.writeShellApplication {
|
||||||
|
inherit name;
|
||||||
|
text = value;
|
||||||
|
}
|
||||||
|
# packages
|
||||||
|
else if lib.isDerivation value then
|
||||||
|
value
|
||||||
|
# attrs to pass to writeShellApplication
|
||||||
|
else
|
||||||
|
writeShellApplicationCompletions (value // { inherit name; })
|
||||||
|
);
|
||||||
|
};
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,55 @@
|
||||||
|
|
||||||
{
|
{
|
||||||
imports = [
|
imports = [
|
||||||
./users.nix
|
|
||||||
./impermanence.nix
|
./impermanence.nix
|
||||||
|
./nix.nix
|
||||||
|
./users.nix
|
||||||
];
|
];
|
||||||
|
|
||||||
|
options.custom = with lib; {
|
||||||
|
shell = {
|
||||||
|
packages = mkOption {
|
||||||
|
type =
|
||||||
|
with types;
|
||||||
|
attrsOf (oneOf [
|
||||||
|
str
|
||||||
|
attrs
|
||||||
|
package
|
||||||
|
]);
|
||||||
|
apply = custom.mkShellPackages;
|
||||||
|
default = { };
|
||||||
|
description = ''
|
||||||
|
Attrset of shell packages to install and add to pkgs.custom overlay (for compatibility across multiple shells).
|
||||||
|
Both string and attr values will be passed as arguments to writeShellApplicationCompletions
|
||||||
|
'';
|
||||||
|
example = ''
|
||||||
|
shell.packages = {
|
||||||
|
myPackage1 = "echo 'Hello, World!'";
|
||||||
|
myPackage2 = {
|
||||||
|
runtimeInputs = [ pkgs.hello ];
|
||||||
|
text = "hello --greeting 'Hi'";
|
||||||
|
};
|
||||||
|
}
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
};
|
||||||
|
symlinks = mkOption {
|
||||||
|
type = types.attrsOf types.str;
|
||||||
|
default = { };
|
||||||
|
description = "Symlinks to create in the format { dest = src;}";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
config = {
|
||||||
|
environment = {
|
||||||
|
systemPackages = with pkgs; [
|
||||||
|
curl
|
||||||
|
eza
|
||||||
|
neovim
|
||||||
|
yazi
|
||||||
|
ripgrep
|
||||||
|
htop
|
||||||
|
] ++ (lib.attrValues config.custom.shell.packages);
|
||||||
|
};
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
163
src/nixos/nix.nix
Normal file
163
src/nixos/nix.nix
Normal file
|
|
@ -0,0 +1,163 @@
|
||||||
|
{
|
||||||
|
config,
|
||||||
|
host,
|
||||||
|
inputs,
|
||||||
|
lib,
|
||||||
|
pkgs,
|
||||||
|
self,
|
||||||
|
user,
|
||||||
|
...
|
||||||
|
}:
|
||||||
|
let
|
||||||
|
dots = "/persist${config.hm.home.homeDirectory}/Code/nix-config";
|
||||||
|
in
|
||||||
|
{
|
||||||
|
# execute shebangs that assume hardcoded shell paths
|
||||||
|
services.envfs.enable = true;
|
||||||
|
|
||||||
|
# run unpatched binaries on nixos
|
||||||
|
programs.nix-ld.enable = true;
|
||||||
|
|
||||||
|
environment = {
|
||||||
|
# for nixlang / nixpkgs
|
||||||
|
systemPackages = with pkgs; [
|
||||||
|
nix-init
|
||||||
|
nix-update
|
||||||
|
nixfmt-rfc-style
|
||||||
|
];
|
||||||
|
};
|
||||||
|
|
||||||
|
# make a symlink of flake within the generation (e.g. /run/current-system/src)
|
||||||
|
system.extraSystemBuilderCmds = "ln -s ${self.sourceInfo.outPath} $out/src";
|
||||||
|
|
||||||
|
systemd.tmpfiles.rules = [
|
||||||
|
# cleanup nixpkgs-review cache on boot
|
||||||
|
"D! ${config.hm.xdg.cacheHome}/nixpkgs-review 1755 ${user} users 1d"
|
||||||
|
# cleanup channels so nix stops complaining
|
||||||
|
"D! /nix/var/nix/profiles/per-user/root 1755 root root 1d"
|
||||||
|
];
|
||||||
|
|
||||||
|
custom.shell.packages =
|
||||||
|
{
|
||||||
|
# list all installed packages
|
||||||
|
nix-list-packages = {
|
||||||
|
text =
|
||||||
|
let
|
||||||
|
allPkgs = map (p: p.name) (
|
||||||
|
config.environment.systemPackages ++ config.users.users.${user}.packages ++ config.hm.home.packages
|
||||||
|
);
|
||||||
|
in
|
||||||
|
''sort -ui <<< "${lib.concatLines allPkgs}"'';
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
nix =
|
||||||
|
let
|
||||||
|
nixPath = [
|
||||||
|
"nixpkgs=flake:nixpkgs"
|
||||||
|
# "/nix/var/nix/profiles/per-user/root/channels"
|
||||||
|
];
|
||||||
|
in
|
||||||
|
{
|
||||||
|
channel.enable = false;
|
||||||
|
# required for nix-shell -p to work
|
||||||
|
inherit nixPath;
|
||||||
|
gc = {
|
||||||
|
# Automatic garbage collection
|
||||||
|
automatic = true;
|
||||||
|
dates = "daily";
|
||||||
|
options = "--delete-older-than 7d";
|
||||||
|
};
|
||||||
|
package = pkgs.nixVersions.latest;
|
||||||
|
registry = {
|
||||||
|
nixpkgs-master = {
|
||||||
|
from = {
|
||||||
|
type = "indirect";
|
||||||
|
id = "nixpkgs-master";
|
||||||
|
};
|
||||||
|
to = {
|
||||||
|
type = "github";
|
||||||
|
owner = "NixOS";
|
||||||
|
repo = "nixpkgs";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
nixpkgs-stable.flake = inputs.nixpkgs-stable;
|
||||||
|
};
|
||||||
|
settings = {
|
||||||
|
auto-optimise-store = true; # Optimise symlinks
|
||||||
|
# re-evaluate on every rebuild instead of "cached failure of attribute" error
|
||||||
|
# eval-cache = false;
|
||||||
|
# required to be set, for some reason nix.nixPath does not write to nix.conf
|
||||||
|
nix-path = nixPath;
|
||||||
|
warn-dirty = false;
|
||||||
|
# removes ~/.nix-profile and ~/.nix-defexpr
|
||||||
|
use-xdg-base-directories = true;
|
||||||
|
|
||||||
|
# use flakes
|
||||||
|
experimental-features = [
|
||||||
|
"nix-command"
|
||||||
|
"flakes"
|
||||||
|
# "repl-flake"
|
||||||
|
];
|
||||||
|
substituters = [
|
||||||
|
"https://hyprland.cachix.org"
|
||||||
|
"https://nix-community.cachix.org"
|
||||||
|
"https://ghostty.cachix.org"
|
||||||
|
];
|
||||||
|
# allow building and pushing of laptop config from desktop
|
||||||
|
trusted-users = [ user ];
|
||||||
|
trusted-public-keys = [
|
||||||
|
"hyprland.cachix.org-1:a7pgxzMz7+chwVL3/pzj6jIBMioiJM7ypFP8PwtkuGc="
|
||||||
|
"nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs="
|
||||||
|
"ghostty.cachix.org-1:QB389yTa6gTyneehvqG58y0WnHjQOqgnA+wBnpWWxns="
|
||||||
|
];
|
||||||
|
};
|
||||||
|
# // lib.optionalAttrs (config.nix.package.pname == "lix") {
|
||||||
|
# repl-overlays = [ ./repl-overlays.nix ];
|
||||||
|
# };
|
||||||
|
};
|
||||||
|
|
||||||
|
# better nixos generation label
|
||||||
|
# https://reddit.com/r/NixOS/comments/16t2njf/small_trick_for_people_using_nixos_with_flakes/k2d0sxx/
|
||||||
|
system.nixos.label = lib.concatStringsSep "-" (
|
||||||
|
(lib.sort (x: y: x < y) config.system.nixos.tags)
|
||||||
|
++ [ "${config.system.nixos.version}.${self.sourceInfo.shortRev or "dirty"}" ]
|
||||||
|
);
|
||||||
|
|
||||||
|
# add nixos-option workaround for flakes
|
||||||
|
# https://github.com/NixOS/nixpkgs/issues/97855#issuecomment-1075818028
|
||||||
|
nixpkgs.overlays = [
|
||||||
|
(_: prev: {
|
||||||
|
nixos-option =
|
||||||
|
let
|
||||||
|
flake-compat = prev.fetchFromGitHub {
|
||||||
|
owner = "edolstra";
|
||||||
|
repo = "flake-compat";
|
||||||
|
rev = "12c64ca55c1014cdc1b16ed5a804aa8576601ff2";
|
||||||
|
hash = "sha256-hY8g6H2KFL8ownSiFeMOjwPC8P0ueXpCVEbxgda3pko=";
|
||||||
|
};
|
||||||
|
prefix = ''(import ${flake-compat} { src = ${dots}; }).defaultNix.nixosConfigurations.${host}'';
|
||||||
|
in
|
||||||
|
prev.runCommandNoCC "nixos-option" { buildInputs = [ prev.makeWrapper ]; } ''
|
||||||
|
makeWrapper ${lib.getExe prev.nixos-option} $out/bin/nixos-option \
|
||||||
|
--add-flags --config_expr \
|
||||||
|
--add-flags "\"${prefix}.config\"" \
|
||||||
|
--add-flags --options_expr \
|
||||||
|
--add-flags "\"${prefix}.options\""
|
||||||
|
'';
|
||||||
|
})
|
||||||
|
];
|
||||||
|
|
||||||
|
# enable man-db cache for fish to be able to find manpages
|
||||||
|
# https://discourse.nixos.org/t/fish-shell-and-manual-page-completion-nixos-home-manager/15661
|
||||||
|
documentation.man.generateCaches = true;
|
||||||
|
|
||||||
|
hm.custom.persist = {
|
||||||
|
home = {
|
||||||
|
cache.directories = [
|
||||||
|
".cache/nix"
|
||||||
|
".cache/nixpkgs-review"
|
||||||
|
];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue