From 5c4007354957bd70388b55763cb60f566ac6f421 Mon Sep 17 00:00:00 2001 From: Sridhar Ratnakumar Date: Fri, 12 Apr 2024 16:46:26 +1000 Subject: [PATCH 01/12] wip - init --- flake-module.nix | 84 ++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 75 insertions(+), 9 deletions(-) diff --git a/flake-module.nix b/flake-module.nix index 52a5a97..0d0ccc9 100644 --- a/flake-module.nix +++ b/flake-module.nix @@ -1,12 +1,78 @@ { - perSystem = { pkgs, ... }: { - devShells.just = pkgs.mkShell { - packages = [ pkgs.just ]; - shellHook = '' - echo - echo "🍎🍎 Run 'just ' to get started" - just - ''; - }; + perSystem = { config, pkgs, lib, ... }: { + options = + let + mkJustfileOption = name: text: lib.mkOption { + type = lib.types.path; + readOnly = true; + default = pkgs.writeTextFile { + name = "${name}.just"; + inherit text; + }; + }; + + mkFeatureModule = name: desc: justfile: { + enable = lib.mkEnableOption desc; + justfile = mkJustfileOption name justfile; + }; + in + { + just-flake.features = { + treefmt = mkFeatureModule "treefmt" "Enable treefmt formatting target (fmt)" '' + # Auto-format the source tree using treefmt + fmt: + treefmt + ''; + rust = mkFeatureModule "rust" "Enable Rust targets (w; test)" '' + # Compile and watch the project + w: + cargo watch + + # Run and watch 'cargo test' + test: + cargo watch -s "cargo test" + ''; + convco = mkFeatureModule "convco" "Enable convco changelog target (changelog)" '' + # Generate CHANGELOG.md using recent commits + changelog: + convco changelog -p "" + ''; + }; + + just-flake.outputs.devShell = lib.mkOption { + type = lib.types.package; + readOnly = true; + }; + }; + config = + let + cfg = config.just-flake; + commonJustfile = pkgs.writeTextFile { + name = "justfile"; + text = '' + ${if cfg.features.treefmt.enable + then "import '${builtins.toString cfg.features.treefmt.justfile}'" + else ""} + ${if cfg.features.rust.enable + then "import '${builtins.toString cfg.features.rust.justfile}'" + else ""} + ${if cfg.features.convco.enable + then "import '${builtins.toString cfg.features.convco.justfile}'" + else ""} + ''; + }; + in + { + just-flake.outputs.devShell = pkgs.mkShell { + packages = [ pkgs.just ]; + shellHook = '' + ln -sf ${builtins.toString commonJustfile} ./common.just + + echo + echo "🍎🍎 Run 'just ' to get started" + just --list + ''; + }; + }; }; } From 1ac55c8e8b90a9632b1876f92c1a74c4e9c82b36 Mon Sep 17 00:00:00 2001 From: Sridhar Ratnakumar Date: Fri, 12 Apr 2024 16:56:01 +1000 Subject: [PATCH 02/12] generalize --- flake-module.nix | 50 ++++++++++++++-------------------------- nix/features/convco.nix | 9 ++++++++ nix/features/rust.nix | 13 +++++++++++ nix/features/treefmt.nix | 9 ++++++++ 4 files changed, 48 insertions(+), 33 deletions(-) create mode 100644 nix/features/convco.nix create mode 100644 nix/features/rust.nix create mode 100644 nix/features/treefmt.nix diff --git a/flake-module.nix b/flake-module.nix index 0d0ccc9..0d72119 100644 --- a/flake-module.nix +++ b/flake-module.nix @@ -10,33 +10,25 @@ inherit text; }; }; - - mkFeatureModule = name: desc: justfile: { - enable = lib.mkEnableOption desc; + mkFeatureSubmodule = { name, description, justfile }: { + enable = lib.mkEnableOption description; justfile = mkJustfileOption name justfile; + outputs.justfile = lib.mkOption { + type = lib.types.str; + readOnly = true; + default = + let cfg = config.just-flake.features.${name}; + in if cfg.enable + then "import '${builtins.toString cfg.justfile}'" + else ""; + }; }; in { just-flake.features = { - treefmt = mkFeatureModule "treefmt" "Enable treefmt formatting target (fmt)" '' - # Auto-format the source tree using treefmt - fmt: - treefmt - ''; - rust = mkFeatureModule "rust" "Enable Rust targets (w; test)" '' - # Compile and watch the project - w: - cargo watch - - # Run and watch 'cargo test' - test: - cargo watch -s "cargo test" - ''; - convco = mkFeatureModule "convco" "Enable convco changelog target (changelog)" '' - # Generate CHANGELOG.md using recent commits - changelog: - convco changelog -p "" - ''; + treefmt = mkFeatureSubmodule (import ./nix/features/treefmt.nix); + rust = mkFeatureSubmodule (import ./nix/features/rust.nix); + convco = mkFeatureSubmodule (import ./nix/features/convco.nix); }; just-flake.outputs.devShell = lib.mkOption { @@ -49,17 +41,9 @@ cfg = config.just-flake; commonJustfile = pkgs.writeTextFile { name = "justfile"; - text = '' - ${if cfg.features.treefmt.enable - then "import '${builtins.toString cfg.features.treefmt.justfile}'" - else ""} - ${if cfg.features.rust.enable - then "import '${builtins.toString cfg.features.rust.justfile}'" - else ""} - ${if cfg.features.convco.enable - then "import '${builtins.toString cfg.features.convco.justfile}'" - else ""} - ''; + text = + lib.concatStringsSep "\n" + (lib.mapAttrsToList (name: feature: feature.outputs.justfile) cfg.features); }; in { diff --git a/nix/features/convco.nix b/nix/features/convco.nix new file mode 100644 index 0000000..18fc2a7 --- /dev/null +++ b/nix/features/convco.nix @@ -0,0 +1,9 @@ +{ + name = "convco"; + description = "Add the 'changelog' target calling convco"; + justfile = '' + # Generate CHANGELOG.md using recent commits + changelog: + convco changelog -p "" + ''; +} diff --git a/nix/features/rust.nix b/nix/features/rust.nix new file mode 100644 index 0000000..182ffcc --- /dev/null +++ b/nix/features/rust.nix @@ -0,0 +1,13 @@ +{ + name = "rust"; + description = "Add 'w' and 'test' targets for running cargo"; + justfile = '' + # Compile and watch the project + w: + cargo watch + + # Run and watch 'cargo test' + test: + cargo watch -s "cargo test" + ''; +} diff --git a/nix/features/treefmt.nix b/nix/features/treefmt.nix new file mode 100644 index 0000000..9207839 --- /dev/null +++ b/nix/features/treefmt.nix @@ -0,0 +1,9 @@ +{ + name = "treefmt"; + description = "Add the 'fmt' target to format source tree using treefmt"; + justfile = '' + # Auto-format the source tree using treefmt + fmt: + treefmt + ''; +} From 632603e37ac599577094e7a0a21f853ef74fa879 Mon Sep 17 00:00:00 2001 From: Sridhar Ratnakumar Date: Fri, 12 Apr 2024 17:01:41 +1000 Subject: [PATCH 03/12] better name --- flake-module.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flake-module.nix b/flake-module.nix index 0d72119..31a98bf 100644 --- a/flake-module.nix +++ b/flake-module.nix @@ -50,7 +50,7 @@ just-flake.outputs.devShell = pkgs.mkShell { packages = [ pkgs.just ]; shellHook = '' - ln -sf ${builtins.toString commonJustfile} ./common.just + ln -sf ${builtins.toString commonJustfile} ./just-flake.just echo echo "🍎🍎 Run 'just ' to get started" From 0094e66e214653a7dbaab163d68cc4652050706f Mon Sep 17 00:00:00 2001 From: Sridhar Ratnakumar Date: Fri, 12 Apr 2024 17:05:19 +1000 Subject: [PATCH 04/12] common fn --- flake-module.nix | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/flake-module.nix b/flake-module.nix index 31a98bf..1b38bf8 100644 --- a/flake-module.nix +++ b/flake-module.nix @@ -5,6 +5,9 @@ mkJustfileOption = name: text: lib.mkOption { type = lib.types.path; readOnly = true; + description = '' + The justfile representing this feature. + ''; default = pkgs.writeTextFile { name = "${name}.just"; inherit text; @@ -16,6 +19,11 @@ outputs.justfile = lib.mkOption { type = lib.types.str; readOnly = true; + description = '' + The justfile code for importing this feature's justfile. + + See https://just.systems/man/en/chapter_53.html + ''; default = let cfg = config.just-flake.features.${name}; in if cfg.enable @@ -31,9 +39,20 @@ convco = mkFeatureSubmodule (import ./nix/features/convco.nix); }; + just-flake.commonFileName = lib.mkOption { + type = lib.types.str; + default = "just-flake.just"; + description = '' + The name of the common justfile generated by this module. + ''; + }; + just-flake.outputs.devShell = lib.mkOption { type = lib.types.package; readOnly = true; + description = '' + The output devShell to include in `inputsFrom`. + ''; }; }; config = @@ -50,7 +69,7 @@ just-flake.outputs.devShell = pkgs.mkShell { packages = [ pkgs.just ]; shellHook = '' - ln -sf ${builtins.toString commonJustfile} ./just-flake.just + ln -sf ${builtins.toString commonJustfile} ./${cfg.commonFileName} echo echo "🍎🍎 Run 'just ' to get started" From f6843d197460184b92c98eec97b0e9d0716ae2c1 Mon Sep 17 00:00:00 2001 From: Sridhar Ratnakumar Date: Tue, 16 Apr 2024 12:41:04 +1000 Subject: [PATCH 05/12] Separate out feature to its own module --- flake-module.nix | 30 +++++++++++++----------------- nix/feature.nix | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 17 deletions(-) create mode 100644 nix/feature.nix diff --git a/flake-module.nix b/flake-module.nix index 1b38bf8..7bed57d 100644 --- a/flake-module.nix +++ b/flake-module.nix @@ -13,24 +13,20 @@ inherit text; }; }; - mkFeatureSubmodule = { name, description, justfile }: { - enable = lib.mkEnableOption description; - justfile = mkJustfileOption name justfile; - outputs.justfile = lib.mkOption { - type = lib.types.str; - readOnly = true; - description = '' - The justfile code for importing this feature's justfile. - - See https://just.systems/man/en/chapter_53.html - ''; - default = - let cfg = config.just-flake.features.${name}; - in if cfg.enable - then "import '${builtins.toString cfg.justfile}'" - else ""; + mkFeatureSubmodule = { name, description, justfile }: + lib.mkOption { + inherit description; + default = { }; + type = lib.types.submoduleWith ({ + modules = [ + ./nix/feature.nix + ]; + specialArgs = { + inherit name justfile; + inherit pkgs; + }; + }); }; - }; in { just-flake.features = { diff --git a/nix/feature.nix b/nix/feature.nix new file mode 100644 index 0000000..89d41b7 --- /dev/null +++ b/nix/feature.nix @@ -0,0 +1,34 @@ +{ config, name, justfile, pkgs, lib, ... }: + +let + mkJustfileOption = text: lib.mkOption { + type = lib.types.path; + readOnly = true; + description = '' + The justfile representing this feature. + ''; + default = pkgs.writeTextFile { + name = "${name}.just"; + inherit text; + }; + }; +in +{ + options = { + enable = lib.mkEnableOption "Enable this feature"; + justfile = mkJustfileOption justfile; + outputs.justfile = lib.mkOption { + type = lib.types.str; + readOnly = true; + description = '' + The justfile code for importing this feature's justfile. + + See https://just.systems/man/en/chapter_53.html + ''; + default = + if config.enable + then "import '${builtins.toString config.justfile}'" + else ""; + }; + }; +} From afc397c6a3ed2fee38d0eace15d0efa4265040cf Mon Sep 17 00:00:00 2001 From: Sridhar Ratnakumar Date: Tue, 16 Apr 2024 15:51:46 +1000 Subject: [PATCH 06/12] rm --- flake-module.nix | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/flake-module.nix b/flake-module.nix index 7bed57d..af3047e 100644 --- a/flake-module.nix +++ b/flake-module.nix @@ -2,17 +2,6 @@ perSystem = { config, pkgs, lib, ... }: { options = let - mkJustfileOption = name: text: lib.mkOption { - type = lib.types.path; - readOnly = true; - description = '' - The justfile representing this feature. - ''; - default = pkgs.writeTextFile { - name = "${name}.just"; - inherit text; - }; - }; mkFeatureSubmodule = { name, description, justfile }: lib.mkOption { inherit description; From ee4dbfe92fa0b0ad8c6c9c4817808eb27296ffa6 Mon Sep 17 00:00:00 2001 From: Sridhar Ratnakumar Date: Tue, 16 Apr 2024 15:58:02 +1000 Subject: [PATCH 07/12] explicit submodule --- flake-module.nix | 44 ++++++++++++++++++++++++++------------------ 1 file changed, 26 insertions(+), 18 deletions(-) diff --git a/flake-module.nix b/flake-module.nix index af3047e..0443021 100644 --- a/flake-module.nix +++ b/flake-module.nix @@ -2,6 +2,7 @@ perSystem = { config, pkgs, lib, ... }: { options = let + inherit (lib) types; mkFeatureSubmodule = { name, description, justfile }: lib.mkOption { inherit description; @@ -18,26 +19,33 @@ }; in { - just-flake.features = { - treefmt = mkFeatureSubmodule (import ./nix/features/treefmt.nix); - rust = mkFeatureSubmodule (import ./nix/features/rust.nix); - convco = mkFeatureSubmodule (import ./nix/features/convco.nix); - }; + just-flake = lib.mkOption { + default = { }; + type = types.submodule { + options = { + features = { + treefmt = mkFeatureSubmodule (import ./nix/features/treefmt.nix); + rust = mkFeatureSubmodule (import ./nix/features/rust.nix); + convco = mkFeatureSubmodule (import ./nix/features/convco.nix); + }; - just-flake.commonFileName = lib.mkOption { - type = lib.types.str; - default = "just-flake.just"; - description = '' - The name of the common justfile generated by this module. - ''; - }; + commonFileName = lib.mkOption { + type = lib.types.str; + default = "just-flake.just"; + description = '' + The name of the common justfile generated by this module. + ''; + }; - just-flake.outputs.devShell = lib.mkOption { - type = lib.types.package; - readOnly = true; - description = '' - The output devShell to include in `inputsFrom`. - ''; + outputs.devShell = lib.mkOption { + type = lib.types.package; + readOnly = true; + description = '' + The output devShell to include in `inputsFrom`. + ''; + }; + }; + }; }; }; config = From 84d8c574a387bfbae1f42de0e947d4aeac092e07 Mon Sep 17 00:00:00 2001 From: Sridhar Ratnakumar Date: Tue, 16 Apr 2024 16:34:49 +1000 Subject: [PATCH 08/12] use freeformType --- flake-module.nix | 133 +++++++++++++++++++++++++-------------- nix/feature.nix | 28 ++++----- nix/features/convco.nix | 9 --- nix/features/rust.nix | 13 ---- nix/features/treefmt.nix | 9 --- 5 files changed, 98 insertions(+), 94 deletions(-) delete mode 100644 nix/features/convco.nix delete mode 100644 nix/features/rust.nix delete mode 100644 nix/features/treefmt.nix diff --git a/flake-module.nix b/flake-module.nix index 0443021..3c3dbdd 100644 --- a/flake-module.nix +++ b/flake-module.nix @@ -3,72 +3,109 @@ options = let inherit (lib) types; - mkFeatureSubmodule = { name, description, justfile }: - lib.mkOption { - inherit description; - default = { }; - type = lib.types.submoduleWith ({ - modules = [ - ./nix/feature.nix - ]; - specialArgs = { - inherit name justfile; - inherit pkgs; - }; - }); - }; + featureMod = { + imports = [ ./nix/feature.nix ]; + config._module.args = { inherit pkgs; }; + }; + featureType = types.submodule featureMod; in { just-flake = lib.mkOption { default = { }; - type = types.submodule { - options = { - features = { - treefmt = mkFeatureSubmodule (import ./nix/features/treefmt.nix); - rust = mkFeatureSubmodule (import ./nix/features/rust.nix); - convco = mkFeatureSubmodule (import ./nix/features/convco.nix); - }; + type = types.submoduleWith { + specialArgs = { inherit pkgs; }; + modules = [{ + imports = [{ + options.features = lib.mkOption { + type = types.submoduleWith { + modules = [{ freeformType = types.attrsOf featureType; }]; + specialArgs = { inherit pkgs; }; + }; + default = { }; + }; + }]; - commonFileName = lib.mkOption { - type = lib.types.str; - default = "just-flake.just"; - description = '' - The name of the common justfile generated by this module. - ''; - }; + options = { + features = { + convco = lib.mkOption { + description = "Add the 'changelog' target calling convco"; + type = types.submodule { imports = [ featureMod ]; }; + }; + rust = lib.mkOption { + description = "Add 'w' and 'test' targets for running cargo"; + type = types.submodule { imports = [ featureMod ]; }; + }; + treefmt = lib.mkOption { + description = "Add the 'fmt' target to format source tree using treefmt"; + type = types.submodule { imports = [ featureMod ]; }; + }; + }; + + commonFileName = lib.mkOption { + type = lib.types.str; + default = "just-flake.just"; + description = '' + The name of the common justfile generated by this module. + ''; + }; - outputs.devShell = lib.mkOption { - type = lib.types.package; - readOnly = true; - description = '' - The output devShell to include in `inputsFrom`. - ''; + outputs.devShell = lib.mkOption { + type = lib.types.package; + readOnly = true; + description = '' + The output devShell to include in `inputsFrom`. + ''; + }; }; - }; + }]; }; }; }; config = let cfg = config.just-flake; - commonJustfile = pkgs.writeTextFile { - name = "justfile"; - text = - lib.concatStringsSep "\n" - (lib.mapAttrsToList (name: feature: feature.outputs.justfile) cfg.features); - }; in { - just-flake.outputs.devShell = pkgs.mkShell { - packages = [ pkgs.just ]; - shellHook = '' - ln -sf ${builtins.toString commonJustfile} ./${cfg.commonFileName} + just-flake.features = lib.mapAttrs (_: lib.mapAttrs (_: lib.mkDefault)) { + convco.justfile = '' + # Generate CHANGELOG.md using recent commits + changelog: + convco changelog -p "" + ''; + rust.justfile = '' + # Compile and watch the project + w: + cargo watch - echo - echo "🍎🍎 Run 'just ' to get started" - just --list + # Run and watch 'cargo test' + test: + cargo watch -s "cargo test" + ''; + treefmt.justfile = '' + # Auto-format the source tree using treefmt + fmt: + treefmt ''; }; + just-flake.outputs.devShell = + let + commonJustfile = pkgs.writeTextFile { + name = "justfile"; + text = + lib.concatStringsSep "\n" + (lib.mapAttrsToList (name: feature: feature.outputs.justfile) cfg.features); + }; + in + pkgs.mkShell { + packages = [ pkgs.just ]; + shellHook = '' + ln -sf ${builtins.toString commonJustfile} ./${cfg.commonFileName} + + echo + echo "🍎🍎 Run 'just ' to get started" + just --list + ''; + }; }; }; } diff --git a/nix/feature.nix b/nix/feature.nix index 89d41b7..1daca27 100644 --- a/nix/feature.nix +++ b/nix/feature.nix @@ -1,22 +1,20 @@ -{ config, name, justfile, pkgs, lib, ... }: +{ config, name, lib, pkgs, ... }: -let - mkJustfileOption = text: lib.mkOption { - type = lib.types.path; - readOnly = true; - description = '' - The justfile representing this feature. - ''; - default = pkgs.writeTextFile { - name = "${name}.just"; - inherit text; - }; - }; -in { options = { enable = lib.mkEnableOption "Enable this feature"; - justfile = mkJustfileOption justfile; + justfile = lib.mkOption { + type = lib.types.either lib.types.str lib.types.path; + description = '' + The justfile representing this feature. + ''; + apply = x: + if builtins.isPath x then x else + pkgs.writeTextFile { + name = "${name}.just"; + text = x; + }; + }; outputs.justfile = lib.mkOption { type = lib.types.str; readOnly = true; diff --git a/nix/features/convco.nix b/nix/features/convco.nix deleted file mode 100644 index 18fc2a7..0000000 --- a/nix/features/convco.nix +++ /dev/null @@ -1,9 +0,0 @@ -{ - name = "convco"; - description = "Add the 'changelog' target calling convco"; - justfile = '' - # Generate CHANGELOG.md using recent commits - changelog: - convco changelog -p "" - ''; -} diff --git a/nix/features/rust.nix b/nix/features/rust.nix deleted file mode 100644 index 182ffcc..0000000 --- a/nix/features/rust.nix +++ /dev/null @@ -1,13 +0,0 @@ -{ - name = "rust"; - description = "Add 'w' and 'test' targets for running cargo"; - justfile = '' - # Compile and watch the project - w: - cargo watch - - # Run and watch 'cargo test' - test: - cargo watch -s "cargo test" - ''; -} diff --git a/nix/features/treefmt.nix b/nix/features/treefmt.nix deleted file mode 100644 index 9207839..0000000 --- a/nix/features/treefmt.nix +++ /dev/null @@ -1,9 +0,0 @@ -{ - name = "treefmt"; - description = "Add the 'fmt' target to format source tree using treefmt"; - justfile = '' - # Auto-format the source tree using treefmt - fmt: - treefmt - ''; -} From d11038aa6570f464164dd9dc27090c3fcccf5a00 Mon Sep 17 00:00:00 2001 From: Sridhar Ratnakumar Date: Tue, 16 Apr 2024 16:44:56 +1000 Subject: [PATCH 09/12] factor out --- flake-module.nix | 53 +++---------------------------------------- nix/features.nix | 58 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+), 50 deletions(-) create mode 100644 nix/features.nix diff --git a/flake-module.nix b/flake-module.nix index 3c3dbdd..1150695 100644 --- a/flake-module.nix +++ b/flake-module.nix @@ -3,11 +3,6 @@ options = let inherit (lib) types; - featureMod = { - imports = [ ./nix/feature.nix ]; - config._module.args = { inherit pkgs; }; - }; - featureType = types.submodule featureMod; in { just-flake = lib.mkOption { @@ -15,32 +10,11 @@ type = types.submoduleWith { specialArgs = { inherit pkgs; }; modules = [{ - imports = [{ - options.features = lib.mkOption { - type = types.submoduleWith { - modules = [{ freeformType = types.attrsOf featureType; }]; - specialArgs = { inherit pkgs; }; - }; - default = { }; - }; - }]; + imports = [ + ./nix/features.nix + ]; options = { - features = { - convco = lib.mkOption { - description = "Add the 'changelog' target calling convco"; - type = types.submodule { imports = [ featureMod ]; }; - }; - rust = lib.mkOption { - description = "Add 'w' and 'test' targets for running cargo"; - type = types.submodule { imports = [ featureMod ]; }; - }; - treefmt = lib.mkOption { - description = "Add the 'fmt' target to format source tree using treefmt"; - type = types.submodule { imports = [ featureMod ]; }; - }; - }; - commonFileName = lib.mkOption { type = lib.types.str; default = "just-flake.just"; @@ -66,27 +40,6 @@ cfg = config.just-flake; in { - just-flake.features = lib.mapAttrs (_: lib.mapAttrs (_: lib.mkDefault)) { - convco.justfile = '' - # Generate CHANGELOG.md using recent commits - changelog: - convco changelog -p "" - ''; - rust.justfile = '' - # Compile and watch the project - w: - cargo watch - - # Run and watch 'cargo test' - test: - cargo watch -s "cargo test" - ''; - treefmt.justfile = '' - # Auto-format the source tree using treefmt - fmt: - treefmt - ''; - }; just-flake.outputs.devShell = let commonJustfile = pkgs.writeTextFile { diff --git a/nix/features.nix b/nix/features.nix new file mode 100644 index 0000000..b877316 --- /dev/null +++ b/nix/features.nix @@ -0,0 +1,58 @@ +{ pkgs, lib, ... }: + +let + inherit (lib) types; + featureMod = { + imports = [ ./feature.nix ]; + config._module.args = { inherit pkgs; }; + }; + featureType = types.submodule featureMod; +in +{ + imports = [{ + options.features = lib.mkOption { + type = types.submoduleWith { + modules = [{ freeformType = types.attrsOf featureType; }]; + specialArgs = { inherit pkgs; }; + }; + default = { }; + }; + }]; + + options.features = { + convco = lib.mkOption { + description = "Add the 'changelog' target calling convco"; + type = types.submodule { imports = [ featureMod ]; }; + }; + rust = lib.mkOption { + description = "Add 'w' and 'test' targets for running cargo"; + type = types.submodule { imports = [ featureMod ]; }; + }; + treefmt = lib.mkOption { + description = "Add the 'fmt' target to format source tree using treefmt"; + type = types.submodule { imports = [ featureMod ]; }; + }; + }; + + config.features = lib.mapAttrs (_: lib.mapAttrs (_: lib.mkDefault)) { + convco.justfile = '' + # Generate CHANGELOG.md using recent commits + changelog: + convco changelog -p "" + ''; + rust.justfile = '' + # Compile and watch the project + w: + cargo watch + + # Run and watch 'cargo test' + test: + cargo watch -s "cargo test" + ''; + treefmt.justfile = '' + # Auto-format the source tree using treefmt + fmt: + treefmt + ''; + }; +} From 923df02286703ca460a4d6a1fd6be22368fd5a55 Mon Sep 17 00:00:00 2001 From: Sridhar Ratnakumar Date: Tue, 16 Apr 2024 16:50:40 +1000 Subject: [PATCH 10/12] readme --- README.md | 42 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 85ffce6..e16bbcd 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,42 @@ +[![project chat](https://img.shields.io/badge/zulip-join_chat-brightgreen.svg)](https://nixos.zulipchat.com/#narrow/stream/413950-nix) + # just-flake -Convenient way to use [`just`](https://just.systems/) in your Nix devShells + +Use [`just`](https://just.systems/) in your Nix devShells with re-usable and share-able targets. + +## Usage + +In your `flake.nix` + +```nix +# In flake-parts' perSystem +{ + just-flake.features = { + treefmt.enable = true; + rust.enable = true; + convco.enable = true; + hello = { + enable = true; + justfile = '' + hello: + echo Hello World + ''; + }; + }; +} +``` + +Then, add `config.just-flake.outputs.devShell` to the `inputsFrom` of your devShell. + +Resulting devShell banner: + +``` +🍎🍎 Run 'just ' to get started +Available recipes: + changelog # Generate CHANGELOG.md using recent commits + default # Display the list of recipes + fmt # Auto-format the source tree using treefmt + hello + test # Run and watch 'cargo test' + w # Compile and watch the project +``` \ No newline at end of file From e08fe33b2a6eb76765bcf9ddf5417e2007488a51 Mon Sep 17 00:00:00 2001 From: Sridhar Ratnakumar Date: Tue, 16 Apr 2024 16:53:23 +1000 Subject: [PATCH 11/12] .. --- README.md | 4 ++++ nix/features.nix | 3 +++ 2 files changed, 7 insertions(+) diff --git a/README.md b/README.md index e16bbcd..22ab945 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,10 @@ Use [`just`](https://just.systems/) in your Nix devShells with re-usable and share-able targets. +> [!WARNING] +> Module options API is subject to change. + + ## Usage In your `flake.nix` diff --git a/nix/features.nix b/nix/features.nix index b877316..b811de6 100644 --- a/nix/features.nix +++ b/nix/features.nix @@ -1,3 +1,5 @@ +# This largely inspired by the use of freeformType in +# https://github.com/cachix/git-hooks.nix/blob/master/modules/hooks.nix { pkgs, lib, ... }: let @@ -19,6 +21,7 @@ in }; }]; + # NOTE: At somepoint, we may want to add `settings` options to some of these features. options.features = { convco = lib.mkOption { description = "Add the 'changelog' target calling convco"; From 03305e53e02b069099b23ce03f534101473d99f6 Mon Sep 17 00:00:00 2001 From: Sridhar Ratnakumar Date: Tue, 16 Apr 2024 16:54:43 +1000 Subject: [PATCH 12/12] readme: more --- README.md | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 22ab945..0238be3 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ Use [`just`](https://just.systems/) in your Nix devShells with re-usable and sha ## Usage -In your `flake.nix` +In your `flake.nix`: ```nix # In flake-parts' perSystem @@ -30,6 +30,17 @@ In your `flake.nix` } ``` +In your `justfile`: + +```just +# See flake.nix (just-flake) +import 'just-flake.just' + +# Display the list of recipes +default: + @just --list +``` + Then, add `config.just-flake.outputs.devShell` to the `inputsFrom` of your devShell. Resulting devShell banner: