From 25180a5e6e3229ef7b7badc57e9c238a272752f9 Mon Sep 17 00:00:00 2001 From: Timothy DeHerrera Date: Mon, 22 Feb 2021 19:49:31 -0700 Subject: [PATCH 1/3] pkgs: use subflake to manage package sources * Resolves #118 * Leverage flakes to manage package sources & hashes * Update documentation with an example. * Add `mkVersion` function to autogenerate a version string. * Add srcs package via overlay containing all sources defined in _pkgs/flake.nix_ * Extend `flk update` with the ability to only update the given input --- doc/flk/update.md | 10 ++++++++++ flake.lock | 12 ++++++++++++ flake.nix | 1 + lib/default.nix | 5 ++++- pkgs/README.md | 32 +++++++++++++++++++++++--------- pkgs/flake.nix | 7 +++++++ shell/flk.sh | 14 +++++++++----- 7 files changed, 66 insertions(+), 15 deletions(-) create mode 100644 pkgs/flake.nix diff --git a/doc/flk/update.md b/doc/flk/update.md index e3a20e8..84f2520 100644 --- a/doc/flk/update.md +++ b/doc/flk/update.md @@ -4,3 +4,13 @@ The `update` subcommand is a simple alias for: nix flake update --recreate-lock-file --commit-lock-file ``` As it sounds, this will update your lock file, and commit it. + +## Updating Package Sources +If you pass an input name then it will only update that input. + +For example, you can update any +[package sources](../../pkgs#automatic-source-updates) you may have declared +in _pkgs/flake.nix_: +```sh +flk update srcs +``` diff --git a/flake.lock b/flake.lock index 3036624..a330e95 100644 --- a/flake.lock +++ b/flake.lock @@ -214,9 +214,21 @@ "nixos-hardware": "nixos-hardware", "nur": "nur", "override": "override", + "srcs": "srcs", "utils": "utils" } }, + "srcs": { + "locked": { + "narHash": "sha256-Ot96/oKT5+A5kdqkfYyT45cfEiqhI5UyPdEfEZjbXaA=", + "path": "./pkgs", + "type": "path" + }, + "original": { + "path": "./pkgs", + "type": "path" + } + }, "utils": { "locked": { "lastModified": 1608663846, diff --git a/flake.nix b/flake.nix index 0f4d60b..0365536 100644 --- a/flake.nix +++ b/flake.nix @@ -23,6 +23,7 @@ naersk.inputs.nixpkgs.follows = "override"; flake-compat.url = "github:edolstra/flake-compat"; flake-compat.flake = false; + srcs.url = "path:./pkgs"; }; outputs = diff --git a/lib/default.nix b/lib/default.nix index 5e3185a..c60880c 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -4,7 +4,7 @@ let pathExists filter; inherit (nixos.lib) fold filterAttrs hasSuffix mapAttrs' nameValuePair removeSuffix - recursiveUpdate genAttrs nixosSystem mkForce optionalAttrs; + recursiveUpdate genAttrs nixosSystem mkForce substring optionalAttrs; # mapFilterAttrs :: # (name -> value -> bool ) @@ -93,6 +93,8 @@ in overlays = pathsToImportedAttrs overlayPaths; + mkVersion = src: "${substring 0 8 src.lastModifiedDate}_${src.shortRev}"; + genPkgs = { self }: let inherit (self) inputs; in @@ -107,6 +109,7 @@ in (overridesOverlay overridePkgs) self.overlay (final: prev: { + srcs = self.inputs.srcs.inputs; lib = (prev.lib or { }) // { inherit (nixos.lib) nixosSystem; flk = self.lib; diff --git a/pkgs/README.md b/pkgs/README.md index dd9352f..89e34fe 100644 --- a/pkgs/README.md +++ b/pkgs/README.md @@ -14,22 +14,24 @@ the supported systems listed in the package's `meta.platforms` attribute. And, as usual, every package in the overlay is also available to any NixOS [host](../hosts). +## Automatic Source Updates +There is the added, but optional, convenience of declaring your sources in +_pkgs/flake.nix_ as an input. This allows updates to be managed automatically +by simply [updating](../doc/flk/update.md#updating-package-sources) the lock +file. No more manually entering sha256 hashes! + + ## Example pkgs/development/libraries/libinih/default.nix: ```nix -{ stdenv, meson, ninja, fetchFromGitHub, ... }: -let version = "r50"; +{ stdenv, meson, ninja, lib, srcs, ... }: +let version = "r53"; in stdenv.mkDerivation { pname = "libinih"; inherit version; - src = fetchFromGitHub { - owner = "benhoyt"; - repo = "inih"; - rev = "${version}"; - hash = "sha256-GF+TVEysaXJxSBBjMsTr2IQvRKlzdEu3rlPQ88PE3nI="; - }; + src = srcs.libinih; buildInputs = [ meson ninja ]; @@ -38,7 +40,7 @@ stdenv.mkDerivation { -Ddistro_install=true ''; - meta = with stdenv.lib; { + meta = with lib; { description = "Simple .INI file parser in C"; homepage = "https://github.com/benhoyt/inih"; maintainers = [ maintainers.divnix ]; @@ -56,4 +58,16 @@ final: prev: { } ``` +pkgs/flake.nix: +```nix +{ + description = "Package sources"; + + inputs = { + libinih.url = "github:benhoyt/inih/r53"; + libinih.flake = false; + }; +} +``` + [pkgs]: https://github.com/NixOS/nixpkgs/tree/master/pkgs diff --git a/pkgs/flake.nix b/pkgs/flake.nix new file mode 100644 index 0000000..257fbe3 --- /dev/null +++ b/pkgs/flake.nix @@ -0,0 +1,7 @@ +{ + description = "Package sources"; + + inputs = { }; + + outputs = { ... }: { }; +} diff --git a/shell/flk.sh b/shell/flk.sh index 99be02b..32b0a21 100755 --- a/shell/flk.sh +++ b/shell/flk.sh @@ -17,12 +17,12 @@ usage () { printf " %-30s %s\n\n" \ "up" "Generate $DEVSHELL_ROOT/hosts/up-$HOSTNAME.nix" \ - "update" "Update and commit the lock file" \ - "get [core|community] DEST" "Copy the desired template to DEST" \ + "update [INPUT]" "Update and commit the lock file" \ + "get (core|community) [DEST]" "Copy the desired template to DEST" \ "iso HOST" "Generate an ISO image of HOST" \ "install HOST [ARGS]" "Shortcut for nixos-install" \ "home HOST USER [switch]" "Home-manager config of USER from HOST" \ - "HOST [switch|boot|test]" "Shortcut for nixos-rebuild" + "HOST (switch|boot|test)" "Shortcut for nixos-rebuild" } case "$1" in @@ -49,14 +49,18 @@ case "$1" in ;; "update") - nix flake update --recreate-lock-file --commit-lock-file "$DEVSHELL_ROOT" + if [[ -n "$2" ]]; then + nix flake update --update-input "$2" --commit-lock-file "$DEVSHELL_ROOT" + else + nix flake update --recreate-lock-file --commit-lock-file "$DEVSHELL_ROOT" + fi ;; "get") if [[ "$2" == "core" || "$2" == "community" ]]; then nix flake new -t "github:divnix/devos/$2" "${3:-flk}" else - echo "flk get [core|community] {dest}" + echo "flk get (core|community) [DEST]" exit 1 fi ;; From e5ddc3127ba7f18a3538dab6bd28ce01ac5d738f Mon Sep 17 00:00:00 2001 From: Timothy DeHerrera Date: Thu, 25 Feb 2021 23:43:03 -0700 Subject: [PATCH 2/3] pkgs#flake: fix flake-compat support https://github.com/edolstra/flake-compat/pull/18 --- flake.lock | 11 ++++++----- flake.nix | 2 +- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/flake.lock b/flake.lock index a330e95..5e3223f 100644 --- a/flake.lock +++ b/flake.lock @@ -74,15 +74,16 @@ "flake-compat": { "flake": false, "locked": { - "lastModified": 1606424373, - "narHash": "sha256-oq8d4//CJOrVj+EcOaSXvMebvuTkmBJuT5tzlfewUnQ=", - "owner": "edolstra", + "lastModified": 1611461076, + "narHash": "sha256-ad++dTtMNeitUIKi1c66aTrVJOSf+mdZTrGrXzjDr6Q=", + "owner": "BBBSnowball", "repo": "flake-compat", - "rev": "99f1c2157fba4bfe6211a321fd0ee43199025dbf", + "rev": "a565cb46bee9fa856a6c15bc9c3bb947fbb784ec", "type": "github" }, "original": { - "owner": "edolstra", + "owner": "BBBSnowball", + "ref": "pr-1", "repo": "flake-compat", "type": "github" } diff --git a/flake.nix b/flake.nix index 0365536..4142656 100644 --- a/flake.nix +++ b/flake.nix @@ -21,7 +21,7 @@ deploy.inputs.flake-compat.follows = "flake-compat"; naersk.url = "github:nmattia/naersk"; naersk.inputs.nixpkgs.follows = "override"; - flake-compat.url = "github:edolstra/flake-compat"; + flake-compat.url = "github:BBBSnowball/flake-compat/pr-1"; flake-compat.flake = false; srcs.url = "path:./pkgs"; }; From 088b51a020ea08d5478e4ef6bc6845764c779716 Mon Sep 17 00:00:00 2001 From: Timothy DeHerrera Date: Fri, 26 Feb 2021 00:07:40 -0700 Subject: [PATCH 3/3] README.md: emphasize source management --- README.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index bf10e97..94b7292 100644 --- a/README.md +++ b/README.md @@ -12,8 +12,10 @@ # Introduction DevOS grants a simple way to use, deploy and manage [NixOS][nixos] systems for personal and productive use. It does this by providing a convenient repository -structure; integrating several popular projects like -[home-manager][home-manager], and [devshell][devshell]. +structure, integrating several popular projects like +[home-manager][home-manager], and [devshell][devshell], and offering useful +conveniences like +[automatic source updates](./pkgs#automatic-source-updates). Skip the indeterminate nature of other systems, _and_ the perceived difficulty of Nix. It's easier than you think!