From 558fc249112ab867da8da3590c788b453a5d73b9 Mon Sep 17 00:00:00 2001 From: Yorick Barbanneau Date: Tue, 28 Jan 2025 23:03:53 +0100 Subject: [PATCH] feat(nix): user flake instead regular shell.nix --- flake.lock | 107 ++++++++++++++++++++++++++++++++++++++++++++++ flake.nix | 24 +++++++++++ nix/default.nix | 8 ++++ nix/devshells.nix | 28 ++++++++++++ nix/packages.nix | 81 +++++++++++++++++++++++++++++++++++ shell.nix | 26 ----------- 6 files changed, 248 insertions(+), 26 deletions(-) create mode 100644 flake.lock create mode 100644 flake.nix create mode 100644 nix/default.nix create mode 100644 nix/devshells.nix create mode 100644 nix/packages.nix delete mode 100644 shell.nix diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..64dbb1c --- /dev/null +++ b/flake.lock @@ -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 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..5c84054 --- /dev/null +++ b/flake.nix @@ -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 + ]; + }; +} diff --git a/nix/default.nix b/nix/default.nix new file mode 100644 index 0000000..129df2f --- /dev/null +++ b/nix/default.nix @@ -0,0 +1,8 @@ + +{ ... }: +{ + imports = [ + ./packages.nix + ./devshells.nix + ]; +} diff --git a/nix/devshells.nix b/nix/devshells.nix new file mode 100644 index 0000000..13aabe9 --- /dev/null +++ b/nix/devshells.nix @@ -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; + }; + }; + }; +} diff --git a/nix/packages.nix b/nix/packages.nix new file mode 100644 index 0000000..54e0923 --- /dev/null +++ b/nix/packages.nix @@ -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 + ]; + }; + }; + }); +} diff --git a/shell.nix b/shell.nix deleted file mode 100644 index 57483a5..0000000 --- a/shell.nix +++ /dev/null @@ -1,26 +0,0 @@ -with (import {}); -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" - ''; -}