aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--flake.lock12
-rw-r--r--flake.nix136
-rw-r--r--nixos.nix54
-rw-r--r--pkgs.nix61
4 files changed, 143 insertions, 120 deletions
diff --git a/flake.lock b/flake.lock
index e6da384..1b37211 100644
--- a/flake.lock
+++ b/flake.lock
@@ -2,11 +2,11 @@
"nodes": {
"flake-utils": {
"locked": {
- "lastModified": 1653893745,
- "narHash": "sha256-0jntwV3Z8//YwuOjzhV2sgJJPt+HY6KhU7VZUL0fKZQ=",
+ "lastModified": 1678901627,
+ "narHash": "sha256-U02riOqrKKzwjsxc/400XnElV+UtPUQWpANPlyazjH0=",
"owner": "numtide",
"repo": "flake-utils",
- "rev": "1ed9fb1935d260de5fe1c2f7ee0ebaae17ed2fa1",
+ "rev": "93a2b84fc4b70d9e089d029deacc3583435c2ed6",
"type": "github"
},
"original": {
@@ -16,11 +16,11 @@
},
"nixpkgs": {
"locked": {
- "lastModified": 1654875595,
- "narHash": "sha256-Vairke3ryPSFpgQdaYicPPhPWMGhtzm6V+1uF2Tefbk=",
+ "lastModified": 1678875422,
+ "narHash": "sha256-T3o6NcQPwXjxJMn2shz86Chch4ljXgZn746c2caGxd8=",
"owner": "NixOS",
"repo": "nixpkgs",
- "rev": "3f909fb574d9b9d7294e544981c62a4a5e4599fc",
+ "rev": "126f49a01de5b7e35a43fd43f891ecf6d3a51459",
"type": "github"
},
"original": {
diff --git a/flake.nix b/flake.nix
index 35c0231..013277b 100644
--- a/flake.nix
+++ b/flake.nix
@@ -1,120 +1,28 @@
{
description = "Cynerd's shell configuration";
- outputs = { self, flake-utils, nixpkgs }:
- let
-
- loadrc = dir: ''
- for sh in ${dir}/*; do
- [ -r "$sh" ] && . "$sh"
- done
- '';
- commonrc = loadrc ./shellrc.d;
- desktoprc = loadrc ./shellrc-desktop.d;
- bashrc = loadrc ./bashrc.d;
- zshrc = loadrc ./zshrc.d;
-
- packages = pkgs: rec {
- shellrc-generic = pkgs.stdenvNoCC.mkDerivation {
- name = "shellrc-profile";
- src = ./.;
- installPhase = ''
- mkdir -p "$out/etc/shellrc"
- cp -r ./shellrc.d/. "$out/etc/shellrc/"
- '';
- };
- shellrc-bashrc = pkgs.stdenvNoCC.mkDerivation {
- name = "shellrc-profile-bash";
- src = ./.;
- shellrc = shellrc-generic;
- installPhase = ''
- mkdir -p "$out/etc/bashrc.d"
- cp -r ./bashrc.d/. "$out/etc/bashrc.d/"
- cat >"$out/etc/bashrc.d/shellrc" <<EOF
- for sh in $shellrc/etc/shellrc/*; do
- [ -r "\$sh" ] && . "\$sh"
- done
- EOF
- '';
- };
- shellrc-zshrc = pkgs.stdenvNoCC.mkDerivation {
- name = "shellrc-profile-zsh";
- src = ./.;
- shellrc = shellrc-generic;
- installPhase = ''
- mkdir -p "$out/etc/zshrc.d"
- cp -r ./zshrc.d/. "$out/etc/zshrc.d/"
- cat >"$out/etc/zshrc.d/shellrc" <<EOF
- for sh in $shellrc/etc/shellrc/*; do
- [ -r "\$sh" ] && . "\$sh"
- done
- EOF
- '';
- };
- shellrc-completion = pkgs.stdenvNoCC.mkDerivation {
- name = "shellrc-completion";
- src = ./.;
- nativeBuildInputs = [ pkgs.installShellFiles ];
- installPhase = ''
- for comp in bash-completion/*; do
- installShellCompletion --bash --name "''${comp##*/}.bash" "$comp"
- done
- for comp in zsh-completion/*; do
- installShellCompletion --zsh --name "''${comp##*/}" "$comp"
- done
- '';
- };
- shellrc = pkgs.symlinkJoin {
- name = "shellrc";
- paths = [ shellrc-bashrc shellrc-zshrc shellrc-completion ];
- };
- default = shellrc;
- };
-
- in {
-
- overlays = {
- shellrc = final: prev: packages prev;
- default = self.overlays.shellrc;
- };
-
- nixosModules = {
- shellrc = { config, lib, pkgs, ... }: with lib; {
- options = {
- programs.shellrc = {
- enable = mkOption {
- type = types.bool;
- default = true;
- description = "If shellrc should be enabled.";
- };
- desktop = mkOption {
- type = types.bool;
- default = false;
- description = "If shellrc's desktop specific files should be used.";
- };
- };
+ outputs = {
+ self,
+ flake-utils,
+ nixpkgs,
+ }:
+ with flake-utils.lib;
+ {
+ overlays = {
+ shellrc = final: prev: import ./pkgs.nix {pkgs = prev;};
+ default = self.overlays.shellrc;
};
-
- config = mkIf config.programs.shellrc.enable {
-
- environment.interactiveShellInit = commonrc + optionalString config.programs.shellrc.desktop desktoprc;
-
- programs.bash.interactiveShellInit = bashrc;
- programs.bash.promptInit = ""; # Disable default prompt as we have our own
-
- programs.zsh.interactiveShellInit = mkIf config.programs.zsh.enable zshrc;
- programs.zsh.promptInit = ""; # Disable default prompt as we have our own
-
- nixpkgs.overlays = [ self.overlays.shellrc ];
- environment.systemPackages = [ pkgs.shellrc-completion ];
-
+ nixosModules = {
+ shellrc = import ./nixos.nix [self.overlays.shellrc];
+ default = self.nixosModules.shellrc;
};
- };
- default = self.nixosModules.shellrc;
- };
-
- } // (flake-utils.lib.eachDefaultSystem (system: {
- packages = packages nixpkgs.legacyPackages.${system};
- }));
-
+ }
+ // eachDefaultSystem (system: let
+ pkgs = nixpkgs.legacyPackages.${system};
+ selfPkgs = filterPackages system (flattenTree (import ./pkgs.nix {inherit pkgs;}));
+ in {
+ packages = selfPkgs // {default = selfPkgs.shellrc-bash;};
+ legacyPackages = pkgs.extend self.overlays.default;
+ formatter = pkgs.alejandra;
+ });
}
diff --git a/nixos.nix b/nixos.nix
new file mode 100644
index 0000000..77b272c
--- /dev/null
+++ b/nixos.nix
@@ -0,0 +1,54 @@
+overlays: {
+ config,
+ lib,
+ pkgs,
+ ...
+}:
+with lib; let
+ cnf = config.programs.shellrc;
+ zshEnable = config.programs.zsh.enable;
+
+ # Source all files in an appropriate shell directory in every profile
+ shellInit = dir: ''
+ for p in $NIX_PROFILES; do
+ for file in $p/etc/${dir}/*; do
+ [ -f "$file" ] || continue
+ . "$file"
+ done
+ done
+ '';
+in {
+ options = {
+ programs.shellrc = {
+ enable = mkOption {
+ type = types.bool;
+ default = true;
+ description = "If shellrc should be enabled.";
+ };
+ desktop = mkOption {
+ type = types.bool;
+ default = false;
+ description = "If shellrc's desktop specific files should be used.";
+ };
+ };
+ };
+
+ config = mkMerge [
+ {
+ nixpkgs.overlays = overlays;
+
+ programs.bash.interactiveShellInit = shellInit "bashrc.d";
+ programs.zsh.interactiveShellInit = mkIf zshEnable (shellInit "zshrc.d");
+ }
+ (mkIf cnf.enable {
+ environment.systemPackages =
+ [pkgs.shellrc-bash]
+ ++ optional cnf.desktop pkgs.shellrc-desktop
+ ++ optional zshEnable pkgs.shellrc-zsh;
+
+ # Disable default prompt as we have our own
+ programs.bash.promptInit = "";
+ programs.zsh.promptInit = ""; # Disable default prompt as we have our own
+ })
+ ];
+}
diff --git a/pkgs.nix b/pkgs.nix
new file mode 100644
index 0000000..f171859
--- /dev/null
+++ b/pkgs.nix
@@ -0,0 +1,61 @@
+{pkgs}: let
+ shellrcPkgs = {
+ shellrc-generic = pkgs.stdenvNoCC.mkDerivation {
+ name = "shellrc-generic";
+ src = ./.;
+ installPhase = ''
+ mkdir -p "$out/etc/shellrc.d"
+ cp -r ./shellrc.d/. "$out/etc/shellrc.d/"
+ '';
+ };
+ shellrc-desktop = pkgs.stdenvNoCC.mkDerivation {
+ name = "shellrc-desktop";
+ src = ./.;
+ installPhase = ''
+ mkdir -p "$out/etc/shellrc.d"
+ cp -r ./shellrc-desktop.d/. "$out/etc/shellrc.d/"
+ '';
+ };
+ shellrc-bash = pkgs.stdenvNoCC.mkDerivation {
+ name = "shellrc-bash";
+ src = ./.;
+ propagatedBuildInputs = [shellrcPkgs.shellrc-generic];
+ installPhase = ''
+ mkdir -p "$out/etc/bashrc.d"
+ cp -r ./bashrc.d/. "$out/etc/bashrc.d/"
+ cat >"$out/etc/bashrc.d/shellrc" <<EOF
+ # Load ShellRC files
+ for p in $NIX_PROFILES; do
+ for sh in $p/etc/shellrc.d/*; do
+ [ -r "\$sh" ] && . "\$sh"
+ done
+ done
+ EOF
+ for comp in bash-completion/*; do
+ installShellCompletion --bash --name "''${comp##*/}.bash" "$comp"
+ done
+ '';
+ };
+ shellrc-zsh = pkgs.stdenvNoCC.mkDerivation {
+ name = "shellrc-zsh";
+ src = ./.;
+ propagatedBuildInputs = [shellrcPkgs.shellrc-generic];
+ installPhase = ''
+ mkdir -p "$out/etc/zshrc.d"
+ cp -r ./zshrc.d/. "$out/etc/zshrc.d/"
+ cat >"$out/etc/zshrc.d/shellrc" <<EOF
+ # Load ShellRC files
+ for p in $NIX_PROFILES; do
+ for sh in $p/etc/shellrc.d/*; do
+ [ -r "\$sh" ] && . "\$sh"
+ done
+ done
+ EOF
+ for comp in zsh-completion/*; do
+ installShellCompletion --zsh --name "''${comp##*/}" "$comp"
+ done
+ '';
+ };
+ };
+in
+ shellrcPkgs