Use impurity.nix

This commit is contained in:
outfoxxed 2023-07-26 01:20:41 -07:00
parent 3c0081ef39
commit 07f488ec6a
Signed by: outfoxxed
GPG key ID: 4C88A185FB89301E
5 changed files with 27 additions and 45 deletions

View file

@ -147,6 +147,21 @@
"type": "github" "type": "github"
} }
}, },
"impurity": {
"locked": {
"lastModified": 1689836741,
"narHash": "sha256-82KeRg2sAqDXCdzVs8P8GoqVaPsZjkWgrfsj6kgOLTY=",
"owner": "outfoxxed",
"repo": "impurity.nix",
"rev": "bbc41b69ab5485cd55aa315d08cff865781d3913",
"type": "github"
},
"original": {
"owner": "outfoxxed",
"repo": "impurity.nix",
"type": "github"
}
},
"ironbar": { "ironbar": {
"inputs": { "inputs": {
"nixpkgs": [ "nixpkgs": [
@ -224,6 +239,7 @@
"hyprland": "hyprland", "hyprland": "hyprland",
"hyprland-hy3": "hyprland-hy3", "hyprland-hy3": "hyprland-hy3",
"hyprpaper": "hyprpaper", "hyprpaper": "hyprpaper",
"impurity": "impurity",
"ironbar": "ironbar", "ironbar": "ironbar",
"nixpkgs": "nixpkgs", "nixpkgs": "nixpkgs",
"nur": "nur", "nur": "nur",

View file

@ -9,6 +9,8 @@
inputs.nixpkgs.follows = "nixpkgs"; inputs.nixpkgs.follows = "nixpkgs";
}; };
impurity.url = "github:outfoxxed/impurity.nix";
emacs-overlay = { emacs-overlay = {
url = "github:nix-community/emacs-overlay?rev=b7a065e692e944e6b68d4285013ca426a8de6663"; url = "github:nix-community/emacs-overlay?rev=b7a065e692e944e6b68d4285013ca426a8de6663";
inputs.nixpkgs.follows = "nixpkgs"; inputs.nixpkgs.follows = "nixpkgs";
@ -50,10 +52,10 @@
nixosConfigurations = { nixosConfigurations = {
lenovo = nixpkgs.lib.nixosSystem rec { lenovo = nixpkgs.lib.nixosSystem rec {
system = "x86_64-linux"; system = "x86_64-linux";
specialArgs = { inherit system inputs; }; specialArgs = { inherit self system inputs; };
modules = [ modules = [
(import ./modules/impurity.nix self) ./modules/impurity.nix
./modules/preserve-system.nix ./modules/preserve-system.nix
./modules/devenv ./modules/devenv
./modules/system.nix ./modules/system.nix

View file

@ -10,6 +10,8 @@
inputs.nixpkgs.follows = "nixpkgs"; inputs.nixpkgs.follows = "nixpkgs";
}; };
impurity.url = "github:outfoxxed/impurity.nix";
emacs-overlay = { emacs-overlay = {
url = "github:nix-community/emacs-overlay?rev=b7a065e692e944e6b68d4285013ca426a8de6663"; url = "github:nix-community/emacs-overlay?rev=b7a065e692e944e6b68d4285013ca426a8de6663";
inputs.nixpkgs.follows = "nixpkgs"; inputs.nixpkgs.follows = "nixpkgs";

View file

@ -1,43 +1,5 @@
self: { lib, config, pkgs, ... }: with lib; let { self, inputs, ... }: {
relativePath = path: assert types.path.check path; imports = [ inputs.impurity.nixosModules.impurity ];
with builtins; strings.removePrefix (toString self) (toString path);
impurityGroupEnabled = group: let impurity.configRoot = self;
impurityGroups = strings.splitString " " (builtins.getEnv "IMPURITY_GROUPS");
in group == "" || builtins.elem group impurityGroups;
impurePath = let
impurePathEnv = builtins.getEnv "IMPURITY_PATH";
in if impurePathEnv == ""
then throw "impurity.enable is true but IMPURITY_PATH is not set"
else impurePathEnv;
createImpurePath = path: let
relative = (relativePath path);
full = impurePath + relative;
in pkgs.runCommand "impurity-${relative}" {} "ln -s ${full} $out";
in {
options.impurity.enable = mkOption {
type = types.bool;
default = false;
description = "Enable impure symlinks";
};
config._module.args.impurity = rec {
groupedLink = groupspec: path:
assert types.path.check path; let
groups =
if groupspec == null
then [ "" ]
else if (types.listOf types.string).check groupspec
then groupspec
else assert types.string.check groupspec;
strings.splitString " " groupspec;
in if config.impurity.enable && lists.any (group: impurityGroupEnabled group) groups
then createImpurePath path
else path;
link = path: groupedLink null path;
};
} }

View file

@ -1,4 +1,4 @@
{ system, inputs, config, lib, impurity, ... }: let { self, system, inputs, config, lib, impurity, ... }: let
username = "admin"; username = "admin";
homeDirectory = "/home/${username}"; homeDirectory = "/home/${username}";
in { in {
@ -23,7 +23,7 @@ in {
home-manager = { home-manager = {
extraSpecialArgs = { extraSpecialArgs = {
inherit system inputs impurity; inherit self system inputs impurity;
}; };
# use system nixpkgs instead of home-manager nixpkgs # use system nixpkgs instead of home-manager nixpkgs