mirror of
https://github.com/kittywitch/nixfiles.git
synced 2026-02-09 04:19:19 -08:00
feat: overlays + pkgs
This commit is contained in:
parent
bed84b16b0
commit
5da80d3c52
17 changed files with 210 additions and 91 deletions
1
.envrc
1
.envrc
|
|
@ -1,2 +1,3 @@
|
|||
export REPO_ROOT="$(pwd)"
|
||||
export REPO_HOSTNAME=$(hostname -s)
|
||||
use flake
|
||||
|
|
|
|||
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -3,3 +3,4 @@ venv/
|
|||
.direnv/
|
||||
result
|
||||
/kittywitch
|
||||
data/
|
||||
|
|
|
|||
|
|
@ -3,13 +3,17 @@
|
|||
lib,
|
||||
std,
|
||||
inputs,
|
||||
tree,
|
||||
...
|
||||
}: let
|
||||
inherit (std) set tuple list;
|
||||
inherit (lib.strings) versionAtLeast;
|
||||
renameAttrs = names: set.remap ({_0, _1}: tuple.tuple2 (names.${_0} or _0) _1);
|
||||
renameAttr = oldName: newName: renameAttrs { ${oldName} = newName; };
|
||||
renameAttrs = names:
|
||||
set.remap ({
|
||||
_0,
|
||||
_1,
|
||||
}:
|
||||
tuple.tuple2 (names.${_0} or _0) _1);
|
||||
renameAttr = oldName: newName: renameAttrs {${oldName} = newName;};
|
||||
in {
|
||||
nix = {
|
||||
nixPath = set.mapToValues (name: flake: "${name}=${flake.outPath}") (renameAttr "self" "kat" inputs);
|
||||
|
|
|
|||
|
|
@ -1,7 +1,9 @@
|
|||
{inputs, ...}: {
|
||||
{
|
||||
inputs,
|
||||
tree,
|
||||
...
|
||||
}: {
|
||||
nixpkgs = {
|
||||
overlays = map (path: import "${path}/overlay.nix") [
|
||||
inputs.arcexprs
|
||||
];
|
||||
overlays = import tree.overlays {inherit inputs;};
|
||||
};
|
||||
}
|
||||
|
|
|
|||
48
flake.lock
generated
48
flake.lock
generated
|
|
@ -59,6 +59,32 @@
|
|||
"type": "github"
|
||||
}
|
||||
},
|
||||
"deploy-rs": {
|
||||
"inputs": {
|
||||
"flake-compat": [
|
||||
"flake-compat"
|
||||
],
|
||||
"nixpkgs": [
|
||||
"nixpkgs"
|
||||
],
|
||||
"utils": [
|
||||
"utils"
|
||||
]
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1674127017,
|
||||
"narHash": "sha256-QO1xF7stu5ZMDLbHN30LFolMAwY6TVlzYvQoUs1RD68=",
|
||||
"owner": "serokell",
|
||||
"repo": "deploy-rs",
|
||||
"rev": "8c9ea9605eed20528bf60fae35a2b613b901fd77",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "serokell",
|
||||
"repo": "deploy-rs",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"empty": {
|
||||
"locked": {
|
||||
"lastModified": 1630400035,
|
||||
|
|
@ -95,7 +121,9 @@
|
|||
"nixpkgs": [
|
||||
"nixpkgs"
|
||||
],
|
||||
"utils": "utils"
|
||||
"utils": [
|
||||
"utils"
|
||||
]
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1674041176,
|
||||
|
|
@ -219,6 +247,7 @@
|
|||
"inputs": {
|
||||
"arcexprs": "arcexprs",
|
||||
"darwin": "darwin",
|
||||
"deploy-rs": "deploy-rs",
|
||||
"empty": "empty",
|
||||
"flake-compat": "flake-compat",
|
||||
"home-manager": "home-manager",
|
||||
|
|
@ -230,7 +259,7 @@
|
|||
"scalpel": "scalpel",
|
||||
"std": "std",
|
||||
"tree": "tree",
|
||||
"utils": "utils_2"
|
||||
"utils": "utils"
|
||||
}
|
||||
},
|
||||
"rust-overlay": {
|
||||
|
|
@ -333,21 +362,6 @@
|
|||
"repo": "flake-utils",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"utils_2": {
|
||||
"locked": {
|
||||
"lastModified": 1667395993,
|
||||
"narHash": "sha256-nuEHfE/LcWyuSWnS8t12N1wc105Qtau+/OdUAjtQ0rA=",
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
"rev": "5aed5285a952e0b949eb3ba02c12fa4fcfef535f",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
"type": "github"
|
||||
}
|
||||
}
|
||||
},
|
||||
"root": "root",
|
||||
|
|
|
|||
16
flake.nix
16
flake.nix
|
|
@ -14,10 +14,22 @@
|
|||
empty.url = "github:input-output-hk/empty-flake";
|
||||
# self-explanatory
|
||||
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
|
||||
# deployments
|
||||
deploy-rs = {
|
||||
url = "github:serokell/deploy-rs";
|
||||
inputs = {
|
||||
flake-compat.follows = "flake-compat";
|
||||
nixpkgs.follows = "nixpkgs";
|
||||
utils.follows = "utils";
|
||||
};
|
||||
};
|
||||
# self-explanatory
|
||||
home-manager = {
|
||||
url = "github:nix-community/home-manager/master";
|
||||
inputs.nixpkgs.follows = "nixpkgs";
|
||||
inputs = {
|
||||
nixpkgs.follows = "nixpkgs";
|
||||
utils.follows = "utils";
|
||||
};
|
||||
};
|
||||
# self-explanatory
|
||||
darwin = {
|
||||
|
|
@ -76,5 +88,5 @@
|
|||
flake = false;
|
||||
};
|
||||
};
|
||||
outputs = inputs: import ./outputs.nix { inherit inputs; };
|
||||
outputs = inputs: import ./outputs.nix {inherit inputs;};
|
||||
}
|
||||
|
|
|
|||
8
formatter.nix
Normal file
8
formatter.nix
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
{
|
||||
inputs,
|
||||
pkgs,
|
||||
...
|
||||
}:
|
||||
inputs.utils.lib.eachDefaultSystem (system: {
|
||||
${system} = pkgs.${system}.alejandra;
|
||||
})
|
||||
3
nixos/common/nix-index.nix
Normal file
3
nixos/common/nix-index.nix
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
_: {
|
||||
programs.command-not-found.enable = false;
|
||||
}
|
||||
|
|
@ -1,6 +1,11 @@
|
|||
{lib, ...}: let
|
||||
inherit (lib.modules) mkDefault;
|
||||
in {
|
||||
boot.loader = {
|
||||
grub.configurationLimit = 8;
|
||||
systemd-boot.configurationLimit = 8;
|
||||
};
|
||||
|
||||
nix.gc = {
|
||||
automatic = mkDefault true;
|
||||
dates = mkDefault "weekly";
|
||||
10
outputs.nix
10
outputs.nix
|
|
@ -1,8 +1,12 @@
|
|||
{ inputs }: let
|
||||
{inputs}: let
|
||||
inherit (inputs.nixpkgs) lib;
|
||||
std = import ./std.nix {inherit inputs;};
|
||||
tree = import ./tree.nix {inherit inputs;};
|
||||
systems = import ./systems {inherit inputs tree lib std;};
|
||||
shells = import ./shells {inherit inputs tree lib std;};
|
||||
shells = import ./shells {inherit inputs tree lib std pkgs;};
|
||||
inherit (import ./pkgs.nix {inherit inputs tree lib;}) pkgs;
|
||||
formatter = import ./formatter.nix {inherit inputs pkgs;};
|
||||
inherit (std) set;
|
||||
checks = set.map (_: deployLib: deployLib.deployChecks inputs.self.deploy) inputs.deploy-rs.lib;
|
||||
in
|
||||
{inherit inputs tree lib std;} // systems // shells
|
||||
{inherit inputs tree lib std pkgs checks formatter;} // systems // shells
|
||||
|
|
|
|||
7
overlays.nix
Normal file
7
overlays.nix
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
{inputs, ...}:
|
||||
[
|
||||
inputs.deploy-rs.overlay
|
||||
]
|
||||
++ map (path: import "${path}/overlay.nix") [
|
||||
inputs.arcexprs
|
||||
]
|
||||
9
pkgs.nix
Normal file
9
pkgs.nix
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
{
|
||||
lib,
|
||||
tree,
|
||||
inputs,
|
||||
...
|
||||
}: let
|
||||
overlays = import tree.overlays {inherit inputs;};
|
||||
in
|
||||
inputs.utils.lib.eachDefaultSystem (system: {pkgs = import inputs.nixpkgs {inherit system overlays;};})
|
||||
|
|
@ -3,6 +3,7 @@
|
|||
tree,
|
||||
inputs,
|
||||
std,
|
||||
pkgs,
|
||||
...
|
||||
}: let
|
||||
inherit (std) set;
|
||||
|
|
@ -10,9 +11,9 @@ in
|
|||
inputs.utils.lib.eachDefaultSystem (system: {
|
||||
devShells = let
|
||||
shells = set.map (_: path:
|
||||
import path rec {
|
||||
import path {
|
||||
inherit tree inputs system lib std;
|
||||
pkgs = inputs.nixpkgs.legacyPackages.${system};
|
||||
pkgs = pkgs.${system};
|
||||
})
|
||||
tree.shells;
|
||||
in
|
||||
|
|
|
|||
|
|
@ -5,20 +5,33 @@
|
|||
...
|
||||
}:
|
||||
with pkgs; let
|
||||
repo = import ../outputs.nix { inherit inputs; };
|
||||
inherit (std) set list;
|
||||
repo = import ../outputs.nix {inherit inputs;};
|
||||
inherit (std) set;
|
||||
repoShell = mkShell {
|
||||
nativeBuildInputs =
|
||||
[
|
||||
fd # fd, better fine!
|
||||
ripgrep # rg, better grep!
|
||||
go # Required for pulumi
|
||||
pulumi-bin # Infrastructure as code
|
||||
deadnix # dead-code scanner
|
||||
alejandra # code formatter
|
||||
statix # anti-pattern finder
|
||||
deploy-rs.deploy-rs # deployment system
|
||||
]
|
||||
++ set.values (set.map (name: _: (pkgs.writeShellScriptBin "${name}-rebuild" ''
|
||||
darwin-rebuild switch --flake $REPO_ROOT#${name}
|
||||
''))
|
||||
repo.darwinConfigurations);
|
||||
shellHook = ''
|
||||
echo -e "\e[39m\e[1m$USER@$REPO_HOSTNAME - \e[35m''$(realpath --relative-to=../ ./nixos/)\e[0m"
|
||||
echo -e "\e[35mRunning alejandra\e[0m"
|
||||
alejandra -cq $(fd -e nix)
|
||||
echo -e "\e[35mRunning statix\e[0m"
|
||||
statix check
|
||||
echo -e "\e[35mRunning deadnix\e[0m"
|
||||
deadnix
|
||||
'';
|
||||
};
|
||||
in repoShell
|
||||
in
|
||||
repoShell
|
||||
|
|
|
|||
54
std.nix
54
std.nix
|
|
@ -1,44 +1,57 @@
|
|||
{ inputs, ... }: let
|
||||
{inputs, ...}: let
|
||||
std = let
|
||||
baseStd = inputs.std.lib;
|
||||
inherit (baseStd) set function list bool types optional;
|
||||
mergeWith = let
|
||||
append = {
|
||||
path
|
||||
, values
|
||||
, canMerge
|
||||
, mapToSet
|
||||
path,
|
||||
values,
|
||||
canMerge,
|
||||
mapToSet,
|
||||
}: let
|
||||
mergeWith' = values: mergeWith {
|
||||
mergeWith' = values:
|
||||
mergeWith {
|
||||
inherit canMerge mapToSet path;
|
||||
sets = list.map (v: (mapToSet path v).value) values;
|
||||
};
|
||||
mergeUntil = list.findIndex (function.not (canMerge path)) values;
|
||||
len = list.length values;
|
||||
in if len == 0 then { }
|
||||
else if len == 1 then list.unsafeHead values
|
||||
else if list.all (canMerge path) values then mergeWith' values
|
||||
else optional.match mergeUntil {
|
||||
in
|
||||
if len == 0
|
||||
then {}
|
||||
else if len == 1
|
||||
then list.unsafeHead values
|
||||
else if list.all (canMerge path) values
|
||||
then mergeWith' values
|
||||
else
|
||||
optional.match mergeUntil {
|
||||
just = i: let
|
||||
split = list.splitAt i values;
|
||||
in if i > 0
|
||||
in
|
||||
if i > 0
|
||||
then mergeWith' split._0
|
||||
else list.unsafeHead values;
|
||||
nothing = list.unsafeHead values;
|
||||
};
|
||||
in {
|
||||
in
|
||||
{
|
||||
canMerge ? path: v: optional.isJust (mapToSet path v),
|
||||
mapToSet ? path: v: bool.toOptional (types.attrs.check v) v,
|
||||
path ? [ ],
|
||||
sets
|
||||
}: set.mapZip (name: values: append {
|
||||
mapToSet ? _: v: bool.toOptional (types.attrs.check v) v,
|
||||
path ? [],
|
||||
sets,
|
||||
}:
|
||||
set.mapZip (name: values:
|
||||
append {
|
||||
path = path ++ list.One name;
|
||||
inherit canMerge mapToSet values;
|
||||
}) sets;
|
||||
merge = sets: mergeWith {
|
||||
})
|
||||
sets;
|
||||
merge = sets:
|
||||
mergeWith {
|
||||
inherit sets;
|
||||
};
|
||||
in merge [
|
||||
in
|
||||
merge [
|
||||
baseStd
|
||||
{
|
||||
function = {
|
||||
|
|
@ -60,4 +73,5 @@
|
|||
};
|
||||
}
|
||||
];
|
||||
in std
|
||||
in
|
||||
std
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@
|
|||
}: let
|
||||
# The purpose of this file is to set up the host module which allows assigning of the system, e.g. aarch64-linux and the builder used with less pain.
|
||||
inherit (lib.modules) evalModules;
|
||||
inherit (std) string list function types bool optional set;
|
||||
inherit (std) string types optional set;
|
||||
defaultSpecialArgs = {
|
||||
inherit inputs tree std;
|
||||
};
|
||||
|
|
@ -106,6 +106,27 @@
|
|||
processHost = name: cfg: let
|
||||
host = cfg.config;
|
||||
in {
|
||||
deploy.nodes = set.merge [
|
||||
(set.optional (host.folder == "nixos") {
|
||||
${name} = {
|
||||
profiles.system = {
|
||||
user = "root";
|
||||
path = inputs.deploy-rs.lib.x86_64-linux.activate.nixos inputs.self.nixosConfigurations.${name};
|
||||
};
|
||||
hostname = "${name}.inskip.me";
|
||||
sshOpts = ["-p" "${builtins.toString (builtins.head inputs.self.nixosConfigurations.${name}.config.services.openssh.ports)}"];
|
||||
sshUser = "kat";
|
||||
user = "root";
|
||||
autoRollback = true;
|
||||
magicRollback = true;
|
||||
};
|
||||
})
|
||||
(set.optional (host.folder == "nixos" && host.arch != "x86_64") {
|
||||
${name} = {
|
||||
remoteBuild = true;
|
||||
};
|
||||
})
|
||||
];
|
||||
"${host.folder}Configurations".${name} = let
|
||||
hostConfig = host.builder {
|
||||
inherit (host) system modules specialArgs;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue