Skip to content

Commit

Permalink
massive rewrite into all flake modules
Browse files Browse the repository at this point in the history
  • Loading branch information
schradert committed Feb 11, 2024
1 parent 5b397c4 commit 2510ffa
Show file tree
Hide file tree
Showing 86 changed files with 1,570 additions and 2,468 deletions.
1 change: 0 additions & 1 deletion .envrc
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
use flake

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@
/src/home/emacs/doom.d/config.el
/src/home/emacs/doom.d/packages.el
/src/home/emacs/doom.d/custom.el
/.pre-commit-config.yaml
2 changes: 1 addition & 1 deletion .sops.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
keys:
- &tristan age1udsm4dv9q95d76p7ljxqyceafrwj3twmq883glc3prmry4w9eunqfhg9p3
creation_rules:
- path_regex: conf/sops.yaml$
- path_regex: src/dev/sops.yaml$
key_groups:
- age:
- *tristan
125 changes: 0 additions & 125 deletions bin/init.sh

This file was deleted.

15 changes: 0 additions & 15 deletions bin/k8s

This file was deleted.

55 changes: 0 additions & 55 deletions bin/nixos

This file was deleted.

3 changes: 0 additions & 3 deletions bin/nux

This file was deleted.

70 changes: 0 additions & 70 deletions bin/tix

This file was deleted.

96 changes: 96 additions & 0 deletions default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
{inputs, ...}: let
lib = inputs.nixpkgs.lib;
flake-parts-lib = inputs.flake-parts.lib;

# Convenience functions
pipe' = functions: value: lib.trivial.pipe value functions;
flatMap = function: pipe' [(builtins.map function) lib.lists.flatten];

# Filesystem traversal
filter = f: root:
lib.trivial.pipe root [
builtins.readDir
(lib.attrsets.filterAttrs f)
builtins.attrNames
(builtins.map (file: root + "/${file}"))
];
dirs = filter (_: type: type == "directory");
files = filter (name: type: type == "regular" && builtins.match ".+\.nix$" name != null);
everything = let
filesAndDirs = root: [
(files root)
(builtins.map everything (dirs root))
];
in
pipe' [lib.lists.toList (flatMap filesAndDirs)];
everythingBut = roots: exclude: builtins.filter (path: lib.lists.all (prefix: ! lib.path.hasPrefix prefix path) exclude) (everything roots);

# Options
mkEnabledOption = doc:
lib.mkOption {
type = lib.types.bool;
default = true;
example = false;
description = lib.mdDoc "Whether to enable ${doc}";
};
mkSystemOption = args:
lib.mkOption ({
type = lib.types.enum (import inputs.systems-all);
default = builtins.head (import inputs.systems-default);
example = builtins.head (import inputs.systems-darwin);
description = lib.mdDoc "System for the configuration";
}
// args);
mkOpenModuleOption = args:
lib.mkOption ({
type = lib.types.lazyAttrsOf lib.types.unspecified;
default = {};
}
// args);

nix = lib.attrsets.mergeAttrsList [
builtins
lib
lib.attrsets
lib.strings
lib.trivial
lib.types
flake-parts-lib
{
inherit pipe' flatMap;
inherit mkEnabledOption mkOpenModuleOption mkSystemOption;
fs = {inherit filter dirs files everything everythingBut;};
}
];
in {
imports = nix.fs.everything ./src;

_module.args.nix = nix;

perSystem = {
config,
pkgs,
system,
...
}: {
_module.args.nix = nix;
_module.args.pkgs = with nix;
import inputs.nixpkgs {
inherit system;
overlays = attrValues inputs.self.overlays;
config.allowUnfreePredicate = pkg: elem (getName pkg) ["terraform" "spotify" "android-studio-stable"];
};
devShells.default = pkgs.mkShell {
inputsFrom = nix.attrValues (nix.removeAttrs config.devShells ["default"]);
};
};

flake.nixosModules.args = {
_module.args.nix = nix;
home-manager.extraSpecialArgs.nix = nix;
};
flake.darwinModules_.args = {
_module.args.nix = nix;
home-manager.extraSpecialArgs.nix = nix;
};
}
Loading

0 comments on commit 2510ffa

Please sign in to comment.