refactor(flake): wrap xonsh as a package

This commit is contained in:
Artur Manuel 2025-01-18 12:34:41 +00:00
commit d84ed13e0f
11 changed files with 287 additions and 135 deletions

122
flake.lock generated
View file

@ -2,17 +2,18 @@
"nodes": { "nodes": {
"chaotic": { "chaotic": {
"inputs": { "inputs": {
"fenix": "fenix",
"flake-schemas": "flake-schemas", "flake-schemas": "flake-schemas",
"home-manager": "home-manager", "home-manager": "home-manager",
"jovian": "jovian", "jovian": "jovian",
"nixpkgs": "nixpkgs" "nixpkgs": "nixpkgs"
}, },
"locked": { "locked": {
"lastModified": 1736848948, "lastModified": 1736971453,
"narHash": "sha256-P9XZoUzRxjq5AJxR1+F0HEyzggNX/zt+A3cuwXER4qM=", "narHash": "sha256-X3f+KFNg+xJcvz3LbV8Sncwnk9AfjzliY5vpw7IpX5c=",
"owner": "chaotic-cx", "owner": "chaotic-cx",
"repo": "nyx", "repo": "nyx",
"rev": "e75f332c423ae95164ec188c0406c2d47b8a4a65", "rev": "368f97d223fc5b5278b520e456a53551d7ac5318",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -27,11 +28,11 @@
"nixpkgs": ["nixpkgs"] "nixpkgs": ["nixpkgs"]
}, },
"locked": { "locked": {
"lastModified": 1736711425, "lastModified": 1737038063,
"narHash": "sha256-8hKhPQuMtXfJi+4lPvw3FBk/zSJVHeb726Zo0uF1PP8=", "narHash": "sha256-rMEuiK69MDhjz1JgbaeQ9mBDXMJ2/P8vmOYRbFndXsk=",
"owner": "nix-community", "owner": "nix-community",
"repo": "disko", "repo": "disko",
"rev": "f720e64ec37fa16ebba6354eadf310f81555cc07", "rev": "bf0abfde48f469c256f2b0f481c6281ff04a5db2",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -59,6 +60,25 @@
"type": "github" "type": "github"
} }
}, },
"fenix": {
"inputs": {
"nixpkgs": ["chaotic", "nixpkgs"],
"rust-analyzer-src": "rust-analyzer-src"
},
"locked": {
"lastModified": 1736836313,
"narHash": "sha256-zdZ7/T6yG0/hzoVOiNpDiR/sW3zR6oSMrfIFJK2BrrE=",
"owner": "nix-community",
"repo": "fenix",
"rev": "056c9393c821a4df356df6ce7f14c722dc8717ec",
"type": "github"
},
"original": {
"owner": "nix-community",
"repo": "fenix",
"type": "github"
}
},
"flake-compat": { "flake-compat": {
"flake": false, "flake": false,
"locked": { "locked": {
@ -150,11 +170,11 @@
"nixpkgs": ["nixpkgs"] "nixpkgs": ["nixpkgs"]
}, },
"locked": { "locked": {
"lastModified": 1735882644, "lastModified": 1737043064,
"narHash": "sha256-3FZAG+pGt3OElQjesCAWeMkQ7C/nB1oTHLRQ8ceP110=", "narHash": "sha256-I/OuxGwXwRi5gnFPsyCvVR+IfFstA+QXEpHu1hvsgD8=",
"owner": "cachix", "owner": "cachix",
"repo": "git-hooks.nix", "repo": "git-hooks.nix",
"rev": "a5a961387e75ae44cc20f0a57ae463da5e959656", "rev": "94ee657f6032d913fe0ef49adaa743804635b0bb",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -181,6 +201,26 @@
"type": "github" "type": "github"
} }
}, },
"hetch": {
"inputs": {
"nixpkgs": ["nixpkgs"],
"treefmt": "treefmt"
},
"locked": {
"lastModified": 1737045336,
"narHash": "sha256-0LiXE5Z7V3gKt2BfZokhnK5GOoCIkLpFoONEucFASv8=",
"ref": "master",
"rev": "7b8af02bcc2d4d56ac09b2de2179de7453925d48",
"revCount": 4,
"type": "git",
"url": "https://codeberg.org/amadaluzia/hetch.git"
},
"original": {
"ref": "master",
"type": "git",
"url": "https://codeberg.org/amadaluzia/hetch.git"
}
},
"home-manager": { "home-manager": {
"inputs": { "inputs": {
"nixpkgs": ["chaotic", "nixpkgs"] "nixpkgs": ["chaotic", "nixpkgs"]
@ -318,11 +358,27 @@
}, },
"nixpkgs_2": { "nixpkgs_2": {
"locked": { "locked": {
"lastModified": 1736798957, "lastModified": 1731890469,
"narHash": "sha256-qwpCtZhSsSNQtK4xYGzMiyEDhkNzOCz/Vfu4oL2ETsQ=", "narHash": "sha256-D1FNZ70NmQEwNxpSSdTXCSklBH1z2isPR84J6DQrJGs=",
"owner": "nixos", "owner": "nixos",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "9abb87b552b7f55ac8916b6fc9e5cb486656a2f3", "rev": "5083ec887760adfe12af64830a66807423a859a7",
"type": "github"
},
"original": {
"owner": "nixos",
"ref": "nixpkgs-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"nixpkgs_3": {
"locked": {
"lastModified": 1736883708,
"narHash": "sha256-uQ+NQ0/xYU0N1CnXsa2zghgNaOPxWpMJXSUJJ9W7140=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "eb62e6aa39ea67e0b8018ba8ea077efe65807dc8",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -332,7 +388,7 @@
"type": "github" "type": "github"
} }
}, },
"nixpkgs_3": { "nixpkgs_4": {
"locked": { "locked": {
"lastModified": 1735523292, "lastModified": 1735523292,
"narHash": "sha256-opBsbR/nrGxiiF6XzlVluiHYb6yN/hEwv+lBWTy9xoM=", "narHash": "sha256-opBsbR/nrGxiiF6XzlVluiHYb6yN/hEwv+lBWTy9xoM=",
@ -370,7 +426,7 @@
"flake-utils": "flake-utils", "flake-utils": "flake-utils",
"mnw": "mnw", "mnw": "mnw",
"nil": "nil", "nil": "nil",
"nixpkgs": "nixpkgs_3", "nixpkgs": "nixpkgs_4",
"nmd": "nmd", "nmd": "nmd",
"plugin-aerial-nvim": "plugin-aerial-nvim", "plugin-aerial-nvim": "plugin-aerial-nvim",
"plugin-alpha-nvim": "plugin-alpha-nvim", "plugin-alpha-nvim": "plugin-alpha-nvim",
@ -2529,7 +2585,8 @@
"disko": "disko", "disko": "disko",
"flake-parts": "flake-parts", "flake-parts": "flake-parts",
"git-hooks-nix": "git-hooks-nix", "git-hooks-nix": "git-hooks-nix",
"nixpkgs": "nixpkgs_2", "hetch": "hetch",
"nixpkgs": "nixpkgs_3",
"painless-neovim": "painless-neovim", "painless-neovim": "painless-neovim",
"pankomacs": "pankomacs", "pankomacs": "pankomacs",
"rosepine-qutebrowser": "rosepine-qutebrowser", "rosepine-qutebrowser": "rosepine-qutebrowser",
@ -2552,6 +2609,23 @@
"type": "github" "type": "github"
} }
}, },
"rust-analyzer-src": {
"flake": false,
"locked": {
"lastModified": 1736690231,
"narHash": "sha256-g9gyxX+F6CrkT5gRIMKPnCPom0o9ZDzYnzzeNF86D6Q=",
"owner": "rust-lang",
"repo": "rust-analyzer",
"rev": "8364ef299790cb6ec22b9e09e873c97dbe9f2cb5",
"type": "github"
},
"original": {
"owner": "rust-lang",
"ref": "nightly",
"repo": "rust-analyzer",
"type": "github"
}
},
"rust-overlay": { "rust-overlay": {
"inputs": { "inputs": {
"nixpkgs": ["painless-neovim", "nvf", "nil", "nixpkgs"] "nixpkgs": ["painless-neovim", "nvf", "nil", "nixpkgs"]
@ -2615,6 +2689,24 @@
"type": "github" "type": "github"
} }
}, },
"treefmt": {
"inputs": {
"nixpkgs": "nixpkgs_2"
},
"locked": {
"lastModified": 1733222881,
"narHash": "sha256-JIPcz1PrpXUCbaccEnrcUS8jjEb/1vJbZz5KkobyFdM=",
"owner": "numtide",
"repo": "treefmt-nix",
"rev": "49717b5af6f80172275d47a418c9719a31a78b53",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "treefmt-nix",
"type": "github"
}
},
"wallpkgs": { "wallpkgs": {
"inputs": { "inputs": {
"nixpkgs": ["nixpkgs"], "nixpkgs": ["nixpkgs"],

View file

@ -55,13 +55,22 @@
ref = "master"; ref = "master";
inputs.nixpkgs.follows = "nixpkgs"; inputs.nixpkgs.follows = "nixpkgs";
}; };
hetch = {
type = "git";
url = "https://codeberg.org/amadaluzia/hetch.git";
ref = "master";
inputs = {
nixpkgs.follows = "nixpkgs";
};
};
}; };
outputs = inputs @ { outputs = inputs @ {
self,
nixpkgs, nixpkgs,
flake-parts, flake-parts,
... ...
}: let }: let
lib = nixpkgs.lib.extend (import ./lib {inherit inputs;}); lib = nixpkgs.lib.extend (import ./lib {inherit inputs self;});
in in
flake-parts.lib.mkFlake { flake-parts.lib.mkFlake {
inherit inputs; inherit inputs;
@ -71,48 +80,8 @@
imports = [ imports = [
./hosts ./hosts
./overlays ./overlays
inputs.git-hooks-nix.flakeModule ./shells
]; ];
flake = {inherit lib;}; flake = {inherit lib;};
perSystem = {
config,
pkgs,
...
}: {
pre-commit = {
check.enable = true;
settings.hooks = {
alejandra.enable = true;
nil.enable = true;
shellcheck.enable = true;
prettier.enable = true;
ruff.enable = true;
ruff-format.enable = true;
shfmt.enable = true;
deadnix = {
enable = true;
args = ["-e"];
};
statix = {
enable = true;
args = ["fix"];
};
};
};
devShells.default = config.pre-commit.devShell;
devShells.haskell = pkgs.mkShell {
name = "haskell";
packages = builtins.attrValues {
inherit (pkgs) ghc;
inherit
(pkgs.haskellPackages)
cabal-install
haskell-language-server
ormolu
;
};
};
formatter = pkgs.alejandra;
};
}; };
} }

View file

@ -18,7 +18,10 @@
}; };
alqueva = { alqueva = {
xonsh.enable = true; xonsh = {
enable = true;
package = pkgs.amadaluzian-xonsh;
};
libvirt.enable = true; libvirt.enable = true;
direnv.enable = true; direnv.enable = true;
git.enable = true; git.enable = true;

View file

@ -38,6 +38,7 @@
qutebrowser qutebrowser
dunst dunst
; ;
inherit (inputs.hetch.packages.${pkgs.system}) hetch;
}; };
groups = [ groups = [
"wheel" "wheel"

View file

@ -42,8 +42,7 @@ in {
description = user; description = user;
isNormalUser = true; isNormalUser = true;
extraGroups = ucfg.groups; extraGroups = ucfg.groups;
inherit (ucfg) packages; inherit (ucfg) packages shell;
shell = ucfg.shell;
initialPassword = "password"; initialPassword = "password";
}) })
cfg; cfg;

View file

@ -5,10 +5,16 @@
... ...
}: let }: let
cfg = config.alqueva.xonsh; cfg = config.alqueva.xonsh;
inherit (pkgs) fetchFromGitHub; attrsToPyDict = attrs: (lib.pipe attrs [
(builtins.mapAttrs (n: v: "aliases['${n}'] = '${v}'"))
builtins.attrValues
(lib.concatStringsSep "\n")
(s: s + "\n")
]);
in { in {
options.alqueva.xonsh = { options.alqueva.xonsh = {
enable = lib.mkEnableOption "xonsh"; enable = lib.mkEnableOption "xonsh";
package = lib.mkPackageOption pkgs "xonsh" {};
}; };
config = lib.mkIf cfg.enable { config = lib.mkIf cfg.enable {
@ -16,83 +22,14 @@ in {
xonsh = { xonsh = {
config = config =
"from xonsh.xontribs import get_xontribs\n" "from xonsh.xontribs import get_xontribs\n"
+ lib.concatStringsSep "\n" (builtins.attrValues (builtins.mapAttrs (n: v: "aliases['${n}'] = '${v}'\n") config.environment.shellAliases)) + attrsToPyDict config.environment.shellAliases
+ '' + ''
for xontrib in get_xontribs(): for xontrib in get_xontribs():
xontrib load @(xontrib) xontrib load @(xontrib)
execx($(zoxide init xonsh --cmd j), 'exec', __xonsh__.ctx, filename='zoxide')
''; '';
package = pkgs.xonsh.override { inherit (cfg) package;
extraPackages = ps: [
(let
pname = "xontrib-fish-completer";
version = "0.0.1";
in
ps.buildPythonPackage {
inherit pname version;
src = fetchFromGitHub {
owner = "xonsh";
repo = pname;
rev = version;
hash = "sha256-PhhdZ3iLPDEIG9uDeR5ctJ9zz2+YORHBhbsiLrJckyA=";
};
})
(let
pname = "xontrib-prompt-starship";
version = "0.3.6";
in
ps.buildPythonPackage {
inherit pname version;
src = fetchFromGitHub {
owner = "anki-code";
repo = pname;
tag = version;
hash = "sha256-CLOvMa3L4XnH53H/k6/1W9URrPakPjbX1T1U43+eSR0=";
};
})
(let
pname = "xontrib-init-ssh-agent";
version = "1.0.1";
in
ps.buildPythonPackage {
inherit pname version;
pyproject = true;
build-system = [
ps.setuptools
ps.wheel
];
dependencies = [
ps.xonsh
];
src = fetchFromGitHub {
owner = "amadaluzia";
repo = pname;
rev = "cac9cfec70ec15b0ed4f1c8a18154ea9b4f8fb47";
hash = "sha256-UkRPdaZFNP8qv7lMwsTUalnre3k2UMfqMzmiTveLiBM=";
};
})
(let
pname = "xonsh-direnv";
version = "1.6.5";
in
ps.buildPythonPackage {
inherit pname version;
src = fetchFromGitHub {
owner = "74th";
repo = pname;
tag = version;
hash = "sha256-huBJ7WknVCk+WgZaXHlL+Y1sqsn6TYqMP29/fsUPSyU=";
};
})
];
};
enable = true; enable = true;
}; };
}; };
environment.systemPackages = [
pkgs.zoxide
pkgs.amadaluzian-starship
];
}; };
} }

View file

@ -1,4 +1,7 @@
{inputs}: _: _: let {
inputs,
self,
}: _: _: let
mkHost = { mkHost = {
host, host,
system, system,
@ -36,8 +39,7 @@
}) })
]; ];
specialArgs = { specialArgs = {
inherit inputs; inherit inputs self;
inherit (inputs) self;
}; };
}; };
in { in {

View file

@ -21,6 +21,7 @@
}; };
}); });
amadaluzian-starship = prev.callPackage ./derivations/starship.nix {}; amadaluzian-starship = prev.callPackage ./derivations/starship.nix {};
amadaluzian-xonsh = prev.callPackage ./derivations/xonsh {};
}; };
perSystem = {pkgs, ...}: { perSystem = {pkgs, ...}: {
packages = self.overlays.default null pkgs; packages = self.overlays.default null pkgs;

View file

@ -0,0 +1 @@
execx($(zoxide init xonsh --cmd j), 'exec', __xonsh__.ctx, filename='zoxide')

View file

@ -0,0 +1,98 @@
{
makeWrapper,
fetchFromGitHub,
symlinkJoin,
python3,
amadaluzian-starship,
zoxide,
}: let
xonsh = python3.withPackages (ps: [
ps.xonsh
(let
pname = "xontrib-fish-completer";
version = "0.0.1";
in
ps.buildPythonPackage {
inherit pname version;
src = fetchFromGitHub {
owner = "xonsh";
repo = pname;
rev = version;
hash = "sha256-PhhdZ3iLPDEIG9uDeR5ctJ9zz2+YORHBhbsiLrJckyA=";
};
})
(let
pname = "xontrib-prompt-starship";
version = "0.3.6";
in
ps.buildPythonPackage {
inherit pname version;
src = fetchFromGitHub {
owner = "anki-code";
repo = pname;
tag = version;
hash = "sha256-CLOvMa3L4XnH53H/k6/1W9URrPakPjbX1T1U43+eSR0=";
};
})
(let
pname = "xontrib-init-ssh-agent";
version = "1.0.1";
in
ps.buildPythonPackage {
inherit pname version;
pyproject = true;
build-system = [
ps.setuptools
ps.wheel
];
dependencies = [
ps.xonsh
];
src = fetchFromGitHub {
owner = "amadaluzia";
repo = pname;
rev = "cac9cfec70ec15b0ed4f1c8a18154ea9b4f8fb47";
hash = "sha256-UkRPdaZFNP8qv7lMwsTUalnre3k2UMfqMzmiTveLiBM=";
};
})
(let
pname = "xonsh-direnv";
version = "1.6.5";
in
ps.buildPythonPackage {
inherit pname version;
src = fetchFromGitHub {
owner = "74th";
repo = pname;
tag = version;
hash = "sha256-huBJ7WknVCk+WgZaXHlL+Y1sqsn6TYqMP29/fsUPSyU=";
};
})
]);
in
symlinkJoin {
name = "xonsh";
paths = [
xonsh
amadaluzian-starship
zoxide
];
nativeBuildInputs = [
makeWrapper
];
postBuild = ''
wrapProgram $out/bin/xonsh \
--set XONSH_CONFIG_DIR ${./cfg}
'';
passthru = {
shellPath = "/bin/xonsh";
};
meta = {
mainProgram = "xonsh";
};
}

49
shells/default.nix Normal file
View file

@ -0,0 +1,49 @@
{inputs, ...}: {
imports = [
inputs.git-hooks-nix.flakeModule
];
perSystem = {
config,
pkgs,
...
}: {
pre-commit = {
check.enable = true;
settings.hooks = {
alejandra.enable = true;
nil.enable = true;
shellcheck.enable = true;
prettier.enable = true;
ruff.enable = true;
ruff-format.enable = true;
shfmt.enable = true;
deadnix = {
enable = true;
args = ["-e"];
};
statix = {
enable = true;
args = ["fix"];
};
};
};
devShells = {
default = config.pre-commit.devShell;
haskell = pkgs.mkShell {
name = "haskell";
packages = builtins.attrValues {
inherit (pkgs) ghc;
inherit
(pkgs.haskellPackages)
stack
haskell-language-server
ormolu
;
};
};
};
formatter = pkgs.alejandra;
};
}