feat(nix): user flake instead regular shell.nix

This commit is contained in:
Yorick Barbanneau 2025-01-28 23:03:53 +01:00
parent b5179b97ac
commit 558fc24911
6 changed files with 248 additions and 26 deletions

107
flake.lock generated Normal file
View file

@ -0,0 +1,107 @@
{
"nodes": {
"flake-parts": {
"inputs": {
"nixpkgs-lib": "nixpkgs-lib"
},
"locked": {
"lastModified": 1736143030,
"narHash": "sha256-+hu54pAoLDEZT9pjHlqL9DNzWz0NbUn8NEAHP7PQPzU=",
"owner": "hercules-ci",
"repo": "flake-parts",
"rev": "b905f6fc23a9051a6e1b741e1438dbfc0634c6de",
"type": "github"
},
"original": {
"owner": "hercules-ci",
"repo": "flake-parts",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1737885589,
"narHash": "sha256-Zf0hSrtzaM1DEz8//+Xs51k/wdSajticVrATqDrfQjg=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "852ff1d9e153d8875a83602e03fdef8a63f0ecf8",
"type": "github"
},
"original": {
"id": "nixpkgs",
"ref": "nixos-unstable",
"type": "indirect"
}
},
"nixpkgs-lib": {
"locked": {
"lastModified": 1735774519,
"narHash": "sha256-CewEm1o2eVAnoqb6Ml+Qi9Gg/EfNAxbRx1lANGVyoLI=",
"type": "tarball",
"url": "https://github.com/NixOS/nixpkgs/archive/e9b51731911566bbf7e4895475a87fe06961de0b.tar.gz"
},
"original": {
"type": "tarball",
"url": "https://github.com/NixOS/nixpkgs/archive/e9b51731911566bbf7e4895475a87fe06961de0b.tar.gz"
}
},
"nixpkgs_2": {
"locked": {
"lastModified": 1735554305,
"narHash": "sha256-zExSA1i/b+1NMRhGGLtNfFGXgLtgo+dcuzHzaWA6w3Q=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "0e82ab234249d8eee3e8c91437802b32c74bb3fd",
"type": "github"
},
"original": {
"owner": "nixos",
"ref": "nixpkgs-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"flake-parts": "flake-parts",
"nixpkgs": "nixpkgs",
"systems": "systems",
"treefmt-nix": "treefmt-nix"
}
},
"systems": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"id": "systems",
"type": "indirect"
}
},
"treefmt-nix": {
"inputs": {
"nixpkgs": "nixpkgs_2"
},
"locked": {
"lastModified": 1738070913,
"narHash": "sha256-j6jC12vCFsTGDmY2u1H12lMr62fnclNjuCtAdF1a4Nk=",
"owner": "numtide",
"repo": "treefmt-nix",
"rev": "bebf27d00f7d10ba75332a0541ac43676985dea3",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "treefmt-nix",
"type": "github"
}
}
},
"root": "root",
"version": 7
}

24
flake.nix Normal file
View file

@ -0,0 +1,24 @@
{
description = "Nix flake for building latex document";
inputs = {
nixpkgs.url = "nixpkgs/nixos-unstable";
flake-parts.url = "github:hercules-ci/flake-parts";
treefmt-nix.url = "github:numtide/treefmt-nix";
};
outputs =
inputs@{
nixpkgs,
flake-parts,
systems,
...
}:
flake-parts.lib.mkFlake { inherit inputs; } {
systems = [ "x86_64-linux" ];
imports = [
inputs.treefmt-nix.flakeModule
./nix/default.nix
];
};
}

8
nix/default.nix Normal file
View file

@ -0,0 +1,8 @@
{ ... }:
{
imports = [
./packages.nix
./devshells.nix
];
}

28
nix/devshells.nix Normal file
View file

@ -0,0 +1,28 @@
_: {
config.perSystem =
{
config,
inputs',
pkgs,
...
}:
{
devShells = {
default = pkgs.mkShell {
name = "hugo-shell";
nativeBuildInputs = config.develPackages
++ config.hugoBuildPackages
;
shellook = ''
mkdir -p themes
ln -snf "${config.themePackage}/" "themes/mainroad"
'';
};
latex = pkgs.mkShell {
name = "latex-shell";
nativeBuildInputs = config.develPackages
++ config.latexBuildPackages;
};
};
};
}

81
nix/packages.nix Normal file
View file

@ -0,0 +1,81 @@
{
lib,
inputs,
...
}:
let
inherit (lib) mkOption mdDoc types;
inherit (inputs.flake-parts.lib) mkPerSystemOption;
in
{
options.perSystem = mkPerSystemOption (
{
pkgs,
config,
...
}:
{
options = {
latexBuildPackages = mkOption {
description = mdDoc "Packages needed to build latex file";
type = types.listOf types.package;
default = with pkgs; [
(pkgs.texlive.combine {
inherit (pkgs.texlive)
babel-french
caption
collection-luatex
float
fontawesome
fontspec
lato
libertine
listings
lstfiracode
pdfpages
pdflscape
scheme-basic
soul
titlesec
xcolor
;
})
fira-code
];
};
hugoBuildPackages = mkOption {
description = mdDoc "Packages needed to build latex file";
type = types.listOf types.package;
default = with pkgs; [
hugo
];
};
themePackage = mkOption {
description = mdDoc "Theme user for my course note";
default = pkgs.stdenvNoCC.mkDerivation {
name = "hugo-theme-mainroad";
pname = "hugo-theme-mainroad";
src = pkgs.fetchFromGitHub {
owner = "vimux";
repo = "mainroad";
rev = "13e04b3694ea2d20a68cfbfaea42a8c565079809";
sha256 = "sha256-td8xQhAz/TnjZmOKIEiQjRgzdoicRrVN9h41Uxnnaso=";
};
installPhase = ''
cp -r $src $out
'';
};
};
develPackages = mkOption {
description = mdDoc "Python package used to development";
type = types.listOf types.package;
default = with pkgs; [
convco
go-task
];
};
};
});
}

View file

@ -1,26 +0,0 @@
with (import <nixpkgs> {});
let
hugo-theme-mainroad = pkgs.stdenvNoCC.mkDerivation {
name = "hugo-theme-mainroad";
src = pkgs.fetchFromGitHub {
owner = "vimux";
repo = "mainroad";
rev = "13e04b3694ea2d20a68cfbfaea42a8c565079809";
sha256 = "sha256-td8xQhAz/TnjZmOKIEiQjRgzdoicRrVN9h41Uxnnaso=";
};
installPhase = ''
cp -r $src $out
'';
preferLocalBuild = true;
};
in
mkShell {
buildInputs = [
hugo
];
shellHook = ''
mkdir -p themes
ln -snf "${hugo-theme-mainroad}/" "themes/mainroad"
'';
}