From 09505225e1aedec607c1d17b38fbbd8ff928727e Mon Sep 17 00:00:00 2001 From: Daniil Iaitskov Date: Fri, 14 Nov 2025 16:44:47 +0300 Subject: [PATCH 01/18] nix ignore nix output dir --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index f94ebc47b..abe9b641c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ dist dist-* +result cabal-dev *.o *.hi From 711844586b2e0e9379a953666bafaa3753d87d9c Mon Sep 17 00:00:00 2001 From: Daniil Iaitskov Date: Fri, 14 Nov 2025 16:45:21 +0300 Subject: [PATCH 02/18] nix note bluespec test long execution time --- copilot-bluespec/README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/copilot-bluespec/README.md b/copilot-bluespec/README.md index e85d9e8c5..b21f7612b 100644 --- a/copilot-bluespec/README.md +++ b/copilot-bluespec/README.md @@ -25,6 +25,8 @@ $ cabal install copilot $ cabal install copilot-bluespec ``` +Test execution time is about 5 minutes. + For more detailed instructions on how to install Copilot, please refer to the [Copilot website](https://copilot-language.github.io). From 999d8b38f6dcffde44d91398a0637f1823c48901 Mon Sep 17 00:00:00 2001 From: Daniil Iaitskov Date: Fri, 14 Nov 2025 16:47:49 +0300 Subject: [PATCH 03/18] nix resolve version collision among cabal packages: crux what4 llvm-pretty --- copilot-theorem/copilot-theorem.cabal | 2 +- copilot-verifier/copilot-verifier.cabal | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/copilot-theorem/copilot-theorem.cabal b/copilot-theorem/copilot-theorem.cabal index b830f91a6..30047cca7 100644 --- a/copilot-theorem/copilot-theorem.cabal +++ b/copilot-theorem/copilot-theorem.cabal @@ -60,7 +60,7 @@ library , random >= 1.1 && < 1.3 , transformers >= 0.5 && < 0.7 , xml >= 1.3 && < 1.4 - , what4 >= 1.3 && < 1.8 + , what4 >= 1.7 && < 1.8 , copilot-core >= 4.6 && < 4.7 , copilot-prettyprinter >= 4.6 && < 4.7 diff --git a/copilot-verifier/copilot-verifier.cabal b/copilot-verifier/copilot-verifier.cabal index 9c6bed8d5..ce1490974 100644 --- a/copilot-verifier/copilot-verifier.cabal +++ b/copilot-verifier/copilot-verifier.cabal @@ -51,10 +51,10 @@ common bldflags crucible >= 0.7.1 && < 0.8, crucible-llvm >= 0.7 && < 0.8, crux >= 0.7.1 && < 0.8, - crux-llvm >= 0.9 && < 0.10, + crux-llvm >= 0.9 && < 0.11, filepath, lens, - llvm-pretty >= 0.12.1.0 && < 0.13, + llvm-pretty >= 0.12.1.0 && < 0.14, mtl, panic >= 0.3, parameterized-utils >= 2.1.4 && < 2.2, @@ -62,7 +62,7 @@ common bldflags text, transformers, vector, - what4 >= 1.6.1 && < 1.7 + what4 >= 1.6.1 && < 1.8 library import: bldflags From 5c3b89ca7e8f0ac69e74427e69427f19533ba1ec Mon Sep 17 00:00:00 2001 From: Daniil Iaitskov Date: Fri, 14 Nov 2025 17:00:49 +0300 Subject: [PATCH 04/18] nix use cabal2nix for every subpackage --- copilot-bluespec/default.nix | 32 ++++ copilot-bluespec/nix/sources.json | 12 ++ copilot-bluespec/nix/sources.nix | 198 +++++++++++++++++++++++++ copilot-c99/default.nix | 28 ++++ copilot-c99/nix/sources.json | 12 ++ copilot-c99/nix/sources.nix | 198 +++++++++++++++++++++++++ copilot-core/default.nix | 26 ++++ copilot-core/nix/sources.json | 12 ++ copilot-core/nix/sources.nix | 198 +++++++++++++++++++++++++ copilot-interpreter/default.nix | 29 ++++ copilot-interpreter/nix/sources.json | 12 ++ copilot-interpreter/nix/sources.nix | 198 +++++++++++++++++++++++++ copilot-language/default.nix | 31 ++++ copilot-language/nix/sources.json | 12 ++ copilot-language/nix/sources.nix | 198 +++++++++++++++++++++++++ copilot-libraries/default.nix | 37 +++++ copilot-libraries/nix/sources.json | 12 ++ copilot-libraries/nix/sources.nix | 198 +++++++++++++++++++++++++ copilot-prettyprinter/default.nix | 28 ++++ copilot-prettyprinter/nix/sources.json | 12 ++ copilot-prettyprinter/nix/sources.nix | 198 +++++++++++++++++++++++++ copilot-theorem/default.nix | 45 ++++++ copilot-theorem/nix/sources.json | 12 ++ copilot-theorem/nix/sources.nix | 198 +++++++++++++++++++++++++ copilot-verifier/default.nix | 76 ++++++++++ copilot-verifier/nix/sources.json | 12 ++ copilot-verifier/nix/sources.nix | 198 +++++++++++++++++++++++++ copilot-visualizer/default.nix | 33 +++++ copilot-visualizer/nix/sources.json | 12 ++ copilot-visualizer/nix/sources.nix | 198 +++++++++++++++++++++++++ copilot/default.nix | 38 +++++ copilot/nix/sources.json | 12 ++ copilot/nix/sources.nix | 198 +++++++++++++++++++++++++ 33 files changed, 2713 insertions(+) create mode 100644 copilot-bluespec/default.nix create mode 100644 copilot-bluespec/nix/sources.json create mode 100644 copilot-bluespec/nix/sources.nix create mode 100644 copilot-c99/default.nix create mode 100644 copilot-c99/nix/sources.json create mode 100644 copilot-c99/nix/sources.nix create mode 100644 copilot-core/default.nix create mode 100644 copilot-core/nix/sources.json create mode 100644 copilot-core/nix/sources.nix create mode 100644 copilot-interpreter/default.nix create mode 100644 copilot-interpreter/nix/sources.json create mode 100644 copilot-interpreter/nix/sources.nix create mode 100644 copilot-language/default.nix create mode 100644 copilot-language/nix/sources.json create mode 100644 copilot-language/nix/sources.nix create mode 100644 copilot-libraries/default.nix create mode 100644 copilot-libraries/nix/sources.json create mode 100644 copilot-libraries/nix/sources.nix create mode 100644 copilot-prettyprinter/default.nix create mode 100644 copilot-prettyprinter/nix/sources.json create mode 100644 copilot-prettyprinter/nix/sources.nix create mode 100644 copilot-theorem/default.nix create mode 100644 copilot-theorem/nix/sources.json create mode 100644 copilot-theorem/nix/sources.nix create mode 100644 copilot-verifier/default.nix create mode 100644 copilot-verifier/nix/sources.json create mode 100644 copilot-verifier/nix/sources.nix create mode 100644 copilot-visualizer/default.nix create mode 100644 copilot-visualizer/nix/sources.json create mode 100644 copilot-visualizer/nix/sources.nix create mode 100644 copilot/default.nix create mode 100644 copilot/nix/sources.json create mode 100644 copilot/nix/sources.nix diff --git a/copilot-bluespec/default.nix b/copilot-bluespec/default.nix new file mode 100644 index 000000000..10c273eb2 --- /dev/null +++ b/copilot-bluespec/default.nix @@ -0,0 +1,32 @@ +{ sources ? import ./nix/sources.nix, ghc ? "ghc98" }: +let + depOverlay = n: o: { + copilot-core = (import ../copilot-core { inherit sources ghc; }).copilot-core; + }; + np = import sources.nixpkgs {}; + bhp = np.haskell.packages.${ghc}; + + sourceRegexes = [ + "^src.*$" + "^tests.*$" + "^.*\\.cabal$" + "^LICENSE$" + ]; + + copilot-bluespec-base = + (hp.callCabal2nix "copilot-bluespec" (np.lib.sourceByRegex ./. sourceRegexes) {} + ).overrideAttrs(oa: { + nativeBuildInputs = [ np.bluespec np.removeReferencesTo ]; + }); + copilot-bluespec-overlay = _n: _o: { copilot-bluespec = copilot-bluespec-base; }; + hp = bhp.override (o: { + overrides = + builtins.foldl' np.lib.composeExtensions (o.overrides or (_: _: {})) + [ depOverlay copilot-bluespec-overlay ]; + }); + copilot-bluespec = hp.copilot-bluespec; +in { + inherit np; + inherit hp; + inherit copilot-bluespec; +} diff --git a/copilot-bluespec/nix/sources.json b/copilot-bluespec/nix/sources.json new file mode 100644 index 000000000..7a59ceccc --- /dev/null +++ b/copilot-bluespec/nix/sources.json @@ -0,0 +1,12 @@ +{ + "nixpkgs": { + "branch": "master", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "63117158fe4f7f9b34eaecef088c417f8151e4ba", + "sha256": "sha256:036cjpfjghm6f8h4cldpv040kfvii7x8g5php4vyn9qmpncybxj6", + "type": "tarball", + "url": "https://github.com/NixOS/nixpkgs/archive/63117158fe4f7f9b34eaecef088c417f8151e4ba.tar.gz", + "url_template": "https://github.com///archive/.tar.gz" + } +} diff --git a/copilot-bluespec/nix/sources.nix b/copilot-bluespec/nix/sources.nix new file mode 100644 index 000000000..fe3dadf7e --- /dev/null +++ b/copilot-bluespec/nix/sources.nix @@ -0,0 +1,198 @@ +# This file has been generated by Niv. + +let + + # + # The fetchers. fetch_ fetches specs of type . + # + + fetch_file = pkgs: name: spec: + let + name' = sanitizeName name + "-src"; + in + if spec.builtin or true then + builtins_fetchurl { inherit (spec) url sha256; name = name'; } + else + pkgs.fetchurl { inherit (spec) url sha256; name = name'; }; + + fetch_tarball = pkgs: name: spec: + let + name' = sanitizeName name + "-src"; + in + if spec.builtin or true then + builtins_fetchTarball { name = name'; inherit (spec) url sha256; } + else + pkgs.fetchzip { name = name'; inherit (spec) url sha256; }; + + fetch_git = name: spec: + let + ref = + spec.ref or ( + if spec ? branch then "refs/heads/${spec.branch}" else + if spec ? tag then "refs/tags/${spec.tag}" else + abort "In git source '${name}': Please specify `ref`, `tag` or `branch`!" + ); + submodules = spec.submodules or false; + submoduleArg = + let + nixSupportsSubmodules = builtins.compareVersions builtins.nixVersion "2.4" >= 0; + emptyArgWithWarning = + if submodules + then + builtins.trace + ( + "The niv input \"${name}\" uses submodules " + + "but your nix's (${builtins.nixVersion}) builtins.fetchGit " + + "does not support them" + ) + { } + else { }; + in + if nixSupportsSubmodules + then { inherit submodules; } + else emptyArgWithWarning; + in + builtins.fetchGit + ({ url = spec.repo; inherit (spec) rev; inherit ref; } // submoduleArg); + + fetch_local = spec: spec.path; + + fetch_builtin-tarball = name: throw + ''[${name}] The niv type "builtin-tarball" is deprecated. You should instead use `builtin = true`. + $ niv modify ${name} -a type=tarball -a builtin=true''; + + fetch_builtin-url = name: throw + ''[${name}] The niv type "builtin-url" will soon be deprecated. You should instead use `builtin = true`. + $ niv modify ${name} -a type=file -a builtin=true''; + + # + # Various helpers + # + + # https://github.com/NixOS/nixpkgs/pull/83241/files#diff-c6f540a4f3bfa4b0e8b6bafd4cd54e8bR695 + sanitizeName = name: + ( + concatMapStrings (s: if builtins.isList s then "-" else s) + ( + builtins.split "[^[:alnum:]+._?=-]+" + ((x: builtins.elemAt (builtins.match "\\.*(.*)" x) 0) name) + ) + ); + + # The set of packages used when specs are fetched using non-builtins. + mkPkgs = sources: system: + let + sourcesNixpkgs = + import (builtins_fetchTarball { inherit (sources.nixpkgs) url sha256; }) { inherit system; }; + hasNixpkgsPath = builtins.any (x: x.prefix == "nixpkgs") builtins.nixPath; + hasThisAsNixpkgsPath = == ./.; + in + if builtins.hasAttr "nixpkgs" sources + then sourcesNixpkgs + else if hasNixpkgsPath && ! hasThisAsNixpkgsPath then + import { } + else + abort + '' + Please specify either (through -I or NIX_PATH=nixpkgs=...) or + add a package called "nixpkgs" to your sources.json. + ''; + + # The actual fetching function. + fetch = pkgs: name: spec: + + if ! builtins.hasAttr "type" spec then + abort "ERROR: niv spec ${name} does not have a 'type' attribute" + else if spec.type == "file" then fetch_file pkgs name spec + else if spec.type == "tarball" then fetch_tarball pkgs name spec + else if spec.type == "git" then fetch_git name spec + else if spec.type == "local" then fetch_local spec + else if spec.type == "builtin-tarball" then fetch_builtin-tarball name + else if spec.type == "builtin-url" then fetch_builtin-url name + else + abort "ERROR: niv spec ${name} has unknown type ${builtins.toJSON spec.type}"; + + # If the environment variable NIV_OVERRIDE_${name} is set, then use + # the path directly as opposed to the fetched source. + replace = name: drv: + let + saneName = stringAsChars (c: if (builtins.match "[a-zA-Z0-9]" c) == null then "_" else c) name; + ersatz = builtins.getEnv "NIV_OVERRIDE_${saneName}"; + in + if ersatz == "" then drv else + # this turns the string into an actual Nix path (for both absolute and + # relative paths) + if builtins.substring 0 1 ersatz == "/" then /. + ersatz else /. + builtins.getEnv "PWD" + "/${ersatz}"; + + # Ports of functions for older nix versions + + # a Nix version of mapAttrs if the built-in doesn't exist + mapAttrs = builtins.mapAttrs or ( + f: set: with builtins; + listToAttrs (map (attr: { name = attr; value = f attr set.${attr}; }) (attrNames set)) + ); + + # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/lists.nix#L295 + range = first: last: if first > last then [ ] else builtins.genList (n: first + n) (last - first + 1); + + # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/strings.nix#L257 + stringToCharacters = s: map (p: builtins.substring p 1 s) (range 0 (builtins.stringLength s - 1)); + + # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/strings.nix#L269 + stringAsChars = f: s: concatStrings (map f (stringToCharacters s)); + concatMapStrings = f: list: concatStrings (map f list); + concatStrings = builtins.concatStringsSep ""; + + # https://github.com/NixOS/nixpkgs/blob/8a9f58a375c401b96da862d969f66429def1d118/lib/attrsets.nix#L331 + optionalAttrs = cond: as: if cond then as else { }; + + # fetchTarball version that is compatible between all the versions of Nix + builtins_fetchTarball = { url, name ? null, sha256 }@attrs: + let + inherit (builtins) lessThan nixVersion fetchTarball; + in + if lessThan nixVersion "1.12" then + fetchTarball ({ inherit url; } // (optionalAttrs (name != null) { inherit name; })) + else + fetchTarball attrs; + + # fetchurl version that is compatible between all the versions of Nix + builtins_fetchurl = { url, name ? null, sha256 }@attrs: + let + inherit (builtins) lessThan nixVersion fetchurl; + in + if lessThan nixVersion "1.12" then + fetchurl ({ inherit url; } // (optionalAttrs (name != null) { inherit name; })) + else + fetchurl attrs; + + # Create the final "sources" from the config + mkSources = config: + mapAttrs + ( + name: spec: + if builtins.hasAttr "outPath" spec + then + abort + "The values in sources.json should not have an 'outPath' attribute" + else + spec // { outPath = replace name (fetch config.pkgs name spec); } + ) + config.sources; + + # The "config" used by the fetchers + mkConfig = + { sourcesFile ? if builtins.pathExists ./sources.json then ./sources.json else null + , sources ? if sourcesFile == null then { } else builtins.fromJSON (builtins.readFile sourcesFile) + , system ? builtins.currentSystem + , pkgs ? mkPkgs sources system + }: rec { + # The sources, i.e. the attribute set of spec name to spec + inherit sources; + + # The "pkgs" (evaluated nixpkgs) to use for e.g. non-builtin fetchers + inherit pkgs; + }; + +in +mkSources (mkConfig { }) // { __functor = _: settings: mkSources (mkConfig settings); } diff --git a/copilot-c99/default.nix b/copilot-c99/default.nix new file mode 100644 index 000000000..f58092877 --- /dev/null +++ b/copilot-c99/default.nix @@ -0,0 +1,28 @@ +{ sources ? import ./nix/sources.nix, ghc ? "ghc98" }: +let + depOverlay = n: o: { + copilot-core = (import ../copilot-core { inherit sources ghc; }).copilot-core; + }; + np = import sources.nixpkgs {}; + bhp = np.haskell.packages.${ghc}; + + sourceRegexes = [ + "^src.*$" + "^tests.*$" + "^.*\\.cabal$" + "^LICENSE$" + ]; + + copilot-c99-base = hp.callCabal2nix "copilot-c99" (np.lib.sourceByRegex ./. sourceRegexes) {}; + copilot-c99-overlay = _n: _o: { copilot-c99 = copilot-c99-base; }; + hp = bhp.override (o: { + overrides = + builtins.foldl' np.lib.composeExtensions (o.overrides or (_: _: {})) + [ depOverlay copilot-c99-overlay ]; + }); + copilot-c99 = hp.copilot-c99; +in { + inherit np; + inherit hp; + inherit copilot-c99; +} diff --git a/copilot-c99/nix/sources.json b/copilot-c99/nix/sources.json new file mode 100644 index 000000000..7a59ceccc --- /dev/null +++ b/copilot-c99/nix/sources.json @@ -0,0 +1,12 @@ +{ + "nixpkgs": { + "branch": "master", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "63117158fe4f7f9b34eaecef088c417f8151e4ba", + "sha256": "sha256:036cjpfjghm6f8h4cldpv040kfvii7x8g5php4vyn9qmpncybxj6", + "type": "tarball", + "url": "https://github.com/NixOS/nixpkgs/archive/63117158fe4f7f9b34eaecef088c417f8151e4ba.tar.gz", + "url_template": "https://github.com///archive/.tar.gz" + } +} diff --git a/copilot-c99/nix/sources.nix b/copilot-c99/nix/sources.nix new file mode 100644 index 000000000..fe3dadf7e --- /dev/null +++ b/copilot-c99/nix/sources.nix @@ -0,0 +1,198 @@ +# This file has been generated by Niv. + +let + + # + # The fetchers. fetch_ fetches specs of type . + # + + fetch_file = pkgs: name: spec: + let + name' = sanitizeName name + "-src"; + in + if spec.builtin or true then + builtins_fetchurl { inherit (spec) url sha256; name = name'; } + else + pkgs.fetchurl { inherit (spec) url sha256; name = name'; }; + + fetch_tarball = pkgs: name: spec: + let + name' = sanitizeName name + "-src"; + in + if spec.builtin or true then + builtins_fetchTarball { name = name'; inherit (spec) url sha256; } + else + pkgs.fetchzip { name = name'; inherit (spec) url sha256; }; + + fetch_git = name: spec: + let + ref = + spec.ref or ( + if spec ? branch then "refs/heads/${spec.branch}" else + if spec ? tag then "refs/tags/${spec.tag}" else + abort "In git source '${name}': Please specify `ref`, `tag` or `branch`!" + ); + submodules = spec.submodules or false; + submoduleArg = + let + nixSupportsSubmodules = builtins.compareVersions builtins.nixVersion "2.4" >= 0; + emptyArgWithWarning = + if submodules + then + builtins.trace + ( + "The niv input \"${name}\" uses submodules " + + "but your nix's (${builtins.nixVersion}) builtins.fetchGit " + + "does not support them" + ) + { } + else { }; + in + if nixSupportsSubmodules + then { inherit submodules; } + else emptyArgWithWarning; + in + builtins.fetchGit + ({ url = spec.repo; inherit (spec) rev; inherit ref; } // submoduleArg); + + fetch_local = spec: spec.path; + + fetch_builtin-tarball = name: throw + ''[${name}] The niv type "builtin-tarball" is deprecated. You should instead use `builtin = true`. + $ niv modify ${name} -a type=tarball -a builtin=true''; + + fetch_builtin-url = name: throw + ''[${name}] The niv type "builtin-url" will soon be deprecated. You should instead use `builtin = true`. + $ niv modify ${name} -a type=file -a builtin=true''; + + # + # Various helpers + # + + # https://github.com/NixOS/nixpkgs/pull/83241/files#diff-c6f540a4f3bfa4b0e8b6bafd4cd54e8bR695 + sanitizeName = name: + ( + concatMapStrings (s: if builtins.isList s then "-" else s) + ( + builtins.split "[^[:alnum:]+._?=-]+" + ((x: builtins.elemAt (builtins.match "\\.*(.*)" x) 0) name) + ) + ); + + # The set of packages used when specs are fetched using non-builtins. + mkPkgs = sources: system: + let + sourcesNixpkgs = + import (builtins_fetchTarball { inherit (sources.nixpkgs) url sha256; }) { inherit system; }; + hasNixpkgsPath = builtins.any (x: x.prefix == "nixpkgs") builtins.nixPath; + hasThisAsNixpkgsPath = == ./.; + in + if builtins.hasAttr "nixpkgs" sources + then sourcesNixpkgs + else if hasNixpkgsPath && ! hasThisAsNixpkgsPath then + import { } + else + abort + '' + Please specify either (through -I or NIX_PATH=nixpkgs=...) or + add a package called "nixpkgs" to your sources.json. + ''; + + # The actual fetching function. + fetch = pkgs: name: spec: + + if ! builtins.hasAttr "type" spec then + abort "ERROR: niv spec ${name} does not have a 'type' attribute" + else if spec.type == "file" then fetch_file pkgs name spec + else if spec.type == "tarball" then fetch_tarball pkgs name spec + else if spec.type == "git" then fetch_git name spec + else if spec.type == "local" then fetch_local spec + else if spec.type == "builtin-tarball" then fetch_builtin-tarball name + else if spec.type == "builtin-url" then fetch_builtin-url name + else + abort "ERROR: niv spec ${name} has unknown type ${builtins.toJSON spec.type}"; + + # If the environment variable NIV_OVERRIDE_${name} is set, then use + # the path directly as opposed to the fetched source. + replace = name: drv: + let + saneName = stringAsChars (c: if (builtins.match "[a-zA-Z0-9]" c) == null then "_" else c) name; + ersatz = builtins.getEnv "NIV_OVERRIDE_${saneName}"; + in + if ersatz == "" then drv else + # this turns the string into an actual Nix path (for both absolute and + # relative paths) + if builtins.substring 0 1 ersatz == "/" then /. + ersatz else /. + builtins.getEnv "PWD" + "/${ersatz}"; + + # Ports of functions for older nix versions + + # a Nix version of mapAttrs if the built-in doesn't exist + mapAttrs = builtins.mapAttrs or ( + f: set: with builtins; + listToAttrs (map (attr: { name = attr; value = f attr set.${attr}; }) (attrNames set)) + ); + + # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/lists.nix#L295 + range = first: last: if first > last then [ ] else builtins.genList (n: first + n) (last - first + 1); + + # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/strings.nix#L257 + stringToCharacters = s: map (p: builtins.substring p 1 s) (range 0 (builtins.stringLength s - 1)); + + # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/strings.nix#L269 + stringAsChars = f: s: concatStrings (map f (stringToCharacters s)); + concatMapStrings = f: list: concatStrings (map f list); + concatStrings = builtins.concatStringsSep ""; + + # https://github.com/NixOS/nixpkgs/blob/8a9f58a375c401b96da862d969f66429def1d118/lib/attrsets.nix#L331 + optionalAttrs = cond: as: if cond then as else { }; + + # fetchTarball version that is compatible between all the versions of Nix + builtins_fetchTarball = { url, name ? null, sha256 }@attrs: + let + inherit (builtins) lessThan nixVersion fetchTarball; + in + if lessThan nixVersion "1.12" then + fetchTarball ({ inherit url; } // (optionalAttrs (name != null) { inherit name; })) + else + fetchTarball attrs; + + # fetchurl version that is compatible between all the versions of Nix + builtins_fetchurl = { url, name ? null, sha256 }@attrs: + let + inherit (builtins) lessThan nixVersion fetchurl; + in + if lessThan nixVersion "1.12" then + fetchurl ({ inherit url; } // (optionalAttrs (name != null) { inherit name; })) + else + fetchurl attrs; + + # Create the final "sources" from the config + mkSources = config: + mapAttrs + ( + name: spec: + if builtins.hasAttr "outPath" spec + then + abort + "The values in sources.json should not have an 'outPath' attribute" + else + spec // { outPath = replace name (fetch config.pkgs name spec); } + ) + config.sources; + + # The "config" used by the fetchers + mkConfig = + { sourcesFile ? if builtins.pathExists ./sources.json then ./sources.json else null + , sources ? if sourcesFile == null then { } else builtins.fromJSON (builtins.readFile sourcesFile) + , system ? builtins.currentSystem + , pkgs ? mkPkgs sources system + }: rec { + # The sources, i.e. the attribute set of spec name to spec + inherit sources; + + # The "pkgs" (evaluated nixpkgs) to use for e.g. non-builtin fetchers + inherit pkgs; + }; + +in +mkSources (mkConfig { }) // { __functor = _: settings: mkSources (mkConfig settings); } diff --git a/copilot-core/default.nix b/copilot-core/default.nix new file mode 100644 index 000000000..b4b2cea8c --- /dev/null +++ b/copilot-core/default.nix @@ -0,0 +1,26 @@ +{ sources ? import ./nix/sources.nix, ghc ? "ghc98" }: +let + np = import sources.nixpkgs {}; + hp = np.haskell.packages.${ghc}; + + sourceRegexes = [ + "^src.*$" + "^tests.*$" + "^.*\\.cabal$" + "^LICENSE$" + ]; + + copilot-core = hp.callCabal2nix "copilot-core" (np.lib.sourceByRegex ./. sourceRegexes) {}; + # copilot-core-overlay = _n: _o: { copilot-core = copilot-core-base; }; + # hp = bhp.override (o: { + # overrides = + # builtins.foldl' np.lib.composeExtensions (o.overrides or (_: _: {})) + # [ copilot-core-overlay ]; + # }); + # copilot-core = hp.copilot-core; + +in { + inherit np; + inherit hp; + inherit copilot-core; +} diff --git a/copilot-core/nix/sources.json b/copilot-core/nix/sources.json new file mode 100644 index 000000000..7a59ceccc --- /dev/null +++ b/copilot-core/nix/sources.json @@ -0,0 +1,12 @@ +{ + "nixpkgs": { + "branch": "master", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "63117158fe4f7f9b34eaecef088c417f8151e4ba", + "sha256": "sha256:036cjpfjghm6f8h4cldpv040kfvii7x8g5php4vyn9qmpncybxj6", + "type": "tarball", + "url": "https://github.com/NixOS/nixpkgs/archive/63117158fe4f7f9b34eaecef088c417f8151e4ba.tar.gz", + "url_template": "https://github.com///archive/.tar.gz" + } +} diff --git a/copilot-core/nix/sources.nix b/copilot-core/nix/sources.nix new file mode 100644 index 000000000..fe3dadf7e --- /dev/null +++ b/copilot-core/nix/sources.nix @@ -0,0 +1,198 @@ +# This file has been generated by Niv. + +let + + # + # The fetchers. fetch_ fetches specs of type . + # + + fetch_file = pkgs: name: spec: + let + name' = sanitizeName name + "-src"; + in + if spec.builtin or true then + builtins_fetchurl { inherit (spec) url sha256; name = name'; } + else + pkgs.fetchurl { inherit (spec) url sha256; name = name'; }; + + fetch_tarball = pkgs: name: spec: + let + name' = sanitizeName name + "-src"; + in + if spec.builtin or true then + builtins_fetchTarball { name = name'; inherit (spec) url sha256; } + else + pkgs.fetchzip { name = name'; inherit (spec) url sha256; }; + + fetch_git = name: spec: + let + ref = + spec.ref or ( + if spec ? branch then "refs/heads/${spec.branch}" else + if spec ? tag then "refs/tags/${spec.tag}" else + abort "In git source '${name}': Please specify `ref`, `tag` or `branch`!" + ); + submodules = spec.submodules or false; + submoduleArg = + let + nixSupportsSubmodules = builtins.compareVersions builtins.nixVersion "2.4" >= 0; + emptyArgWithWarning = + if submodules + then + builtins.trace + ( + "The niv input \"${name}\" uses submodules " + + "but your nix's (${builtins.nixVersion}) builtins.fetchGit " + + "does not support them" + ) + { } + else { }; + in + if nixSupportsSubmodules + then { inherit submodules; } + else emptyArgWithWarning; + in + builtins.fetchGit + ({ url = spec.repo; inherit (spec) rev; inherit ref; } // submoduleArg); + + fetch_local = spec: spec.path; + + fetch_builtin-tarball = name: throw + ''[${name}] The niv type "builtin-tarball" is deprecated. You should instead use `builtin = true`. + $ niv modify ${name} -a type=tarball -a builtin=true''; + + fetch_builtin-url = name: throw + ''[${name}] The niv type "builtin-url" will soon be deprecated. You should instead use `builtin = true`. + $ niv modify ${name} -a type=file -a builtin=true''; + + # + # Various helpers + # + + # https://github.com/NixOS/nixpkgs/pull/83241/files#diff-c6f540a4f3bfa4b0e8b6bafd4cd54e8bR695 + sanitizeName = name: + ( + concatMapStrings (s: if builtins.isList s then "-" else s) + ( + builtins.split "[^[:alnum:]+._?=-]+" + ((x: builtins.elemAt (builtins.match "\\.*(.*)" x) 0) name) + ) + ); + + # The set of packages used when specs are fetched using non-builtins. + mkPkgs = sources: system: + let + sourcesNixpkgs = + import (builtins_fetchTarball { inherit (sources.nixpkgs) url sha256; }) { inherit system; }; + hasNixpkgsPath = builtins.any (x: x.prefix == "nixpkgs") builtins.nixPath; + hasThisAsNixpkgsPath = == ./.; + in + if builtins.hasAttr "nixpkgs" sources + then sourcesNixpkgs + else if hasNixpkgsPath && ! hasThisAsNixpkgsPath then + import { } + else + abort + '' + Please specify either (through -I or NIX_PATH=nixpkgs=...) or + add a package called "nixpkgs" to your sources.json. + ''; + + # The actual fetching function. + fetch = pkgs: name: spec: + + if ! builtins.hasAttr "type" spec then + abort "ERROR: niv spec ${name} does not have a 'type' attribute" + else if spec.type == "file" then fetch_file pkgs name spec + else if spec.type == "tarball" then fetch_tarball pkgs name spec + else if spec.type == "git" then fetch_git name spec + else if spec.type == "local" then fetch_local spec + else if spec.type == "builtin-tarball" then fetch_builtin-tarball name + else if spec.type == "builtin-url" then fetch_builtin-url name + else + abort "ERROR: niv spec ${name} has unknown type ${builtins.toJSON spec.type}"; + + # If the environment variable NIV_OVERRIDE_${name} is set, then use + # the path directly as opposed to the fetched source. + replace = name: drv: + let + saneName = stringAsChars (c: if (builtins.match "[a-zA-Z0-9]" c) == null then "_" else c) name; + ersatz = builtins.getEnv "NIV_OVERRIDE_${saneName}"; + in + if ersatz == "" then drv else + # this turns the string into an actual Nix path (for both absolute and + # relative paths) + if builtins.substring 0 1 ersatz == "/" then /. + ersatz else /. + builtins.getEnv "PWD" + "/${ersatz}"; + + # Ports of functions for older nix versions + + # a Nix version of mapAttrs if the built-in doesn't exist + mapAttrs = builtins.mapAttrs or ( + f: set: with builtins; + listToAttrs (map (attr: { name = attr; value = f attr set.${attr}; }) (attrNames set)) + ); + + # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/lists.nix#L295 + range = first: last: if first > last then [ ] else builtins.genList (n: first + n) (last - first + 1); + + # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/strings.nix#L257 + stringToCharacters = s: map (p: builtins.substring p 1 s) (range 0 (builtins.stringLength s - 1)); + + # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/strings.nix#L269 + stringAsChars = f: s: concatStrings (map f (stringToCharacters s)); + concatMapStrings = f: list: concatStrings (map f list); + concatStrings = builtins.concatStringsSep ""; + + # https://github.com/NixOS/nixpkgs/blob/8a9f58a375c401b96da862d969f66429def1d118/lib/attrsets.nix#L331 + optionalAttrs = cond: as: if cond then as else { }; + + # fetchTarball version that is compatible between all the versions of Nix + builtins_fetchTarball = { url, name ? null, sha256 }@attrs: + let + inherit (builtins) lessThan nixVersion fetchTarball; + in + if lessThan nixVersion "1.12" then + fetchTarball ({ inherit url; } // (optionalAttrs (name != null) { inherit name; })) + else + fetchTarball attrs; + + # fetchurl version that is compatible between all the versions of Nix + builtins_fetchurl = { url, name ? null, sha256 }@attrs: + let + inherit (builtins) lessThan nixVersion fetchurl; + in + if lessThan nixVersion "1.12" then + fetchurl ({ inherit url; } // (optionalAttrs (name != null) { inherit name; })) + else + fetchurl attrs; + + # Create the final "sources" from the config + mkSources = config: + mapAttrs + ( + name: spec: + if builtins.hasAttr "outPath" spec + then + abort + "The values in sources.json should not have an 'outPath' attribute" + else + spec // { outPath = replace name (fetch config.pkgs name spec); } + ) + config.sources; + + # The "config" used by the fetchers + mkConfig = + { sourcesFile ? if builtins.pathExists ./sources.json then ./sources.json else null + , sources ? if sourcesFile == null then { } else builtins.fromJSON (builtins.readFile sourcesFile) + , system ? builtins.currentSystem + , pkgs ? mkPkgs sources system + }: rec { + # The sources, i.e. the attribute set of spec name to spec + inherit sources; + + # The "pkgs" (evaluated nixpkgs) to use for e.g. non-builtin fetchers + inherit pkgs; + }; + +in +mkSources (mkConfig { }) // { __functor = _: settings: mkSources (mkConfig settings); } diff --git a/copilot-interpreter/default.nix b/copilot-interpreter/default.nix new file mode 100644 index 000000000..b48893682 --- /dev/null +++ b/copilot-interpreter/default.nix @@ -0,0 +1,29 @@ +{ sources ? import ./nix/sources.nix, ghc ? "ghc98" }: +let + depOverlay = n: o: { + copilot-core = (import ../copilot-core { inherit sources ghc; }).copilot-core; + copilot-prettyprinter = (import ../copilot-prettyprinter { inherit sources ghc; }).copilot-prettyprinter; + }; + np = import sources.nixpkgs {}; + bhp = np.haskell.packages.${ghc}; + + sourceRegexes = [ + "^src.*$" + "^tests.*$" + "^.*\\.cabal$" + "^LICENSE$" + ]; + + copilot-interpreter-base = hp.callCabal2nix "copilot-interpreter" (np.lib.sourceByRegex ./. sourceRegexes) {}; + copilot-interpreter-overlay = _n: _o: { copilot-interpreter = copilot-interpreter-base; }; + hp = bhp.override (o: { + overrides = + builtins.foldl' np.lib.composeExtensions (o.overrides or (_: _: {})) + [ depOverlay copilot-interpreter-overlay ]; + }); + copilot-interpreter = hp.copilot-interpreter; +in { + inherit np; + inherit hp; + inherit copilot-interpreter; +} diff --git a/copilot-interpreter/nix/sources.json b/copilot-interpreter/nix/sources.json new file mode 100644 index 000000000..7a59ceccc --- /dev/null +++ b/copilot-interpreter/nix/sources.json @@ -0,0 +1,12 @@ +{ + "nixpkgs": { + "branch": "master", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "63117158fe4f7f9b34eaecef088c417f8151e4ba", + "sha256": "sha256:036cjpfjghm6f8h4cldpv040kfvii7x8g5php4vyn9qmpncybxj6", + "type": "tarball", + "url": "https://github.com/NixOS/nixpkgs/archive/63117158fe4f7f9b34eaecef088c417f8151e4ba.tar.gz", + "url_template": "https://github.com///archive/.tar.gz" + } +} diff --git a/copilot-interpreter/nix/sources.nix b/copilot-interpreter/nix/sources.nix new file mode 100644 index 000000000..fe3dadf7e --- /dev/null +++ b/copilot-interpreter/nix/sources.nix @@ -0,0 +1,198 @@ +# This file has been generated by Niv. + +let + + # + # The fetchers. fetch_ fetches specs of type . + # + + fetch_file = pkgs: name: spec: + let + name' = sanitizeName name + "-src"; + in + if spec.builtin or true then + builtins_fetchurl { inherit (spec) url sha256; name = name'; } + else + pkgs.fetchurl { inherit (spec) url sha256; name = name'; }; + + fetch_tarball = pkgs: name: spec: + let + name' = sanitizeName name + "-src"; + in + if spec.builtin or true then + builtins_fetchTarball { name = name'; inherit (spec) url sha256; } + else + pkgs.fetchzip { name = name'; inherit (spec) url sha256; }; + + fetch_git = name: spec: + let + ref = + spec.ref or ( + if spec ? branch then "refs/heads/${spec.branch}" else + if spec ? tag then "refs/tags/${spec.tag}" else + abort "In git source '${name}': Please specify `ref`, `tag` or `branch`!" + ); + submodules = spec.submodules or false; + submoduleArg = + let + nixSupportsSubmodules = builtins.compareVersions builtins.nixVersion "2.4" >= 0; + emptyArgWithWarning = + if submodules + then + builtins.trace + ( + "The niv input \"${name}\" uses submodules " + + "but your nix's (${builtins.nixVersion}) builtins.fetchGit " + + "does not support them" + ) + { } + else { }; + in + if nixSupportsSubmodules + then { inherit submodules; } + else emptyArgWithWarning; + in + builtins.fetchGit + ({ url = spec.repo; inherit (spec) rev; inherit ref; } // submoduleArg); + + fetch_local = spec: spec.path; + + fetch_builtin-tarball = name: throw + ''[${name}] The niv type "builtin-tarball" is deprecated. You should instead use `builtin = true`. + $ niv modify ${name} -a type=tarball -a builtin=true''; + + fetch_builtin-url = name: throw + ''[${name}] The niv type "builtin-url" will soon be deprecated. You should instead use `builtin = true`. + $ niv modify ${name} -a type=file -a builtin=true''; + + # + # Various helpers + # + + # https://github.com/NixOS/nixpkgs/pull/83241/files#diff-c6f540a4f3bfa4b0e8b6bafd4cd54e8bR695 + sanitizeName = name: + ( + concatMapStrings (s: if builtins.isList s then "-" else s) + ( + builtins.split "[^[:alnum:]+._?=-]+" + ((x: builtins.elemAt (builtins.match "\\.*(.*)" x) 0) name) + ) + ); + + # The set of packages used when specs are fetched using non-builtins. + mkPkgs = sources: system: + let + sourcesNixpkgs = + import (builtins_fetchTarball { inherit (sources.nixpkgs) url sha256; }) { inherit system; }; + hasNixpkgsPath = builtins.any (x: x.prefix == "nixpkgs") builtins.nixPath; + hasThisAsNixpkgsPath = == ./.; + in + if builtins.hasAttr "nixpkgs" sources + then sourcesNixpkgs + else if hasNixpkgsPath && ! hasThisAsNixpkgsPath then + import { } + else + abort + '' + Please specify either (through -I or NIX_PATH=nixpkgs=...) or + add a package called "nixpkgs" to your sources.json. + ''; + + # The actual fetching function. + fetch = pkgs: name: spec: + + if ! builtins.hasAttr "type" spec then + abort "ERROR: niv spec ${name} does not have a 'type' attribute" + else if spec.type == "file" then fetch_file pkgs name spec + else if spec.type == "tarball" then fetch_tarball pkgs name spec + else if spec.type == "git" then fetch_git name spec + else if spec.type == "local" then fetch_local spec + else if spec.type == "builtin-tarball" then fetch_builtin-tarball name + else if spec.type == "builtin-url" then fetch_builtin-url name + else + abort "ERROR: niv spec ${name} has unknown type ${builtins.toJSON spec.type}"; + + # If the environment variable NIV_OVERRIDE_${name} is set, then use + # the path directly as opposed to the fetched source. + replace = name: drv: + let + saneName = stringAsChars (c: if (builtins.match "[a-zA-Z0-9]" c) == null then "_" else c) name; + ersatz = builtins.getEnv "NIV_OVERRIDE_${saneName}"; + in + if ersatz == "" then drv else + # this turns the string into an actual Nix path (for both absolute and + # relative paths) + if builtins.substring 0 1 ersatz == "/" then /. + ersatz else /. + builtins.getEnv "PWD" + "/${ersatz}"; + + # Ports of functions for older nix versions + + # a Nix version of mapAttrs if the built-in doesn't exist + mapAttrs = builtins.mapAttrs or ( + f: set: with builtins; + listToAttrs (map (attr: { name = attr; value = f attr set.${attr}; }) (attrNames set)) + ); + + # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/lists.nix#L295 + range = first: last: if first > last then [ ] else builtins.genList (n: first + n) (last - first + 1); + + # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/strings.nix#L257 + stringToCharacters = s: map (p: builtins.substring p 1 s) (range 0 (builtins.stringLength s - 1)); + + # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/strings.nix#L269 + stringAsChars = f: s: concatStrings (map f (stringToCharacters s)); + concatMapStrings = f: list: concatStrings (map f list); + concatStrings = builtins.concatStringsSep ""; + + # https://github.com/NixOS/nixpkgs/blob/8a9f58a375c401b96da862d969f66429def1d118/lib/attrsets.nix#L331 + optionalAttrs = cond: as: if cond then as else { }; + + # fetchTarball version that is compatible between all the versions of Nix + builtins_fetchTarball = { url, name ? null, sha256 }@attrs: + let + inherit (builtins) lessThan nixVersion fetchTarball; + in + if lessThan nixVersion "1.12" then + fetchTarball ({ inherit url; } // (optionalAttrs (name != null) { inherit name; })) + else + fetchTarball attrs; + + # fetchurl version that is compatible between all the versions of Nix + builtins_fetchurl = { url, name ? null, sha256 }@attrs: + let + inherit (builtins) lessThan nixVersion fetchurl; + in + if lessThan nixVersion "1.12" then + fetchurl ({ inherit url; } // (optionalAttrs (name != null) { inherit name; })) + else + fetchurl attrs; + + # Create the final "sources" from the config + mkSources = config: + mapAttrs + ( + name: spec: + if builtins.hasAttr "outPath" spec + then + abort + "The values in sources.json should not have an 'outPath' attribute" + else + spec // { outPath = replace name (fetch config.pkgs name spec); } + ) + config.sources; + + # The "config" used by the fetchers + mkConfig = + { sourcesFile ? if builtins.pathExists ./sources.json then ./sources.json else null + , sources ? if sourcesFile == null then { } else builtins.fromJSON (builtins.readFile sourcesFile) + , system ? builtins.currentSystem + , pkgs ? mkPkgs sources system + }: rec { + # The sources, i.e. the attribute set of spec name to spec + inherit sources; + + # The "pkgs" (evaluated nixpkgs) to use for e.g. non-builtin fetchers + inherit pkgs; + }; + +in +mkSources (mkConfig { }) // { __functor = _: settings: mkSources (mkConfig settings); } diff --git a/copilot-language/default.nix b/copilot-language/default.nix new file mode 100644 index 000000000..d5edcbbb9 --- /dev/null +++ b/copilot-language/default.nix @@ -0,0 +1,31 @@ +{ sources ? import ./nix/sources.nix, ghc ? "ghc98" }: +let + depOverlay = n: o: { + copilot-core = (import ../copilot-core { inherit sources ghc; }).copilot-core; + copilot-interpreter = (import ../copilot-interpreter { inherit sources ghc; }).copilot-interpreter; + copilot-theorem = (import ../copilot-theorem { inherit sources ghc; }).copilot-theorem; + copilot-prettyprinter = (import ../copilot-prettyprinter { inherit sources ghc; }).copilot-prettyprinter; + }; + np = import sources.nixpkgs {}; + bhp = np.haskell.packages.${ghc}; + + sourceRegexes = [ + "^src.*$" + "^tests.*$" + "^.*\\.cabal$" + "^LICENSE$" + ]; + + copilot-language-base = hp.callCabal2nix "copilot-language" (np.lib.sourceByRegex ./. sourceRegexes) {}; + copilot-language-overlay = _n: _o: { copilot-language = copilot-language-base; }; + hp = bhp.override (o: { + overrides = + builtins.foldl' np.lib.composeExtensions (o.overrides or (_: _: {})) + [ depOverlay copilot-language-overlay ]; + }); + copilot-language = hp.copilot-language; +in { + inherit np; + inherit hp; + inherit copilot-language; +} diff --git a/copilot-language/nix/sources.json b/copilot-language/nix/sources.json new file mode 100644 index 000000000..7a59ceccc --- /dev/null +++ b/copilot-language/nix/sources.json @@ -0,0 +1,12 @@ +{ + "nixpkgs": { + "branch": "master", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "63117158fe4f7f9b34eaecef088c417f8151e4ba", + "sha256": "sha256:036cjpfjghm6f8h4cldpv040kfvii7x8g5php4vyn9qmpncybxj6", + "type": "tarball", + "url": "https://github.com/NixOS/nixpkgs/archive/63117158fe4f7f9b34eaecef088c417f8151e4ba.tar.gz", + "url_template": "https://github.com///archive/.tar.gz" + } +} diff --git a/copilot-language/nix/sources.nix b/copilot-language/nix/sources.nix new file mode 100644 index 000000000..fe3dadf7e --- /dev/null +++ b/copilot-language/nix/sources.nix @@ -0,0 +1,198 @@ +# This file has been generated by Niv. + +let + + # + # The fetchers. fetch_ fetches specs of type . + # + + fetch_file = pkgs: name: spec: + let + name' = sanitizeName name + "-src"; + in + if spec.builtin or true then + builtins_fetchurl { inherit (spec) url sha256; name = name'; } + else + pkgs.fetchurl { inherit (spec) url sha256; name = name'; }; + + fetch_tarball = pkgs: name: spec: + let + name' = sanitizeName name + "-src"; + in + if spec.builtin or true then + builtins_fetchTarball { name = name'; inherit (spec) url sha256; } + else + pkgs.fetchzip { name = name'; inherit (spec) url sha256; }; + + fetch_git = name: spec: + let + ref = + spec.ref or ( + if spec ? branch then "refs/heads/${spec.branch}" else + if spec ? tag then "refs/tags/${spec.tag}" else + abort "In git source '${name}': Please specify `ref`, `tag` or `branch`!" + ); + submodules = spec.submodules or false; + submoduleArg = + let + nixSupportsSubmodules = builtins.compareVersions builtins.nixVersion "2.4" >= 0; + emptyArgWithWarning = + if submodules + then + builtins.trace + ( + "The niv input \"${name}\" uses submodules " + + "but your nix's (${builtins.nixVersion}) builtins.fetchGit " + + "does not support them" + ) + { } + else { }; + in + if nixSupportsSubmodules + then { inherit submodules; } + else emptyArgWithWarning; + in + builtins.fetchGit + ({ url = spec.repo; inherit (spec) rev; inherit ref; } // submoduleArg); + + fetch_local = spec: spec.path; + + fetch_builtin-tarball = name: throw + ''[${name}] The niv type "builtin-tarball" is deprecated. You should instead use `builtin = true`. + $ niv modify ${name} -a type=tarball -a builtin=true''; + + fetch_builtin-url = name: throw + ''[${name}] The niv type "builtin-url" will soon be deprecated. You should instead use `builtin = true`. + $ niv modify ${name} -a type=file -a builtin=true''; + + # + # Various helpers + # + + # https://github.com/NixOS/nixpkgs/pull/83241/files#diff-c6f540a4f3bfa4b0e8b6bafd4cd54e8bR695 + sanitizeName = name: + ( + concatMapStrings (s: if builtins.isList s then "-" else s) + ( + builtins.split "[^[:alnum:]+._?=-]+" + ((x: builtins.elemAt (builtins.match "\\.*(.*)" x) 0) name) + ) + ); + + # The set of packages used when specs are fetched using non-builtins. + mkPkgs = sources: system: + let + sourcesNixpkgs = + import (builtins_fetchTarball { inherit (sources.nixpkgs) url sha256; }) { inherit system; }; + hasNixpkgsPath = builtins.any (x: x.prefix == "nixpkgs") builtins.nixPath; + hasThisAsNixpkgsPath = == ./.; + in + if builtins.hasAttr "nixpkgs" sources + then sourcesNixpkgs + else if hasNixpkgsPath && ! hasThisAsNixpkgsPath then + import { } + else + abort + '' + Please specify either (through -I or NIX_PATH=nixpkgs=...) or + add a package called "nixpkgs" to your sources.json. + ''; + + # The actual fetching function. + fetch = pkgs: name: spec: + + if ! builtins.hasAttr "type" spec then + abort "ERROR: niv spec ${name} does not have a 'type' attribute" + else if spec.type == "file" then fetch_file pkgs name spec + else if spec.type == "tarball" then fetch_tarball pkgs name spec + else if spec.type == "git" then fetch_git name spec + else if spec.type == "local" then fetch_local spec + else if spec.type == "builtin-tarball" then fetch_builtin-tarball name + else if spec.type == "builtin-url" then fetch_builtin-url name + else + abort "ERROR: niv spec ${name} has unknown type ${builtins.toJSON spec.type}"; + + # If the environment variable NIV_OVERRIDE_${name} is set, then use + # the path directly as opposed to the fetched source. + replace = name: drv: + let + saneName = stringAsChars (c: if (builtins.match "[a-zA-Z0-9]" c) == null then "_" else c) name; + ersatz = builtins.getEnv "NIV_OVERRIDE_${saneName}"; + in + if ersatz == "" then drv else + # this turns the string into an actual Nix path (for both absolute and + # relative paths) + if builtins.substring 0 1 ersatz == "/" then /. + ersatz else /. + builtins.getEnv "PWD" + "/${ersatz}"; + + # Ports of functions for older nix versions + + # a Nix version of mapAttrs if the built-in doesn't exist + mapAttrs = builtins.mapAttrs or ( + f: set: with builtins; + listToAttrs (map (attr: { name = attr; value = f attr set.${attr}; }) (attrNames set)) + ); + + # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/lists.nix#L295 + range = first: last: if first > last then [ ] else builtins.genList (n: first + n) (last - first + 1); + + # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/strings.nix#L257 + stringToCharacters = s: map (p: builtins.substring p 1 s) (range 0 (builtins.stringLength s - 1)); + + # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/strings.nix#L269 + stringAsChars = f: s: concatStrings (map f (stringToCharacters s)); + concatMapStrings = f: list: concatStrings (map f list); + concatStrings = builtins.concatStringsSep ""; + + # https://github.com/NixOS/nixpkgs/blob/8a9f58a375c401b96da862d969f66429def1d118/lib/attrsets.nix#L331 + optionalAttrs = cond: as: if cond then as else { }; + + # fetchTarball version that is compatible between all the versions of Nix + builtins_fetchTarball = { url, name ? null, sha256 }@attrs: + let + inherit (builtins) lessThan nixVersion fetchTarball; + in + if lessThan nixVersion "1.12" then + fetchTarball ({ inherit url; } // (optionalAttrs (name != null) { inherit name; })) + else + fetchTarball attrs; + + # fetchurl version that is compatible between all the versions of Nix + builtins_fetchurl = { url, name ? null, sha256 }@attrs: + let + inherit (builtins) lessThan nixVersion fetchurl; + in + if lessThan nixVersion "1.12" then + fetchurl ({ inherit url; } // (optionalAttrs (name != null) { inherit name; })) + else + fetchurl attrs; + + # Create the final "sources" from the config + mkSources = config: + mapAttrs + ( + name: spec: + if builtins.hasAttr "outPath" spec + then + abort + "The values in sources.json should not have an 'outPath' attribute" + else + spec // { outPath = replace name (fetch config.pkgs name spec); } + ) + config.sources; + + # The "config" used by the fetchers + mkConfig = + { sourcesFile ? if builtins.pathExists ./sources.json then ./sources.json else null + , sources ? if sourcesFile == null then { } else builtins.fromJSON (builtins.readFile sourcesFile) + , system ? builtins.currentSystem + , pkgs ? mkPkgs sources system + }: rec { + # The sources, i.e. the attribute set of spec name to spec + inherit sources; + + # The "pkgs" (evaluated nixpkgs) to use for e.g. non-builtin fetchers + inherit pkgs; + }; + +in +mkSources (mkConfig { }) // { __functor = _: settings: mkSources (mkConfig settings); } diff --git a/copilot-libraries/default.nix b/copilot-libraries/default.nix new file mode 100644 index 000000000..631419be9 --- /dev/null +++ b/copilot-libraries/default.nix @@ -0,0 +1,37 @@ +{ sources ? import ./nix/sources.nix, ghc ? "ghc98" }: +let + depOverlay = n: o: { + copilot-language = (import ../copilot-language { inherit sources ghc; }).copilot-language; + copilot-interpreter = (import ../copilot-interpreter { inherit sources ghc; }).copilot-interpreter; + copilot-theorem = (import ../copilot-theorem { inherit sources ghc; }).copilot-theorem; + }; + np = import sources.nixpkgs {}; + bhp = np.haskell.packages.${ghc}; + + sourceRegexes = [ + "^src.*$" + "^tests.*$" + "^.*\\.cabal$" + "^LICENSE$" + ]; + + importZ3 = drv: + drv.overrideAttrs (oa: { + propagatedBuildInputs = (oa.propagatedBuildInputs or []) ++ [np.z3]; + }); + + copilot-libraries-base = + importZ3 (hp.callCabal2nix "copilot-libraries" (np.lib.sourceByRegex ./. sourceRegexes) {}); + + copilot-libraries-overlay = _n: _o: { copilot-libraries = copilot-libraries-base; }; + hp = bhp.override (o: { + overrides = + builtins.foldl' np.lib.composeExtensions (o.overrides or (_: _: {})) + [ depOverlay copilot-libraries-overlay ]; + }); + copilot-libraries = hp.copilot-libraries; +in { + inherit np; + inherit hp; + inherit copilot-libraries; +} diff --git a/copilot-libraries/nix/sources.json b/copilot-libraries/nix/sources.json new file mode 100644 index 000000000..7a59ceccc --- /dev/null +++ b/copilot-libraries/nix/sources.json @@ -0,0 +1,12 @@ +{ + "nixpkgs": { + "branch": "master", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "63117158fe4f7f9b34eaecef088c417f8151e4ba", + "sha256": "sha256:036cjpfjghm6f8h4cldpv040kfvii7x8g5php4vyn9qmpncybxj6", + "type": "tarball", + "url": "https://github.com/NixOS/nixpkgs/archive/63117158fe4f7f9b34eaecef088c417f8151e4ba.tar.gz", + "url_template": "https://github.com///archive/.tar.gz" + } +} diff --git a/copilot-libraries/nix/sources.nix b/copilot-libraries/nix/sources.nix new file mode 100644 index 000000000..fe3dadf7e --- /dev/null +++ b/copilot-libraries/nix/sources.nix @@ -0,0 +1,198 @@ +# This file has been generated by Niv. + +let + + # + # The fetchers. fetch_ fetches specs of type . + # + + fetch_file = pkgs: name: spec: + let + name' = sanitizeName name + "-src"; + in + if spec.builtin or true then + builtins_fetchurl { inherit (spec) url sha256; name = name'; } + else + pkgs.fetchurl { inherit (spec) url sha256; name = name'; }; + + fetch_tarball = pkgs: name: spec: + let + name' = sanitizeName name + "-src"; + in + if spec.builtin or true then + builtins_fetchTarball { name = name'; inherit (spec) url sha256; } + else + pkgs.fetchzip { name = name'; inherit (spec) url sha256; }; + + fetch_git = name: spec: + let + ref = + spec.ref or ( + if spec ? branch then "refs/heads/${spec.branch}" else + if spec ? tag then "refs/tags/${spec.tag}" else + abort "In git source '${name}': Please specify `ref`, `tag` or `branch`!" + ); + submodules = spec.submodules or false; + submoduleArg = + let + nixSupportsSubmodules = builtins.compareVersions builtins.nixVersion "2.4" >= 0; + emptyArgWithWarning = + if submodules + then + builtins.trace + ( + "The niv input \"${name}\" uses submodules " + + "but your nix's (${builtins.nixVersion}) builtins.fetchGit " + + "does not support them" + ) + { } + else { }; + in + if nixSupportsSubmodules + then { inherit submodules; } + else emptyArgWithWarning; + in + builtins.fetchGit + ({ url = spec.repo; inherit (spec) rev; inherit ref; } // submoduleArg); + + fetch_local = spec: spec.path; + + fetch_builtin-tarball = name: throw + ''[${name}] The niv type "builtin-tarball" is deprecated. You should instead use `builtin = true`. + $ niv modify ${name} -a type=tarball -a builtin=true''; + + fetch_builtin-url = name: throw + ''[${name}] The niv type "builtin-url" will soon be deprecated. You should instead use `builtin = true`. + $ niv modify ${name} -a type=file -a builtin=true''; + + # + # Various helpers + # + + # https://github.com/NixOS/nixpkgs/pull/83241/files#diff-c6f540a4f3bfa4b0e8b6bafd4cd54e8bR695 + sanitizeName = name: + ( + concatMapStrings (s: if builtins.isList s then "-" else s) + ( + builtins.split "[^[:alnum:]+._?=-]+" + ((x: builtins.elemAt (builtins.match "\\.*(.*)" x) 0) name) + ) + ); + + # The set of packages used when specs are fetched using non-builtins. + mkPkgs = sources: system: + let + sourcesNixpkgs = + import (builtins_fetchTarball { inherit (sources.nixpkgs) url sha256; }) { inherit system; }; + hasNixpkgsPath = builtins.any (x: x.prefix == "nixpkgs") builtins.nixPath; + hasThisAsNixpkgsPath = == ./.; + in + if builtins.hasAttr "nixpkgs" sources + then sourcesNixpkgs + else if hasNixpkgsPath && ! hasThisAsNixpkgsPath then + import { } + else + abort + '' + Please specify either (through -I or NIX_PATH=nixpkgs=...) or + add a package called "nixpkgs" to your sources.json. + ''; + + # The actual fetching function. + fetch = pkgs: name: spec: + + if ! builtins.hasAttr "type" spec then + abort "ERROR: niv spec ${name} does not have a 'type' attribute" + else if spec.type == "file" then fetch_file pkgs name spec + else if spec.type == "tarball" then fetch_tarball pkgs name spec + else if spec.type == "git" then fetch_git name spec + else if spec.type == "local" then fetch_local spec + else if spec.type == "builtin-tarball" then fetch_builtin-tarball name + else if spec.type == "builtin-url" then fetch_builtin-url name + else + abort "ERROR: niv spec ${name} has unknown type ${builtins.toJSON spec.type}"; + + # If the environment variable NIV_OVERRIDE_${name} is set, then use + # the path directly as opposed to the fetched source. + replace = name: drv: + let + saneName = stringAsChars (c: if (builtins.match "[a-zA-Z0-9]" c) == null then "_" else c) name; + ersatz = builtins.getEnv "NIV_OVERRIDE_${saneName}"; + in + if ersatz == "" then drv else + # this turns the string into an actual Nix path (for both absolute and + # relative paths) + if builtins.substring 0 1 ersatz == "/" then /. + ersatz else /. + builtins.getEnv "PWD" + "/${ersatz}"; + + # Ports of functions for older nix versions + + # a Nix version of mapAttrs if the built-in doesn't exist + mapAttrs = builtins.mapAttrs or ( + f: set: with builtins; + listToAttrs (map (attr: { name = attr; value = f attr set.${attr}; }) (attrNames set)) + ); + + # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/lists.nix#L295 + range = first: last: if first > last then [ ] else builtins.genList (n: first + n) (last - first + 1); + + # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/strings.nix#L257 + stringToCharacters = s: map (p: builtins.substring p 1 s) (range 0 (builtins.stringLength s - 1)); + + # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/strings.nix#L269 + stringAsChars = f: s: concatStrings (map f (stringToCharacters s)); + concatMapStrings = f: list: concatStrings (map f list); + concatStrings = builtins.concatStringsSep ""; + + # https://github.com/NixOS/nixpkgs/blob/8a9f58a375c401b96da862d969f66429def1d118/lib/attrsets.nix#L331 + optionalAttrs = cond: as: if cond then as else { }; + + # fetchTarball version that is compatible between all the versions of Nix + builtins_fetchTarball = { url, name ? null, sha256 }@attrs: + let + inherit (builtins) lessThan nixVersion fetchTarball; + in + if lessThan nixVersion "1.12" then + fetchTarball ({ inherit url; } // (optionalAttrs (name != null) { inherit name; })) + else + fetchTarball attrs; + + # fetchurl version that is compatible between all the versions of Nix + builtins_fetchurl = { url, name ? null, sha256 }@attrs: + let + inherit (builtins) lessThan nixVersion fetchurl; + in + if lessThan nixVersion "1.12" then + fetchurl ({ inherit url; } // (optionalAttrs (name != null) { inherit name; })) + else + fetchurl attrs; + + # Create the final "sources" from the config + mkSources = config: + mapAttrs + ( + name: spec: + if builtins.hasAttr "outPath" spec + then + abort + "The values in sources.json should not have an 'outPath' attribute" + else + spec // { outPath = replace name (fetch config.pkgs name spec); } + ) + config.sources; + + # The "config" used by the fetchers + mkConfig = + { sourcesFile ? if builtins.pathExists ./sources.json then ./sources.json else null + , sources ? if sourcesFile == null then { } else builtins.fromJSON (builtins.readFile sourcesFile) + , system ? builtins.currentSystem + , pkgs ? mkPkgs sources system + }: rec { + # The sources, i.e. the attribute set of spec name to spec + inherit sources; + + # The "pkgs" (evaluated nixpkgs) to use for e.g. non-builtin fetchers + inherit pkgs; + }; + +in +mkSources (mkConfig { }) // { __functor = _: settings: mkSources (mkConfig settings); } diff --git a/copilot-prettyprinter/default.nix b/copilot-prettyprinter/default.nix new file mode 100644 index 000000000..b8d08f22b --- /dev/null +++ b/copilot-prettyprinter/default.nix @@ -0,0 +1,28 @@ +{ sources ? import ./nix/sources.nix, ghc ? "ghc98" }: +let + depOverlay = n: o: { + copilot-core = (import ../copilot-core { inherit sources ghc; }).copilot-core; + }; + np = import sources.nixpkgs {}; + bhp = np.haskell.packages.${ghc}; + + sourceRegexes = [ + "^src.*$" + "^tests.*$" + "^.*\\.cabal$" + "^LICENSE$" + ]; + + copilot-prettyprinter-base = hp.callCabal2nix "copilot-prettyprinter" (np.lib.sourceByRegex ./. sourceRegexes) {}; + copilot-prettyprinter-overlay = _n: _o: { copilot-prettyprinter = copilot-prettyprinter-base; }; + hp = bhp.override (o: { + overrides = + builtins.foldl' np.lib.composeExtensions (o.overrides or (_: _: {})) + [ depOverlay copilot-prettyprinter-overlay ]; + }); + copilot-prettyprinter = hp.copilot-prettyprinter; +in { + inherit np; + inherit hp; + inherit copilot-prettyprinter; +} diff --git a/copilot-prettyprinter/nix/sources.json b/copilot-prettyprinter/nix/sources.json new file mode 100644 index 000000000..7a59ceccc --- /dev/null +++ b/copilot-prettyprinter/nix/sources.json @@ -0,0 +1,12 @@ +{ + "nixpkgs": { + "branch": "master", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "63117158fe4f7f9b34eaecef088c417f8151e4ba", + "sha256": "sha256:036cjpfjghm6f8h4cldpv040kfvii7x8g5php4vyn9qmpncybxj6", + "type": "tarball", + "url": "https://github.com/NixOS/nixpkgs/archive/63117158fe4f7f9b34eaecef088c417f8151e4ba.tar.gz", + "url_template": "https://github.com///archive/.tar.gz" + } +} diff --git a/copilot-prettyprinter/nix/sources.nix b/copilot-prettyprinter/nix/sources.nix new file mode 100644 index 000000000..fe3dadf7e --- /dev/null +++ b/copilot-prettyprinter/nix/sources.nix @@ -0,0 +1,198 @@ +# This file has been generated by Niv. + +let + + # + # The fetchers. fetch_ fetches specs of type . + # + + fetch_file = pkgs: name: spec: + let + name' = sanitizeName name + "-src"; + in + if spec.builtin or true then + builtins_fetchurl { inherit (spec) url sha256; name = name'; } + else + pkgs.fetchurl { inherit (spec) url sha256; name = name'; }; + + fetch_tarball = pkgs: name: spec: + let + name' = sanitizeName name + "-src"; + in + if spec.builtin or true then + builtins_fetchTarball { name = name'; inherit (spec) url sha256; } + else + pkgs.fetchzip { name = name'; inherit (spec) url sha256; }; + + fetch_git = name: spec: + let + ref = + spec.ref or ( + if spec ? branch then "refs/heads/${spec.branch}" else + if spec ? tag then "refs/tags/${spec.tag}" else + abort "In git source '${name}': Please specify `ref`, `tag` or `branch`!" + ); + submodules = spec.submodules or false; + submoduleArg = + let + nixSupportsSubmodules = builtins.compareVersions builtins.nixVersion "2.4" >= 0; + emptyArgWithWarning = + if submodules + then + builtins.trace + ( + "The niv input \"${name}\" uses submodules " + + "but your nix's (${builtins.nixVersion}) builtins.fetchGit " + + "does not support them" + ) + { } + else { }; + in + if nixSupportsSubmodules + then { inherit submodules; } + else emptyArgWithWarning; + in + builtins.fetchGit + ({ url = spec.repo; inherit (spec) rev; inherit ref; } // submoduleArg); + + fetch_local = spec: spec.path; + + fetch_builtin-tarball = name: throw + ''[${name}] The niv type "builtin-tarball" is deprecated. You should instead use `builtin = true`. + $ niv modify ${name} -a type=tarball -a builtin=true''; + + fetch_builtin-url = name: throw + ''[${name}] The niv type "builtin-url" will soon be deprecated. You should instead use `builtin = true`. + $ niv modify ${name} -a type=file -a builtin=true''; + + # + # Various helpers + # + + # https://github.com/NixOS/nixpkgs/pull/83241/files#diff-c6f540a4f3bfa4b0e8b6bafd4cd54e8bR695 + sanitizeName = name: + ( + concatMapStrings (s: if builtins.isList s then "-" else s) + ( + builtins.split "[^[:alnum:]+._?=-]+" + ((x: builtins.elemAt (builtins.match "\\.*(.*)" x) 0) name) + ) + ); + + # The set of packages used when specs are fetched using non-builtins. + mkPkgs = sources: system: + let + sourcesNixpkgs = + import (builtins_fetchTarball { inherit (sources.nixpkgs) url sha256; }) { inherit system; }; + hasNixpkgsPath = builtins.any (x: x.prefix == "nixpkgs") builtins.nixPath; + hasThisAsNixpkgsPath = == ./.; + in + if builtins.hasAttr "nixpkgs" sources + then sourcesNixpkgs + else if hasNixpkgsPath && ! hasThisAsNixpkgsPath then + import { } + else + abort + '' + Please specify either (through -I or NIX_PATH=nixpkgs=...) or + add a package called "nixpkgs" to your sources.json. + ''; + + # The actual fetching function. + fetch = pkgs: name: spec: + + if ! builtins.hasAttr "type" spec then + abort "ERROR: niv spec ${name} does not have a 'type' attribute" + else if spec.type == "file" then fetch_file pkgs name spec + else if spec.type == "tarball" then fetch_tarball pkgs name spec + else if spec.type == "git" then fetch_git name spec + else if spec.type == "local" then fetch_local spec + else if spec.type == "builtin-tarball" then fetch_builtin-tarball name + else if spec.type == "builtin-url" then fetch_builtin-url name + else + abort "ERROR: niv spec ${name} has unknown type ${builtins.toJSON spec.type}"; + + # If the environment variable NIV_OVERRIDE_${name} is set, then use + # the path directly as opposed to the fetched source. + replace = name: drv: + let + saneName = stringAsChars (c: if (builtins.match "[a-zA-Z0-9]" c) == null then "_" else c) name; + ersatz = builtins.getEnv "NIV_OVERRIDE_${saneName}"; + in + if ersatz == "" then drv else + # this turns the string into an actual Nix path (for both absolute and + # relative paths) + if builtins.substring 0 1 ersatz == "/" then /. + ersatz else /. + builtins.getEnv "PWD" + "/${ersatz}"; + + # Ports of functions for older nix versions + + # a Nix version of mapAttrs if the built-in doesn't exist + mapAttrs = builtins.mapAttrs or ( + f: set: with builtins; + listToAttrs (map (attr: { name = attr; value = f attr set.${attr}; }) (attrNames set)) + ); + + # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/lists.nix#L295 + range = first: last: if first > last then [ ] else builtins.genList (n: first + n) (last - first + 1); + + # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/strings.nix#L257 + stringToCharacters = s: map (p: builtins.substring p 1 s) (range 0 (builtins.stringLength s - 1)); + + # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/strings.nix#L269 + stringAsChars = f: s: concatStrings (map f (stringToCharacters s)); + concatMapStrings = f: list: concatStrings (map f list); + concatStrings = builtins.concatStringsSep ""; + + # https://github.com/NixOS/nixpkgs/blob/8a9f58a375c401b96da862d969f66429def1d118/lib/attrsets.nix#L331 + optionalAttrs = cond: as: if cond then as else { }; + + # fetchTarball version that is compatible between all the versions of Nix + builtins_fetchTarball = { url, name ? null, sha256 }@attrs: + let + inherit (builtins) lessThan nixVersion fetchTarball; + in + if lessThan nixVersion "1.12" then + fetchTarball ({ inherit url; } // (optionalAttrs (name != null) { inherit name; })) + else + fetchTarball attrs; + + # fetchurl version that is compatible between all the versions of Nix + builtins_fetchurl = { url, name ? null, sha256 }@attrs: + let + inherit (builtins) lessThan nixVersion fetchurl; + in + if lessThan nixVersion "1.12" then + fetchurl ({ inherit url; } // (optionalAttrs (name != null) { inherit name; })) + else + fetchurl attrs; + + # Create the final "sources" from the config + mkSources = config: + mapAttrs + ( + name: spec: + if builtins.hasAttr "outPath" spec + then + abort + "The values in sources.json should not have an 'outPath' attribute" + else + spec // { outPath = replace name (fetch config.pkgs name spec); } + ) + config.sources; + + # The "config" used by the fetchers + mkConfig = + { sourcesFile ? if builtins.pathExists ./sources.json then ./sources.json else null + , sources ? if sourcesFile == null then { } else builtins.fromJSON (builtins.readFile sourcesFile) + , system ? builtins.currentSystem + , pkgs ? mkPkgs sources system + }: rec { + # The sources, i.e. the attribute set of spec name to spec + inherit sources; + + # The "pkgs" (evaluated nixpkgs) to use for e.g. non-builtin fetchers + inherit pkgs; + }; + +in +mkSources (mkConfig { }) // { __functor = _: settings: mkSources (mkConfig settings); } diff --git a/copilot-theorem/default.nix b/copilot-theorem/default.nix new file mode 100644 index 000000000..4fe952f4c --- /dev/null +++ b/copilot-theorem/default.nix @@ -0,0 +1,45 @@ +{ sources ? import ./nix/sources.nix, ghc ? "ghc98" }: +let + depOverlay = n: o: { + copilot-core = (import ../copilot-core { inherit sources ghc; }).copilot-core; + copilot-prettyprinter = (import ../copilot-prettyprinter { inherit sources ghc; }).copilot-prettyprinter; + what4 = bhp.what4_1_7; + # importCvc5 (importZ3 (bhp.callHackageDirect { + # pkg = "what4"; + # ver = "1.7.1.0"; + # sha256="sha256-2V03HpjtEZl7U1n/pvgzenXO7Igmt79DZvETDjYj08k="; + # } { })); + }; + np = import sources.nixpkgs {}; + bhp = np.haskell.packages.${ghc}; + + sourceRegexes = [ + "^src.*$" + "^tests.*$" + "^.*\\.cabal$" + "^LICENSE$" + ]; + + importZ3 = drv: + drv.overrideAttrs (oa: { + propagatedBuildInputs = (oa.propagatedBuildInputs or []) ++ [np.z3]; + }); + + importCvc5 = drv: + drv.overrideAttrs (oa: { + propagatedBuildInputs = (oa.propagatedBuildInputs or []) ++ [np.cvc5]; + }); + + copilot-theorem-base = importZ3 (hp.callCabal2nix "copilot-theorem" (np.lib.sourceByRegex ./. sourceRegexes) {}); + copilot-theorem-overlay = _n: _o: { copilot-theorem = copilot-theorem-base; }; + hp = bhp.override (o: { + overrides = + builtins.foldl' np.lib.composeExtensions (o.overrides or (_: _: {})) + [ depOverlay copilot-theorem-overlay ]; + }); + copilot-theorem = hp.copilot-theorem; +in { + inherit np; + inherit hp; + inherit copilot-theorem; +} diff --git a/copilot-theorem/nix/sources.json b/copilot-theorem/nix/sources.json new file mode 100644 index 000000000..7a59ceccc --- /dev/null +++ b/copilot-theorem/nix/sources.json @@ -0,0 +1,12 @@ +{ + "nixpkgs": { + "branch": "master", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "63117158fe4f7f9b34eaecef088c417f8151e4ba", + "sha256": "sha256:036cjpfjghm6f8h4cldpv040kfvii7x8g5php4vyn9qmpncybxj6", + "type": "tarball", + "url": "https://github.com/NixOS/nixpkgs/archive/63117158fe4f7f9b34eaecef088c417f8151e4ba.tar.gz", + "url_template": "https://github.com///archive/.tar.gz" + } +} diff --git a/copilot-theorem/nix/sources.nix b/copilot-theorem/nix/sources.nix new file mode 100644 index 000000000..fe3dadf7e --- /dev/null +++ b/copilot-theorem/nix/sources.nix @@ -0,0 +1,198 @@ +# This file has been generated by Niv. + +let + + # + # The fetchers. fetch_ fetches specs of type . + # + + fetch_file = pkgs: name: spec: + let + name' = sanitizeName name + "-src"; + in + if spec.builtin or true then + builtins_fetchurl { inherit (spec) url sha256; name = name'; } + else + pkgs.fetchurl { inherit (spec) url sha256; name = name'; }; + + fetch_tarball = pkgs: name: spec: + let + name' = sanitizeName name + "-src"; + in + if spec.builtin or true then + builtins_fetchTarball { name = name'; inherit (spec) url sha256; } + else + pkgs.fetchzip { name = name'; inherit (spec) url sha256; }; + + fetch_git = name: spec: + let + ref = + spec.ref or ( + if spec ? branch then "refs/heads/${spec.branch}" else + if spec ? tag then "refs/tags/${spec.tag}" else + abort "In git source '${name}': Please specify `ref`, `tag` or `branch`!" + ); + submodules = spec.submodules or false; + submoduleArg = + let + nixSupportsSubmodules = builtins.compareVersions builtins.nixVersion "2.4" >= 0; + emptyArgWithWarning = + if submodules + then + builtins.trace + ( + "The niv input \"${name}\" uses submodules " + + "but your nix's (${builtins.nixVersion}) builtins.fetchGit " + + "does not support them" + ) + { } + else { }; + in + if nixSupportsSubmodules + then { inherit submodules; } + else emptyArgWithWarning; + in + builtins.fetchGit + ({ url = spec.repo; inherit (spec) rev; inherit ref; } // submoduleArg); + + fetch_local = spec: spec.path; + + fetch_builtin-tarball = name: throw + ''[${name}] The niv type "builtin-tarball" is deprecated. You should instead use `builtin = true`. + $ niv modify ${name} -a type=tarball -a builtin=true''; + + fetch_builtin-url = name: throw + ''[${name}] The niv type "builtin-url" will soon be deprecated. You should instead use `builtin = true`. + $ niv modify ${name} -a type=file -a builtin=true''; + + # + # Various helpers + # + + # https://github.com/NixOS/nixpkgs/pull/83241/files#diff-c6f540a4f3bfa4b0e8b6bafd4cd54e8bR695 + sanitizeName = name: + ( + concatMapStrings (s: if builtins.isList s then "-" else s) + ( + builtins.split "[^[:alnum:]+._?=-]+" + ((x: builtins.elemAt (builtins.match "\\.*(.*)" x) 0) name) + ) + ); + + # The set of packages used when specs are fetched using non-builtins. + mkPkgs = sources: system: + let + sourcesNixpkgs = + import (builtins_fetchTarball { inherit (sources.nixpkgs) url sha256; }) { inherit system; }; + hasNixpkgsPath = builtins.any (x: x.prefix == "nixpkgs") builtins.nixPath; + hasThisAsNixpkgsPath = == ./.; + in + if builtins.hasAttr "nixpkgs" sources + then sourcesNixpkgs + else if hasNixpkgsPath && ! hasThisAsNixpkgsPath then + import { } + else + abort + '' + Please specify either (through -I or NIX_PATH=nixpkgs=...) or + add a package called "nixpkgs" to your sources.json. + ''; + + # The actual fetching function. + fetch = pkgs: name: spec: + + if ! builtins.hasAttr "type" spec then + abort "ERROR: niv spec ${name} does not have a 'type' attribute" + else if spec.type == "file" then fetch_file pkgs name spec + else if spec.type == "tarball" then fetch_tarball pkgs name spec + else if spec.type == "git" then fetch_git name spec + else if spec.type == "local" then fetch_local spec + else if spec.type == "builtin-tarball" then fetch_builtin-tarball name + else if spec.type == "builtin-url" then fetch_builtin-url name + else + abort "ERROR: niv spec ${name} has unknown type ${builtins.toJSON spec.type}"; + + # If the environment variable NIV_OVERRIDE_${name} is set, then use + # the path directly as opposed to the fetched source. + replace = name: drv: + let + saneName = stringAsChars (c: if (builtins.match "[a-zA-Z0-9]" c) == null then "_" else c) name; + ersatz = builtins.getEnv "NIV_OVERRIDE_${saneName}"; + in + if ersatz == "" then drv else + # this turns the string into an actual Nix path (for both absolute and + # relative paths) + if builtins.substring 0 1 ersatz == "/" then /. + ersatz else /. + builtins.getEnv "PWD" + "/${ersatz}"; + + # Ports of functions for older nix versions + + # a Nix version of mapAttrs if the built-in doesn't exist + mapAttrs = builtins.mapAttrs or ( + f: set: with builtins; + listToAttrs (map (attr: { name = attr; value = f attr set.${attr}; }) (attrNames set)) + ); + + # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/lists.nix#L295 + range = first: last: if first > last then [ ] else builtins.genList (n: first + n) (last - first + 1); + + # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/strings.nix#L257 + stringToCharacters = s: map (p: builtins.substring p 1 s) (range 0 (builtins.stringLength s - 1)); + + # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/strings.nix#L269 + stringAsChars = f: s: concatStrings (map f (stringToCharacters s)); + concatMapStrings = f: list: concatStrings (map f list); + concatStrings = builtins.concatStringsSep ""; + + # https://github.com/NixOS/nixpkgs/blob/8a9f58a375c401b96da862d969f66429def1d118/lib/attrsets.nix#L331 + optionalAttrs = cond: as: if cond then as else { }; + + # fetchTarball version that is compatible between all the versions of Nix + builtins_fetchTarball = { url, name ? null, sha256 }@attrs: + let + inherit (builtins) lessThan nixVersion fetchTarball; + in + if lessThan nixVersion "1.12" then + fetchTarball ({ inherit url; } // (optionalAttrs (name != null) { inherit name; })) + else + fetchTarball attrs; + + # fetchurl version that is compatible between all the versions of Nix + builtins_fetchurl = { url, name ? null, sha256 }@attrs: + let + inherit (builtins) lessThan nixVersion fetchurl; + in + if lessThan nixVersion "1.12" then + fetchurl ({ inherit url; } // (optionalAttrs (name != null) { inherit name; })) + else + fetchurl attrs; + + # Create the final "sources" from the config + mkSources = config: + mapAttrs + ( + name: spec: + if builtins.hasAttr "outPath" spec + then + abort + "The values in sources.json should not have an 'outPath' attribute" + else + spec // { outPath = replace name (fetch config.pkgs name spec); } + ) + config.sources; + + # The "config" used by the fetchers + mkConfig = + { sourcesFile ? if builtins.pathExists ./sources.json then ./sources.json else null + , sources ? if sourcesFile == null then { } else builtins.fromJSON (builtins.readFile sourcesFile) + , system ? builtins.currentSystem + , pkgs ? mkPkgs sources system + }: rec { + # The sources, i.e. the attribute set of spec name to spec + inherit sources; + + # The "pkgs" (evaluated nixpkgs) to use for e.g. non-builtin fetchers + inherit pkgs; + }; + +in +mkSources (mkConfig { }) // { __functor = _: settings: mkSources (mkConfig settings); } diff --git a/copilot-verifier/default.nix b/copilot-verifier/default.nix new file mode 100644 index 000000000..85ae2c557 --- /dev/null +++ b/copilot-verifier/default.nix @@ -0,0 +1,76 @@ +{ sources ? import ./nix/sources.nix, ghc ? "ghc98" }: +let + # depOverlay2 = n: o: { + # th-abstraction = + # bhp.callHackageDirect { + # pkg = "th-abstraction"; + # ver = "0.6.0.0"; + # sha256="sha256-eOUH1OSmLL8hS8mzijfJvGhxfMEU2vQozKHKlbv2B/A="; + # } { }; + # }; + depOverlay = n: o: { + copilot = (import ../copilot { inherit sources ghc; }).copilot; + copilot-core = (import ../copilot-core { inherit sources ghc; }).copilot-core; + copilot-c99 = (import ../copilot-c99 { inherit sources ghc; }).copilot-c99; + copilot-language = (import ../copilot-language { inherit sources ghc; }).copilot-language; + copilot-interpreter = (import ../copilot-interpreter { inherit sources ghc; }).copilot-interpreter; + copilot-libraries = (import ../copilot-libraries { inherit sources ghc; }).copilot-libraries; + copilot-prettyprinter = (import ../copilot-prettyprinter { inherit sources ghc; }).copilot-prettyprinter; + copilot-theorem = (import ../copilot-theorem { inherit sources ghc; }).copilot-theorem; + # > crux-llvm >=0.9 && <0.10, llvm-pretty >=0.12.1.0 && <0.13 + # pkg = "reflex-test-host"; + # ver = "0.1.2.3"; + # sha256 = "9ee3ad9ac4fc58c6dcabcd9fbc6d109a51d8e86ba2682cee8367bc6b452f09ea"; + # crux-llvm = + # bhp.callHackageDirect { + # pkg = "crux-llvm"; + # ver = "0.9.1"; + # sha256="sha256-OPCiLp0xDIvzdPtmEk0m7/RncZjo8fkRX1kiNr5DWTo="; + # rev = { revision = "1"; + # sha256 = "sha256-vqbWx4L7SygP07H3Jn6wsqAu1Fl/oAT1H0umOvJC8yw="; + # }; + # } { }; + # llvm-pretty = + # bhp.callHackageDirect { + # pkg = "llvm-pretty"; + # ver = "0.12.1.0"; + # sha256="sha256-0scMOvY8sXQuCXpSidRpELTyhxh7YbVOZ/2gRLo+hF0="; + # rev = { revision = "1"; + # sha256 = "sha256-vqbWx4L7SygP07H3Jn6wsqAu1Fl/oAT1H0umOvJC8yw="; + # }; + # } { }; + + # crux-llvm = bhp.callHackage "crux-llvm" "0.9.1" { }; + }; + np = import sources.nixpkgs {}; + bhp = np.haskell.packages.${ghc}; + + sourceRegexes = [ + "^src.*$" + "^exe.*$" + "^examples.*$" + "^test.*$" + "^.*\\.cabal$" + "^LICENSE$" + ]; + + importZ3 = drv: + drv.overrideAttrs (oa: { + propagatedBuildInputs = (oa.propagatedBuildInputs or []) ++ [np.z3 np.clang np.llvm]; + }); + + copilot-verifier-base = + importZ3 (hp.callCabal2nix "copilot-verifier" (np.lib.sourceByRegex ./. sourceRegexes) {}); + + copilot-verifier-overlay = _n: _o: { copilot-verifier = copilot-verifier-base; }; + hp = bhp.override (o: { + overrides = + builtins.foldl' np.lib.composeExtensions (o.overrides or (_: _: {})) + [ depOverlay copilot-verifier-overlay ]; + }); + copilot-verifier = hp.copilot-verifier; +in { + inherit np; + inherit hp; + inherit copilot-verifier; +} diff --git a/copilot-verifier/nix/sources.json b/copilot-verifier/nix/sources.json new file mode 100644 index 000000000..9d76be057 --- /dev/null +++ b/copilot-verifier/nix/sources.json @@ -0,0 +1,12 @@ +{ + "nixpkgs": { + "branch": "master", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "da5af46a09eeb2b1c8f4193d626727d5b7460601", + "sha256": "sha256:1hmj9mg81gy8c7v8j563793sckawyxnca60zlif7qpsri597hlhh", + "type": "tarball", + "url": "https://github.com/NixOS/nixpkgs/archive/da5af46a09eeb2b1c8f4193d626727d5b7460601.tar.gz", + "url_template": "https://github.com///archive/.tar.gz" + } +} diff --git a/copilot-verifier/nix/sources.nix b/copilot-verifier/nix/sources.nix new file mode 100644 index 000000000..fe3dadf7e --- /dev/null +++ b/copilot-verifier/nix/sources.nix @@ -0,0 +1,198 @@ +# This file has been generated by Niv. + +let + + # + # The fetchers. fetch_ fetches specs of type . + # + + fetch_file = pkgs: name: spec: + let + name' = sanitizeName name + "-src"; + in + if spec.builtin or true then + builtins_fetchurl { inherit (spec) url sha256; name = name'; } + else + pkgs.fetchurl { inherit (spec) url sha256; name = name'; }; + + fetch_tarball = pkgs: name: spec: + let + name' = sanitizeName name + "-src"; + in + if spec.builtin or true then + builtins_fetchTarball { name = name'; inherit (spec) url sha256; } + else + pkgs.fetchzip { name = name'; inherit (spec) url sha256; }; + + fetch_git = name: spec: + let + ref = + spec.ref or ( + if spec ? branch then "refs/heads/${spec.branch}" else + if spec ? tag then "refs/tags/${spec.tag}" else + abort "In git source '${name}': Please specify `ref`, `tag` or `branch`!" + ); + submodules = spec.submodules or false; + submoduleArg = + let + nixSupportsSubmodules = builtins.compareVersions builtins.nixVersion "2.4" >= 0; + emptyArgWithWarning = + if submodules + then + builtins.trace + ( + "The niv input \"${name}\" uses submodules " + + "but your nix's (${builtins.nixVersion}) builtins.fetchGit " + + "does not support them" + ) + { } + else { }; + in + if nixSupportsSubmodules + then { inherit submodules; } + else emptyArgWithWarning; + in + builtins.fetchGit + ({ url = spec.repo; inherit (spec) rev; inherit ref; } // submoduleArg); + + fetch_local = spec: spec.path; + + fetch_builtin-tarball = name: throw + ''[${name}] The niv type "builtin-tarball" is deprecated. You should instead use `builtin = true`. + $ niv modify ${name} -a type=tarball -a builtin=true''; + + fetch_builtin-url = name: throw + ''[${name}] The niv type "builtin-url" will soon be deprecated. You should instead use `builtin = true`. + $ niv modify ${name} -a type=file -a builtin=true''; + + # + # Various helpers + # + + # https://github.com/NixOS/nixpkgs/pull/83241/files#diff-c6f540a4f3bfa4b0e8b6bafd4cd54e8bR695 + sanitizeName = name: + ( + concatMapStrings (s: if builtins.isList s then "-" else s) + ( + builtins.split "[^[:alnum:]+._?=-]+" + ((x: builtins.elemAt (builtins.match "\\.*(.*)" x) 0) name) + ) + ); + + # The set of packages used when specs are fetched using non-builtins. + mkPkgs = sources: system: + let + sourcesNixpkgs = + import (builtins_fetchTarball { inherit (sources.nixpkgs) url sha256; }) { inherit system; }; + hasNixpkgsPath = builtins.any (x: x.prefix == "nixpkgs") builtins.nixPath; + hasThisAsNixpkgsPath = == ./.; + in + if builtins.hasAttr "nixpkgs" sources + then sourcesNixpkgs + else if hasNixpkgsPath && ! hasThisAsNixpkgsPath then + import { } + else + abort + '' + Please specify either (through -I or NIX_PATH=nixpkgs=...) or + add a package called "nixpkgs" to your sources.json. + ''; + + # The actual fetching function. + fetch = pkgs: name: spec: + + if ! builtins.hasAttr "type" spec then + abort "ERROR: niv spec ${name} does not have a 'type' attribute" + else if spec.type == "file" then fetch_file pkgs name spec + else if spec.type == "tarball" then fetch_tarball pkgs name spec + else if spec.type == "git" then fetch_git name spec + else if spec.type == "local" then fetch_local spec + else if spec.type == "builtin-tarball" then fetch_builtin-tarball name + else if spec.type == "builtin-url" then fetch_builtin-url name + else + abort "ERROR: niv spec ${name} has unknown type ${builtins.toJSON spec.type}"; + + # If the environment variable NIV_OVERRIDE_${name} is set, then use + # the path directly as opposed to the fetched source. + replace = name: drv: + let + saneName = stringAsChars (c: if (builtins.match "[a-zA-Z0-9]" c) == null then "_" else c) name; + ersatz = builtins.getEnv "NIV_OVERRIDE_${saneName}"; + in + if ersatz == "" then drv else + # this turns the string into an actual Nix path (for both absolute and + # relative paths) + if builtins.substring 0 1 ersatz == "/" then /. + ersatz else /. + builtins.getEnv "PWD" + "/${ersatz}"; + + # Ports of functions for older nix versions + + # a Nix version of mapAttrs if the built-in doesn't exist + mapAttrs = builtins.mapAttrs or ( + f: set: with builtins; + listToAttrs (map (attr: { name = attr; value = f attr set.${attr}; }) (attrNames set)) + ); + + # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/lists.nix#L295 + range = first: last: if first > last then [ ] else builtins.genList (n: first + n) (last - first + 1); + + # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/strings.nix#L257 + stringToCharacters = s: map (p: builtins.substring p 1 s) (range 0 (builtins.stringLength s - 1)); + + # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/strings.nix#L269 + stringAsChars = f: s: concatStrings (map f (stringToCharacters s)); + concatMapStrings = f: list: concatStrings (map f list); + concatStrings = builtins.concatStringsSep ""; + + # https://github.com/NixOS/nixpkgs/blob/8a9f58a375c401b96da862d969f66429def1d118/lib/attrsets.nix#L331 + optionalAttrs = cond: as: if cond then as else { }; + + # fetchTarball version that is compatible between all the versions of Nix + builtins_fetchTarball = { url, name ? null, sha256 }@attrs: + let + inherit (builtins) lessThan nixVersion fetchTarball; + in + if lessThan nixVersion "1.12" then + fetchTarball ({ inherit url; } // (optionalAttrs (name != null) { inherit name; })) + else + fetchTarball attrs; + + # fetchurl version that is compatible between all the versions of Nix + builtins_fetchurl = { url, name ? null, sha256 }@attrs: + let + inherit (builtins) lessThan nixVersion fetchurl; + in + if lessThan nixVersion "1.12" then + fetchurl ({ inherit url; } // (optionalAttrs (name != null) { inherit name; })) + else + fetchurl attrs; + + # Create the final "sources" from the config + mkSources = config: + mapAttrs + ( + name: spec: + if builtins.hasAttr "outPath" spec + then + abort + "The values in sources.json should not have an 'outPath' attribute" + else + spec // { outPath = replace name (fetch config.pkgs name spec); } + ) + config.sources; + + # The "config" used by the fetchers + mkConfig = + { sourcesFile ? if builtins.pathExists ./sources.json then ./sources.json else null + , sources ? if sourcesFile == null then { } else builtins.fromJSON (builtins.readFile sourcesFile) + , system ? builtins.currentSystem + , pkgs ? mkPkgs sources system + }: rec { + # The sources, i.e. the attribute set of spec name to spec + inherit sources; + + # The "pkgs" (evaluated nixpkgs) to use for e.g. non-builtin fetchers + inherit pkgs; + }; + +in +mkSources (mkConfig { }) // { __functor = _: settings: mkSources (mkConfig settings); } diff --git a/copilot-visualizer/default.nix b/copilot-visualizer/default.nix new file mode 100644 index 000000000..896230e4f --- /dev/null +++ b/copilot-visualizer/default.nix @@ -0,0 +1,33 @@ +{ sources ? import ./nix/sources.nix, ghc ? "ghc98" }: +let + depOverlay = n: o: { + copilot-language = (import ../copilot-language { inherit sources ghc; }).copilot-language; + copilot-interpreter = (import ../copilot-interpreter { inherit sources ghc; }).copilot-interpreter; + copilot-core = (import ../copilot-core { inherit sources ghc; }).copilot-core; + copilot = (import ../copilot { inherit sources ghc; }).copilot; + copilot-prettyprinter = (import ../copilot-prettyprinter { inherit sources ghc; }).copilot-prettyprinter; + }; + np = import sources.nixpkgs {}; + bhp = np.haskell.packages.${ghc}; + + sourceRegexes = [ + "^src.*$" + "^data.*$" + "^examples.*$" + "^.*\\.cabal$" + "^LICENSE$" + ]; + + copilot-visualizer-base = hp.callCabal2nix "copilot-visualizer" (np.lib.sourceByRegex ./. sourceRegexes) {}; + copilot-visualizer-overlay = _n: _o: { copilot-visualizer = copilot-visualizer-base; }; + hp = bhp.override (o: { + overrides = + builtins.foldl' np.lib.composeExtensions (o.overrides or (_: _: {})) + [ depOverlay copilot-visualizer-overlay ]; + }); + copilot-visualizer = hp.copilot-visualizer; +in { + inherit np; + inherit hp; + inherit copilot-visualizer; +} diff --git a/copilot-visualizer/nix/sources.json b/copilot-visualizer/nix/sources.json new file mode 100644 index 000000000..7a59ceccc --- /dev/null +++ b/copilot-visualizer/nix/sources.json @@ -0,0 +1,12 @@ +{ + "nixpkgs": { + "branch": "master", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "63117158fe4f7f9b34eaecef088c417f8151e4ba", + "sha256": "sha256:036cjpfjghm6f8h4cldpv040kfvii7x8g5php4vyn9qmpncybxj6", + "type": "tarball", + "url": "https://github.com/NixOS/nixpkgs/archive/63117158fe4f7f9b34eaecef088c417f8151e4ba.tar.gz", + "url_template": "https://github.com///archive/.tar.gz" + } +} diff --git a/copilot-visualizer/nix/sources.nix b/copilot-visualizer/nix/sources.nix new file mode 100644 index 000000000..fe3dadf7e --- /dev/null +++ b/copilot-visualizer/nix/sources.nix @@ -0,0 +1,198 @@ +# This file has been generated by Niv. + +let + + # + # The fetchers. fetch_ fetches specs of type . + # + + fetch_file = pkgs: name: spec: + let + name' = sanitizeName name + "-src"; + in + if spec.builtin or true then + builtins_fetchurl { inherit (spec) url sha256; name = name'; } + else + pkgs.fetchurl { inherit (spec) url sha256; name = name'; }; + + fetch_tarball = pkgs: name: spec: + let + name' = sanitizeName name + "-src"; + in + if spec.builtin or true then + builtins_fetchTarball { name = name'; inherit (spec) url sha256; } + else + pkgs.fetchzip { name = name'; inherit (spec) url sha256; }; + + fetch_git = name: spec: + let + ref = + spec.ref or ( + if spec ? branch then "refs/heads/${spec.branch}" else + if spec ? tag then "refs/tags/${spec.tag}" else + abort "In git source '${name}': Please specify `ref`, `tag` or `branch`!" + ); + submodules = spec.submodules or false; + submoduleArg = + let + nixSupportsSubmodules = builtins.compareVersions builtins.nixVersion "2.4" >= 0; + emptyArgWithWarning = + if submodules + then + builtins.trace + ( + "The niv input \"${name}\" uses submodules " + + "but your nix's (${builtins.nixVersion}) builtins.fetchGit " + + "does not support them" + ) + { } + else { }; + in + if nixSupportsSubmodules + then { inherit submodules; } + else emptyArgWithWarning; + in + builtins.fetchGit + ({ url = spec.repo; inherit (spec) rev; inherit ref; } // submoduleArg); + + fetch_local = spec: spec.path; + + fetch_builtin-tarball = name: throw + ''[${name}] The niv type "builtin-tarball" is deprecated. You should instead use `builtin = true`. + $ niv modify ${name} -a type=tarball -a builtin=true''; + + fetch_builtin-url = name: throw + ''[${name}] The niv type "builtin-url" will soon be deprecated. You should instead use `builtin = true`. + $ niv modify ${name} -a type=file -a builtin=true''; + + # + # Various helpers + # + + # https://github.com/NixOS/nixpkgs/pull/83241/files#diff-c6f540a4f3bfa4b0e8b6bafd4cd54e8bR695 + sanitizeName = name: + ( + concatMapStrings (s: if builtins.isList s then "-" else s) + ( + builtins.split "[^[:alnum:]+._?=-]+" + ((x: builtins.elemAt (builtins.match "\\.*(.*)" x) 0) name) + ) + ); + + # The set of packages used when specs are fetched using non-builtins. + mkPkgs = sources: system: + let + sourcesNixpkgs = + import (builtins_fetchTarball { inherit (sources.nixpkgs) url sha256; }) { inherit system; }; + hasNixpkgsPath = builtins.any (x: x.prefix == "nixpkgs") builtins.nixPath; + hasThisAsNixpkgsPath = == ./.; + in + if builtins.hasAttr "nixpkgs" sources + then sourcesNixpkgs + else if hasNixpkgsPath && ! hasThisAsNixpkgsPath then + import { } + else + abort + '' + Please specify either (through -I or NIX_PATH=nixpkgs=...) or + add a package called "nixpkgs" to your sources.json. + ''; + + # The actual fetching function. + fetch = pkgs: name: spec: + + if ! builtins.hasAttr "type" spec then + abort "ERROR: niv spec ${name} does not have a 'type' attribute" + else if spec.type == "file" then fetch_file pkgs name spec + else if spec.type == "tarball" then fetch_tarball pkgs name spec + else if spec.type == "git" then fetch_git name spec + else if spec.type == "local" then fetch_local spec + else if spec.type == "builtin-tarball" then fetch_builtin-tarball name + else if spec.type == "builtin-url" then fetch_builtin-url name + else + abort "ERROR: niv spec ${name} has unknown type ${builtins.toJSON spec.type}"; + + # If the environment variable NIV_OVERRIDE_${name} is set, then use + # the path directly as opposed to the fetched source. + replace = name: drv: + let + saneName = stringAsChars (c: if (builtins.match "[a-zA-Z0-9]" c) == null then "_" else c) name; + ersatz = builtins.getEnv "NIV_OVERRIDE_${saneName}"; + in + if ersatz == "" then drv else + # this turns the string into an actual Nix path (for both absolute and + # relative paths) + if builtins.substring 0 1 ersatz == "/" then /. + ersatz else /. + builtins.getEnv "PWD" + "/${ersatz}"; + + # Ports of functions for older nix versions + + # a Nix version of mapAttrs if the built-in doesn't exist + mapAttrs = builtins.mapAttrs or ( + f: set: with builtins; + listToAttrs (map (attr: { name = attr; value = f attr set.${attr}; }) (attrNames set)) + ); + + # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/lists.nix#L295 + range = first: last: if first > last then [ ] else builtins.genList (n: first + n) (last - first + 1); + + # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/strings.nix#L257 + stringToCharacters = s: map (p: builtins.substring p 1 s) (range 0 (builtins.stringLength s - 1)); + + # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/strings.nix#L269 + stringAsChars = f: s: concatStrings (map f (stringToCharacters s)); + concatMapStrings = f: list: concatStrings (map f list); + concatStrings = builtins.concatStringsSep ""; + + # https://github.com/NixOS/nixpkgs/blob/8a9f58a375c401b96da862d969f66429def1d118/lib/attrsets.nix#L331 + optionalAttrs = cond: as: if cond then as else { }; + + # fetchTarball version that is compatible between all the versions of Nix + builtins_fetchTarball = { url, name ? null, sha256 }@attrs: + let + inherit (builtins) lessThan nixVersion fetchTarball; + in + if lessThan nixVersion "1.12" then + fetchTarball ({ inherit url; } // (optionalAttrs (name != null) { inherit name; })) + else + fetchTarball attrs; + + # fetchurl version that is compatible between all the versions of Nix + builtins_fetchurl = { url, name ? null, sha256 }@attrs: + let + inherit (builtins) lessThan nixVersion fetchurl; + in + if lessThan nixVersion "1.12" then + fetchurl ({ inherit url; } // (optionalAttrs (name != null) { inherit name; })) + else + fetchurl attrs; + + # Create the final "sources" from the config + mkSources = config: + mapAttrs + ( + name: spec: + if builtins.hasAttr "outPath" spec + then + abort + "The values in sources.json should not have an 'outPath' attribute" + else + spec // { outPath = replace name (fetch config.pkgs name spec); } + ) + config.sources; + + # The "config" used by the fetchers + mkConfig = + { sourcesFile ? if builtins.pathExists ./sources.json then ./sources.json else null + , sources ? if sourcesFile == null then { } else builtins.fromJSON (builtins.readFile sourcesFile) + , system ? builtins.currentSystem + , pkgs ? mkPkgs sources system + }: rec { + # The sources, i.e. the attribute set of spec name to spec + inherit sources; + + # The "pkgs" (evaluated nixpkgs) to use for e.g. non-builtin fetchers + inherit pkgs; + }; + +in +mkSources (mkConfig { }) // { __functor = _: settings: mkSources (mkConfig settings); } diff --git a/copilot/default.nix b/copilot/default.nix new file mode 100644 index 000000000..cba76477b --- /dev/null +++ b/copilot/default.nix @@ -0,0 +1,38 @@ +{ sources ? import ./nix/sources.nix, ghc ? "ghc98" }: +let + depOverlay = n: o: { + copilot-core = (import ../copilot-core { inherit sources ghc; }).copilot-core; + copilot-c99 = (import ../copilot-c99 { inherit sources ghc; }).copilot-c99; + copilot-language = (import ../copilot-language { inherit sources ghc; }).copilot-language; + copilot-libraries = (import ../copilot-libraries { inherit sources ghc; }).copilot-libraries; + copilot-prettyprinter = (import ../copilot-prettyprinter { inherit sources ghc; }).copilot-prettyprinter; + copilot-theorem = (import ../copilot-theorem { inherit sources ghc; }).copilot-theorem; + }; + np = import sources.nixpkgs {}; + bhp = np.haskell.packages.${ghc}; + + sourceRegexes = [ + "^src.*$" + "^examples.*$" + "^runtest$" + "^.*\\.cabal$" + "^LICENSE$" + ]; + + withExamples = drv: drv.overrideAttrs(oa: + { configureFlags = oa.configureFlags ++ [ "-f examples" ]; }); + + copilot-base = withExamples (hp.callCabal2nix "copilot" (np.lib.sourceByRegex ./. sourceRegexes) {}); + + copilot-overlay = _n: _o: { copilot = copilot-base; }; + hp = bhp.override (o: { + overrides = + builtins.foldl' np.lib.composeExtensions (o.overrides or (_: _: {})) + [ depOverlay copilot-overlay ]; + }); + copilot = hp.copilot; +in { + inherit np; + inherit hp; + inherit copilot; +} diff --git a/copilot/nix/sources.json b/copilot/nix/sources.json new file mode 100644 index 000000000..7a59ceccc --- /dev/null +++ b/copilot/nix/sources.json @@ -0,0 +1,12 @@ +{ + "nixpkgs": { + "branch": "master", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "63117158fe4f7f9b34eaecef088c417f8151e4ba", + "sha256": "sha256:036cjpfjghm6f8h4cldpv040kfvii7x8g5php4vyn9qmpncybxj6", + "type": "tarball", + "url": "https://github.com/NixOS/nixpkgs/archive/63117158fe4f7f9b34eaecef088c417f8151e4ba.tar.gz", + "url_template": "https://github.com///archive/.tar.gz" + } +} diff --git a/copilot/nix/sources.nix b/copilot/nix/sources.nix new file mode 100644 index 000000000..fe3dadf7e --- /dev/null +++ b/copilot/nix/sources.nix @@ -0,0 +1,198 @@ +# This file has been generated by Niv. + +let + + # + # The fetchers. fetch_ fetches specs of type . + # + + fetch_file = pkgs: name: spec: + let + name' = sanitizeName name + "-src"; + in + if spec.builtin or true then + builtins_fetchurl { inherit (spec) url sha256; name = name'; } + else + pkgs.fetchurl { inherit (spec) url sha256; name = name'; }; + + fetch_tarball = pkgs: name: spec: + let + name' = sanitizeName name + "-src"; + in + if spec.builtin or true then + builtins_fetchTarball { name = name'; inherit (spec) url sha256; } + else + pkgs.fetchzip { name = name'; inherit (spec) url sha256; }; + + fetch_git = name: spec: + let + ref = + spec.ref or ( + if spec ? branch then "refs/heads/${spec.branch}" else + if spec ? tag then "refs/tags/${spec.tag}" else + abort "In git source '${name}': Please specify `ref`, `tag` or `branch`!" + ); + submodules = spec.submodules or false; + submoduleArg = + let + nixSupportsSubmodules = builtins.compareVersions builtins.nixVersion "2.4" >= 0; + emptyArgWithWarning = + if submodules + then + builtins.trace + ( + "The niv input \"${name}\" uses submodules " + + "but your nix's (${builtins.nixVersion}) builtins.fetchGit " + + "does not support them" + ) + { } + else { }; + in + if nixSupportsSubmodules + then { inherit submodules; } + else emptyArgWithWarning; + in + builtins.fetchGit + ({ url = spec.repo; inherit (spec) rev; inherit ref; } // submoduleArg); + + fetch_local = spec: spec.path; + + fetch_builtin-tarball = name: throw + ''[${name}] The niv type "builtin-tarball" is deprecated. You should instead use `builtin = true`. + $ niv modify ${name} -a type=tarball -a builtin=true''; + + fetch_builtin-url = name: throw + ''[${name}] The niv type "builtin-url" will soon be deprecated. You should instead use `builtin = true`. + $ niv modify ${name} -a type=file -a builtin=true''; + + # + # Various helpers + # + + # https://github.com/NixOS/nixpkgs/pull/83241/files#diff-c6f540a4f3bfa4b0e8b6bafd4cd54e8bR695 + sanitizeName = name: + ( + concatMapStrings (s: if builtins.isList s then "-" else s) + ( + builtins.split "[^[:alnum:]+._?=-]+" + ((x: builtins.elemAt (builtins.match "\\.*(.*)" x) 0) name) + ) + ); + + # The set of packages used when specs are fetched using non-builtins. + mkPkgs = sources: system: + let + sourcesNixpkgs = + import (builtins_fetchTarball { inherit (sources.nixpkgs) url sha256; }) { inherit system; }; + hasNixpkgsPath = builtins.any (x: x.prefix == "nixpkgs") builtins.nixPath; + hasThisAsNixpkgsPath = == ./.; + in + if builtins.hasAttr "nixpkgs" sources + then sourcesNixpkgs + else if hasNixpkgsPath && ! hasThisAsNixpkgsPath then + import { } + else + abort + '' + Please specify either (through -I or NIX_PATH=nixpkgs=...) or + add a package called "nixpkgs" to your sources.json. + ''; + + # The actual fetching function. + fetch = pkgs: name: spec: + + if ! builtins.hasAttr "type" spec then + abort "ERROR: niv spec ${name} does not have a 'type' attribute" + else if spec.type == "file" then fetch_file pkgs name spec + else if spec.type == "tarball" then fetch_tarball pkgs name spec + else if spec.type == "git" then fetch_git name spec + else if spec.type == "local" then fetch_local spec + else if spec.type == "builtin-tarball" then fetch_builtin-tarball name + else if spec.type == "builtin-url" then fetch_builtin-url name + else + abort "ERROR: niv spec ${name} has unknown type ${builtins.toJSON spec.type}"; + + # If the environment variable NIV_OVERRIDE_${name} is set, then use + # the path directly as opposed to the fetched source. + replace = name: drv: + let + saneName = stringAsChars (c: if (builtins.match "[a-zA-Z0-9]" c) == null then "_" else c) name; + ersatz = builtins.getEnv "NIV_OVERRIDE_${saneName}"; + in + if ersatz == "" then drv else + # this turns the string into an actual Nix path (for both absolute and + # relative paths) + if builtins.substring 0 1 ersatz == "/" then /. + ersatz else /. + builtins.getEnv "PWD" + "/${ersatz}"; + + # Ports of functions for older nix versions + + # a Nix version of mapAttrs if the built-in doesn't exist + mapAttrs = builtins.mapAttrs or ( + f: set: with builtins; + listToAttrs (map (attr: { name = attr; value = f attr set.${attr}; }) (attrNames set)) + ); + + # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/lists.nix#L295 + range = first: last: if first > last then [ ] else builtins.genList (n: first + n) (last - first + 1); + + # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/strings.nix#L257 + stringToCharacters = s: map (p: builtins.substring p 1 s) (range 0 (builtins.stringLength s - 1)); + + # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/strings.nix#L269 + stringAsChars = f: s: concatStrings (map f (stringToCharacters s)); + concatMapStrings = f: list: concatStrings (map f list); + concatStrings = builtins.concatStringsSep ""; + + # https://github.com/NixOS/nixpkgs/blob/8a9f58a375c401b96da862d969f66429def1d118/lib/attrsets.nix#L331 + optionalAttrs = cond: as: if cond then as else { }; + + # fetchTarball version that is compatible between all the versions of Nix + builtins_fetchTarball = { url, name ? null, sha256 }@attrs: + let + inherit (builtins) lessThan nixVersion fetchTarball; + in + if lessThan nixVersion "1.12" then + fetchTarball ({ inherit url; } // (optionalAttrs (name != null) { inherit name; })) + else + fetchTarball attrs; + + # fetchurl version that is compatible between all the versions of Nix + builtins_fetchurl = { url, name ? null, sha256 }@attrs: + let + inherit (builtins) lessThan nixVersion fetchurl; + in + if lessThan nixVersion "1.12" then + fetchurl ({ inherit url; } // (optionalAttrs (name != null) { inherit name; })) + else + fetchurl attrs; + + # Create the final "sources" from the config + mkSources = config: + mapAttrs + ( + name: spec: + if builtins.hasAttr "outPath" spec + then + abort + "The values in sources.json should not have an 'outPath' attribute" + else + spec // { outPath = replace name (fetch config.pkgs name spec); } + ) + config.sources; + + # The "config" used by the fetchers + mkConfig = + { sourcesFile ? if builtins.pathExists ./sources.json then ./sources.json else null + , sources ? if sourcesFile == null then { } else builtins.fromJSON (builtins.readFile sourcesFile) + , system ? builtins.currentSystem + , pkgs ? mkPkgs sources system + }: rec { + # The sources, i.e. the attribute set of spec name to spec + inherit sources; + + # The "pkgs" (evaluated nixpkgs) to use for e.g. non-builtin fetchers + inherit pkgs; + }; + +in +mkSources (mkConfig { }) // { __functor = _: settings: mkSources (mkConfig settings); } From 3c1c7cf25019af46ea917ca7ca32a254ec32e632 Mon Sep 17 00:00:00 2001 From: Daniil Iaitskov Date: Fri, 14 Nov 2025 17:24:10 +0300 Subject: [PATCH 05/18] nix remove dead nix lines --- copilot-theorem/default.nix | 10 ---------- copilot-verifier/default.nix | 24 ------------------------ 2 files changed, 34 deletions(-) diff --git a/copilot-theorem/default.nix b/copilot-theorem/default.nix index 4fe952f4c..cb4caf650 100644 --- a/copilot-theorem/default.nix +++ b/copilot-theorem/default.nix @@ -4,11 +4,6 @@ let copilot-core = (import ../copilot-core { inherit sources ghc; }).copilot-core; copilot-prettyprinter = (import ../copilot-prettyprinter { inherit sources ghc; }).copilot-prettyprinter; what4 = bhp.what4_1_7; - # importCvc5 (importZ3 (bhp.callHackageDirect { - # pkg = "what4"; - # ver = "1.7.1.0"; - # sha256="sha256-2V03HpjtEZl7U1n/pvgzenXO7Igmt79DZvETDjYj08k="; - # } { })); }; np = import sources.nixpkgs {}; bhp = np.haskell.packages.${ghc}; @@ -25,11 +20,6 @@ let propagatedBuildInputs = (oa.propagatedBuildInputs or []) ++ [np.z3]; }); - importCvc5 = drv: - drv.overrideAttrs (oa: { - propagatedBuildInputs = (oa.propagatedBuildInputs or []) ++ [np.cvc5]; - }); - copilot-theorem-base = importZ3 (hp.callCabal2nix "copilot-theorem" (np.lib.sourceByRegex ./. sourceRegexes) {}); copilot-theorem-overlay = _n: _o: { copilot-theorem = copilot-theorem-base; }; hp = bhp.override (o: { diff --git a/copilot-verifier/default.nix b/copilot-verifier/default.nix index 85ae2c557..548073e08 100644 --- a/copilot-verifier/default.nix +++ b/copilot-verifier/default.nix @@ -17,30 +17,6 @@ let copilot-libraries = (import ../copilot-libraries { inherit sources ghc; }).copilot-libraries; copilot-prettyprinter = (import ../copilot-prettyprinter { inherit sources ghc; }).copilot-prettyprinter; copilot-theorem = (import ../copilot-theorem { inherit sources ghc; }).copilot-theorem; - # > crux-llvm >=0.9 && <0.10, llvm-pretty >=0.12.1.0 && <0.13 - # pkg = "reflex-test-host"; - # ver = "0.1.2.3"; - # sha256 = "9ee3ad9ac4fc58c6dcabcd9fbc6d109a51d8e86ba2682cee8367bc6b452f09ea"; - # crux-llvm = - # bhp.callHackageDirect { - # pkg = "crux-llvm"; - # ver = "0.9.1"; - # sha256="sha256-OPCiLp0xDIvzdPtmEk0m7/RncZjo8fkRX1kiNr5DWTo="; - # rev = { revision = "1"; - # sha256 = "sha256-vqbWx4L7SygP07H3Jn6wsqAu1Fl/oAT1H0umOvJC8yw="; - # }; - # } { }; - # llvm-pretty = - # bhp.callHackageDirect { - # pkg = "llvm-pretty"; - # ver = "0.12.1.0"; - # sha256="sha256-0scMOvY8sXQuCXpSidRpELTyhxh7YbVOZ/2gRLo+hF0="; - # rev = { revision = "1"; - # sha256 = "sha256-vqbWx4L7SygP07H3Jn6wsqAu1Fl/oAT1H0umOvJC8yw="; - # }; - # } { }; - - # crux-llvm = bhp.callHackage "crux-llvm" "0.9.1" { }; }; np = import sources.nixpkgs {}; bhp = np.haskell.packages.${ghc}; From caabb9f24783a6acb7e0a6a4d02d63423af9e009 Mon Sep 17 00:00:00 2001 From: Daniil Iaitskov Date: Fri, 14 Nov 2025 17:25:29 +0300 Subject: [PATCH 06/18] nix extract from importZ clang and llvm into separate functions --- copilot-verifier/default.nix | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/copilot-verifier/default.nix b/copilot-verifier/default.nix index 548073e08..62f0dd113 100644 --- a/copilot-verifier/default.nix +++ b/copilot-verifier/default.nix @@ -32,11 +32,21 @@ let importZ3 = drv: drv.overrideAttrs (oa: { - propagatedBuildInputs = (oa.propagatedBuildInputs or []) ++ [np.z3 np.clang np.llvm]; + propagatedBuildInputs = (oa.propagatedBuildInputs or []) ++ [np.z3]; + }); + + importClang = drv: + drv.overrideAttrs (oa: { + propagatedBuildInputs = (oa.propagatedBuildInputs or []) ++ [np.clang]; + }); + + importLLVM = drv: + drv.overrideAttrs (oa: { + propagatedBuildInputs = (oa.propagatedBuildInputs or []) ++ [np.llvm_14]; }); copilot-verifier-base = - importZ3 (hp.callCabal2nix "copilot-verifier" (np.lib.sourceByRegex ./. sourceRegexes) {}); + importLLVM (importClang (importZ3 (hp.callCabal2nix "copilot-verifier" (np.lib.sourceByRegex ./. sourceRegexes) {}))); copilot-verifier-overlay = _n: _o: { copilot-verifier = copilot-verifier-base; }; hp = bhp.override (o: { From 5d9e5b41fcba5dd1ae5a0ae3756ce6ab728571cd Mon Sep 17 00:00:00 2001 From: Daniil Iaitskov Date: Fri, 14 Nov 2025 19:26:31 +0300 Subject: [PATCH 07/18] nix remove cabal.project because cabal in nix-shell breaks --- cabal.project | 10 ---------- 1 file changed, 10 deletions(-) delete mode 100644 cabal.project diff --git a/cabal.project b/cabal.project deleted file mode 100644 index 812c95ba6..000000000 --- a/cabal.project +++ /dev/null @@ -1,10 +0,0 @@ -packages: - copilot-bluespec/copilot-bluespec.cabal - copilot-c99/copilot-c99.cabal - copilot-core/copilot-core.cabal - copilot-interpreter/copilot-interpreter.cabal - copilot-language/copilot-language.cabal - copilot-libraries/copilot-libraries.cabal - copilot-prettyprinter/copilot-prettyprinter.cabal - copilot-theorem/copilot-theorem.cabal - copilot/copilot.cabal From 7b46f5c03fd03514a5d1c566fbfafb48c86c9dae Mon Sep 17 00:00:00 2001 From: Daniil Iaitskov Date: Fri, 14 Nov 2025 19:27:00 +0300 Subject: [PATCH 08/18] nix dead code --- copilot-verifier/default.nix | 8 -------- 1 file changed, 8 deletions(-) diff --git a/copilot-verifier/default.nix b/copilot-verifier/default.nix index 62f0dd113..3af7a719c 100644 --- a/copilot-verifier/default.nix +++ b/copilot-verifier/default.nix @@ -1,13 +1,5 @@ { sources ? import ./nix/sources.nix, ghc ? "ghc98" }: let - # depOverlay2 = n: o: { - # th-abstraction = - # bhp.callHackageDirect { - # pkg = "th-abstraction"; - # ver = "0.6.0.0"; - # sha256="sha256-eOUH1OSmLL8hS8mzijfJvGhxfMEU2vQozKHKlbv2B/A="; - # } { }; - # }; depOverlay = n: o: { copilot = (import ../copilot { inherit sources ghc; }).copilot; copilot-core = (import ../copilot-core { inherit sources ghc; }).copilot-core; From 5eab31e9e3abc416eea3d065f4577d90afec9236 Mon Sep 17 00:00:00 2001 From: Daniil Iaitskov Date: Fri, 14 Nov 2025 19:27:37 +0300 Subject: [PATCH 09/18] nix sync llvm and clang versions as 16 --- copilot-verifier/default.nix | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/copilot-verifier/default.nix b/copilot-verifier/default.nix index 3af7a719c..d2689d164 100644 --- a/copilot-verifier/default.nix +++ b/copilot-verifier/default.nix @@ -29,12 +29,12 @@ let importClang = drv: drv.overrideAttrs (oa: { - propagatedBuildInputs = (oa.propagatedBuildInputs or []) ++ [np.clang]; + propagatedBuildInputs = (oa.propagatedBuildInputs or []) ++ [np.clang_16]; }); importLLVM = drv: - drv.overrideAttrs (oa: { - propagatedBuildInputs = (oa.propagatedBuildInputs or []) ++ [np.llvm_14]; + drv.overrideAttrs (oa: { # llvm and clang versions are coupled + propagatedBuildInputs = (oa.propagatedBuildInputs or []) ++ [np.llvm_16]; }); copilot-verifier-base = From 02a7249f03b22847ddab83bfbe7b476755eef9f8 Mon Sep 17 00:00:00 2001 From: Daniil Iaitskov Date: Fri, 14 Nov 2025 19:27:51 +0300 Subject: [PATCH 10/18] nix copilot-verifier/shell.nix --- copilot-verifier/shell.nix | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 copilot-verifier/shell.nix diff --git a/copilot-verifier/shell.nix b/copilot-verifier/shell.nix new file mode 100644 index 000000000..7e0d3e36d --- /dev/null +++ b/copilot-verifier/shell.nix @@ -0,0 +1,8 @@ +{}: +let + inherit (import ./. {}) copilot-verifier hp np; +in +hp.shellFor { + packages = p: [ copilot-verifier ]; + nativeBuildInputs = (with np; [ cabal-install ghcid niv np.clang_16 np.llvm_16 np.z3 ]); +} From 8e03a6b61cf10cd2a34b661fb6686d363e13e1b6 Mon Sep 17 00:00:00 2001 From: Daniil Iaitskov Date: Sat, 15 Nov 2025 13:16:58 +0300 Subject: [PATCH 11/18] nix nix CI --- .github/workflows/test.yml | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 .github/workflows/test.yml diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 000000000..b0bbacc7d --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,15 @@ +name: "nix-build with tests" +on: + pull_request: + push: +jobs: + tests: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4.2.2 + - uses: cachix/install-nix-action@v31 + with: + nix_path: nixpkgs=channel:nixos-unstable + - run: + nix-build copilot-bluespec + nix-build copilot-verifier From e52d03191507e267bb1af5123fa03aaafe15c423 Mon Sep 17 00:00:00 2001 From: Daniil Iaitskov Date: Sat, 15 Nov 2025 13:34:09 +0300 Subject: [PATCH 12/18] nix split commands on CI --- .github/workflows/test.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b0bbacc7d..10e23d423 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -12,4 +12,5 @@ jobs: nix_path: nixpkgs=channel:nixos-unstable - run: nix-build copilot-bluespec + - run: nix-build copilot-verifier From bb1e7d150787ea4a712cb12771a9291514b5ad79 Mon Sep 17 00:00:00 2001 From: Daniil Iaitskov Date: Sat, 15 Nov 2025 15:16:17 +0300 Subject: [PATCH 13/18] nix turn off wrapv in tests and shell to make AbsIntMin-fail test pass --- copilot-verifier/default.nix | 27 +++++++++++---------------- copilot-verifier/shell.nix | 5 +++-- 2 files changed, 14 insertions(+), 18 deletions(-) diff --git a/copilot-verifier/default.nix b/copilot-verifier/default.nix index d2689d164..b25b09c76 100644 --- a/copilot-verifier/default.nix +++ b/copilot-verifier/default.nix @@ -22,23 +22,16 @@ let "^LICENSE$" ]; - importZ3 = drv: - drv.overrideAttrs (oa: { - propagatedBuildInputs = (oa.propagatedBuildInputs or []) ++ [np.z3]; - }); - - importClang = drv: - drv.overrideAttrs (oa: { - propagatedBuildInputs = (oa.propagatedBuildInputs or []) ++ [np.clang_16]; - }); - - importLLVM = drv: - drv.overrideAttrs (oa: { # llvm and clang versions are coupled - propagatedBuildInputs = (oa.propagatedBuildInputs or []) ++ [np.llvm_16]; - }); - + # llvm and clang versions are coupled + externalDeps = [np.z3 np.clang_16 np.llvm_16]; + shellTuning = ''export CCC_OVERRIDE_OPTIONS=+-fno-wrapv + ''; copilot-verifier-base = - importLLVM (importClang (importZ3 (hp.callCabal2nix "copilot-verifier" (np.lib.sourceByRegex ./. sourceRegexes) {}))); + (hp.callCabal2nix "copilot-verifier" (np.lib.sourceByRegex ./. sourceRegexes) {}).overrideAttrs + (oa: { + checkPhase = shellTuning + oa.checkPhase; + propagatedBuildInputs = (oa.propagatedBuildInputs or []) ++ externalDeps; + }); copilot-verifier-overlay = _n: _o: { copilot-verifier = copilot-verifier-base; }; hp = bhp.override (o: { @@ -50,5 +43,7 @@ let in { inherit np; inherit hp; + inherit externalDeps; + inherit shellTuning; inherit copilot-verifier; } diff --git a/copilot-verifier/shell.nix b/copilot-verifier/shell.nix index 7e0d3e36d..7cb0ba608 100644 --- a/copilot-verifier/shell.nix +++ b/copilot-verifier/shell.nix @@ -1,8 +1,9 @@ {}: let - inherit (import ./. {}) copilot-verifier hp np; + inherit (import ./. {}) copilot-verifier hp np externalDeps shellTuning; in hp.shellFor { packages = p: [ copilot-verifier ]; - nativeBuildInputs = (with np; [ cabal-install ghcid niv np.clang_16 np.llvm_16 np.z3 ]); + nativeBuildInputs = (with np; [ cabal-install ghcid niv]) ++ externalDeps; + shellHook = shellTuning; } From d4192377aeac8fad9ced216b2b492f8661a9c501 Mon Sep 17 00:00:00 2001 From: Daniil Iaitskov Date: Sat, 15 Nov 2025 16:23:33 +0300 Subject: [PATCH 14/18] nix deduplicate nix folder --- copilot-bluespec/default.nix | 2 +- copilot-bluespec/nix/sources.json | 12 -- copilot-c99/default.nix | 2 +- copilot-c99/nix/sources.json | 12 -- copilot-c99/nix/sources.nix | 198 --------------------- copilot-core/default.nix | 10 +- copilot-core/nix/sources.json | 12 -- copilot-core/nix/sources.nix | 198 --------------------- copilot-interpreter/default.nix | 2 +- copilot-interpreter/nix/sources.json | 12 -- copilot-interpreter/nix/sources.nix | 198 --------------------- copilot-language/default.nix | 2 +- copilot-language/nix/sources.json | 12 -- copilot-language/nix/sources.nix | 198 --------------------- copilot-libraries/default.nix | 2 +- copilot-libraries/nix/sources.json | 12 -- copilot-libraries/nix/sources.nix | 198 --------------------- copilot-prettyprinter/default.nix | 2 +- copilot-prettyprinter/nix/sources.json | 12 -- copilot-prettyprinter/nix/sources.nix | 198 --------------------- copilot-theorem/default.nix | 2 +- copilot-theorem/nix/sources.json | 12 -- copilot-theorem/nix/sources.nix | 198 --------------------- copilot-verifier/default.nix | 2 +- copilot-verifier/nix/sources.nix | 198 --------------------- copilot-visualizer/default.nix | 2 +- copilot-visualizer/nix/sources.json | 12 -- copilot-visualizer/nix/sources.nix | 198 --------------------- copilot/default.nix | 2 +- copilot/nix/sources.json | 12 -- copilot/nix/sources.nix | 198 --------------------- {copilot-verifier/nix => nix}/sources.json | 0 {copilot-bluespec/nix => nix}/sources.nix | 0 33 files changed, 11 insertions(+), 2119 deletions(-) delete mode 100644 copilot-bluespec/nix/sources.json delete mode 100644 copilot-c99/nix/sources.json delete mode 100644 copilot-c99/nix/sources.nix delete mode 100644 copilot-core/nix/sources.json delete mode 100644 copilot-core/nix/sources.nix delete mode 100644 copilot-interpreter/nix/sources.json delete mode 100644 copilot-interpreter/nix/sources.nix delete mode 100644 copilot-language/nix/sources.json delete mode 100644 copilot-language/nix/sources.nix delete mode 100644 copilot-libraries/nix/sources.json delete mode 100644 copilot-libraries/nix/sources.nix delete mode 100644 copilot-prettyprinter/nix/sources.json delete mode 100644 copilot-prettyprinter/nix/sources.nix delete mode 100644 copilot-theorem/nix/sources.json delete mode 100644 copilot-theorem/nix/sources.nix delete mode 100644 copilot-verifier/nix/sources.nix delete mode 100644 copilot-visualizer/nix/sources.json delete mode 100644 copilot-visualizer/nix/sources.nix delete mode 100644 copilot/nix/sources.json delete mode 100644 copilot/nix/sources.nix rename {copilot-verifier/nix => nix}/sources.json (100%) rename {copilot-bluespec/nix => nix}/sources.nix (100%) diff --git a/copilot-bluespec/default.nix b/copilot-bluespec/default.nix index 10c273eb2..97430f9b3 100644 --- a/copilot-bluespec/default.nix +++ b/copilot-bluespec/default.nix @@ -1,4 +1,4 @@ -{ sources ? import ./nix/sources.nix, ghc ? "ghc98" }: +{ sources ? import ../nix/sources.nix, ghc ? "ghc98" }: let depOverlay = n: o: { copilot-core = (import ../copilot-core { inherit sources ghc; }).copilot-core; diff --git a/copilot-bluespec/nix/sources.json b/copilot-bluespec/nix/sources.json deleted file mode 100644 index 7a59ceccc..000000000 --- a/copilot-bluespec/nix/sources.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "nixpkgs": { - "branch": "master", - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "63117158fe4f7f9b34eaecef088c417f8151e4ba", - "sha256": "sha256:036cjpfjghm6f8h4cldpv040kfvii7x8g5php4vyn9qmpncybxj6", - "type": "tarball", - "url": "https://github.com/NixOS/nixpkgs/archive/63117158fe4f7f9b34eaecef088c417f8151e4ba.tar.gz", - "url_template": "https://github.com///archive/.tar.gz" - } -} diff --git a/copilot-c99/default.nix b/copilot-c99/default.nix index f58092877..154b7057d 100644 --- a/copilot-c99/default.nix +++ b/copilot-c99/default.nix @@ -1,4 +1,4 @@ -{ sources ? import ./nix/sources.nix, ghc ? "ghc98" }: +{ sources ? import ../nix/sources.nix, ghc ? "ghc98" }: let depOverlay = n: o: { copilot-core = (import ../copilot-core { inherit sources ghc; }).copilot-core; diff --git a/copilot-c99/nix/sources.json b/copilot-c99/nix/sources.json deleted file mode 100644 index 7a59ceccc..000000000 --- a/copilot-c99/nix/sources.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "nixpkgs": { - "branch": "master", - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "63117158fe4f7f9b34eaecef088c417f8151e4ba", - "sha256": "sha256:036cjpfjghm6f8h4cldpv040kfvii7x8g5php4vyn9qmpncybxj6", - "type": "tarball", - "url": "https://github.com/NixOS/nixpkgs/archive/63117158fe4f7f9b34eaecef088c417f8151e4ba.tar.gz", - "url_template": "https://github.com///archive/.tar.gz" - } -} diff --git a/copilot-c99/nix/sources.nix b/copilot-c99/nix/sources.nix deleted file mode 100644 index fe3dadf7e..000000000 --- a/copilot-c99/nix/sources.nix +++ /dev/null @@ -1,198 +0,0 @@ -# This file has been generated by Niv. - -let - - # - # The fetchers. fetch_ fetches specs of type . - # - - fetch_file = pkgs: name: spec: - let - name' = sanitizeName name + "-src"; - in - if spec.builtin or true then - builtins_fetchurl { inherit (spec) url sha256; name = name'; } - else - pkgs.fetchurl { inherit (spec) url sha256; name = name'; }; - - fetch_tarball = pkgs: name: spec: - let - name' = sanitizeName name + "-src"; - in - if spec.builtin or true then - builtins_fetchTarball { name = name'; inherit (spec) url sha256; } - else - pkgs.fetchzip { name = name'; inherit (spec) url sha256; }; - - fetch_git = name: spec: - let - ref = - spec.ref or ( - if spec ? branch then "refs/heads/${spec.branch}" else - if spec ? tag then "refs/tags/${spec.tag}" else - abort "In git source '${name}': Please specify `ref`, `tag` or `branch`!" - ); - submodules = spec.submodules or false; - submoduleArg = - let - nixSupportsSubmodules = builtins.compareVersions builtins.nixVersion "2.4" >= 0; - emptyArgWithWarning = - if submodules - then - builtins.trace - ( - "The niv input \"${name}\" uses submodules " - + "but your nix's (${builtins.nixVersion}) builtins.fetchGit " - + "does not support them" - ) - { } - else { }; - in - if nixSupportsSubmodules - then { inherit submodules; } - else emptyArgWithWarning; - in - builtins.fetchGit - ({ url = spec.repo; inherit (spec) rev; inherit ref; } // submoduleArg); - - fetch_local = spec: spec.path; - - fetch_builtin-tarball = name: throw - ''[${name}] The niv type "builtin-tarball" is deprecated. You should instead use `builtin = true`. - $ niv modify ${name} -a type=tarball -a builtin=true''; - - fetch_builtin-url = name: throw - ''[${name}] The niv type "builtin-url" will soon be deprecated. You should instead use `builtin = true`. - $ niv modify ${name} -a type=file -a builtin=true''; - - # - # Various helpers - # - - # https://github.com/NixOS/nixpkgs/pull/83241/files#diff-c6f540a4f3bfa4b0e8b6bafd4cd54e8bR695 - sanitizeName = name: - ( - concatMapStrings (s: if builtins.isList s then "-" else s) - ( - builtins.split "[^[:alnum:]+._?=-]+" - ((x: builtins.elemAt (builtins.match "\\.*(.*)" x) 0) name) - ) - ); - - # The set of packages used when specs are fetched using non-builtins. - mkPkgs = sources: system: - let - sourcesNixpkgs = - import (builtins_fetchTarball { inherit (sources.nixpkgs) url sha256; }) { inherit system; }; - hasNixpkgsPath = builtins.any (x: x.prefix == "nixpkgs") builtins.nixPath; - hasThisAsNixpkgsPath = == ./.; - in - if builtins.hasAttr "nixpkgs" sources - then sourcesNixpkgs - else if hasNixpkgsPath && ! hasThisAsNixpkgsPath then - import { } - else - abort - '' - Please specify either (through -I or NIX_PATH=nixpkgs=...) or - add a package called "nixpkgs" to your sources.json. - ''; - - # The actual fetching function. - fetch = pkgs: name: spec: - - if ! builtins.hasAttr "type" spec then - abort "ERROR: niv spec ${name} does not have a 'type' attribute" - else if spec.type == "file" then fetch_file pkgs name spec - else if spec.type == "tarball" then fetch_tarball pkgs name spec - else if spec.type == "git" then fetch_git name spec - else if spec.type == "local" then fetch_local spec - else if spec.type == "builtin-tarball" then fetch_builtin-tarball name - else if spec.type == "builtin-url" then fetch_builtin-url name - else - abort "ERROR: niv spec ${name} has unknown type ${builtins.toJSON spec.type}"; - - # If the environment variable NIV_OVERRIDE_${name} is set, then use - # the path directly as opposed to the fetched source. - replace = name: drv: - let - saneName = stringAsChars (c: if (builtins.match "[a-zA-Z0-9]" c) == null then "_" else c) name; - ersatz = builtins.getEnv "NIV_OVERRIDE_${saneName}"; - in - if ersatz == "" then drv else - # this turns the string into an actual Nix path (for both absolute and - # relative paths) - if builtins.substring 0 1 ersatz == "/" then /. + ersatz else /. + builtins.getEnv "PWD" + "/${ersatz}"; - - # Ports of functions for older nix versions - - # a Nix version of mapAttrs if the built-in doesn't exist - mapAttrs = builtins.mapAttrs or ( - f: set: with builtins; - listToAttrs (map (attr: { name = attr; value = f attr set.${attr}; }) (attrNames set)) - ); - - # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/lists.nix#L295 - range = first: last: if first > last then [ ] else builtins.genList (n: first + n) (last - first + 1); - - # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/strings.nix#L257 - stringToCharacters = s: map (p: builtins.substring p 1 s) (range 0 (builtins.stringLength s - 1)); - - # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/strings.nix#L269 - stringAsChars = f: s: concatStrings (map f (stringToCharacters s)); - concatMapStrings = f: list: concatStrings (map f list); - concatStrings = builtins.concatStringsSep ""; - - # https://github.com/NixOS/nixpkgs/blob/8a9f58a375c401b96da862d969f66429def1d118/lib/attrsets.nix#L331 - optionalAttrs = cond: as: if cond then as else { }; - - # fetchTarball version that is compatible between all the versions of Nix - builtins_fetchTarball = { url, name ? null, sha256 }@attrs: - let - inherit (builtins) lessThan nixVersion fetchTarball; - in - if lessThan nixVersion "1.12" then - fetchTarball ({ inherit url; } // (optionalAttrs (name != null) { inherit name; })) - else - fetchTarball attrs; - - # fetchurl version that is compatible between all the versions of Nix - builtins_fetchurl = { url, name ? null, sha256 }@attrs: - let - inherit (builtins) lessThan nixVersion fetchurl; - in - if lessThan nixVersion "1.12" then - fetchurl ({ inherit url; } // (optionalAttrs (name != null) { inherit name; })) - else - fetchurl attrs; - - # Create the final "sources" from the config - mkSources = config: - mapAttrs - ( - name: spec: - if builtins.hasAttr "outPath" spec - then - abort - "The values in sources.json should not have an 'outPath' attribute" - else - spec // { outPath = replace name (fetch config.pkgs name spec); } - ) - config.sources; - - # The "config" used by the fetchers - mkConfig = - { sourcesFile ? if builtins.pathExists ./sources.json then ./sources.json else null - , sources ? if sourcesFile == null then { } else builtins.fromJSON (builtins.readFile sourcesFile) - , system ? builtins.currentSystem - , pkgs ? mkPkgs sources system - }: rec { - # The sources, i.e. the attribute set of spec name to spec - inherit sources; - - # The "pkgs" (evaluated nixpkgs) to use for e.g. non-builtin fetchers - inherit pkgs; - }; - -in -mkSources (mkConfig { }) // { __functor = _: settings: mkSources (mkConfig settings); } diff --git a/copilot-core/default.nix b/copilot-core/default.nix index b4b2cea8c..b8ea8705e 100644 --- a/copilot-core/default.nix +++ b/copilot-core/default.nix @@ -1,4 +1,4 @@ -{ sources ? import ./nix/sources.nix, ghc ? "ghc98" }: +{ sources ? import ../nix/sources.nix, ghc ? "ghc98" }: let np = import sources.nixpkgs {}; hp = np.haskell.packages.${ghc}; @@ -11,14 +11,6 @@ let ]; copilot-core = hp.callCabal2nix "copilot-core" (np.lib.sourceByRegex ./. sourceRegexes) {}; - # copilot-core-overlay = _n: _o: { copilot-core = copilot-core-base; }; - # hp = bhp.override (o: { - # overrides = - # builtins.foldl' np.lib.composeExtensions (o.overrides or (_: _: {})) - # [ copilot-core-overlay ]; - # }); - # copilot-core = hp.copilot-core; - in { inherit np; inherit hp; diff --git a/copilot-core/nix/sources.json b/copilot-core/nix/sources.json deleted file mode 100644 index 7a59ceccc..000000000 --- a/copilot-core/nix/sources.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "nixpkgs": { - "branch": "master", - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "63117158fe4f7f9b34eaecef088c417f8151e4ba", - "sha256": "sha256:036cjpfjghm6f8h4cldpv040kfvii7x8g5php4vyn9qmpncybxj6", - "type": "tarball", - "url": "https://github.com/NixOS/nixpkgs/archive/63117158fe4f7f9b34eaecef088c417f8151e4ba.tar.gz", - "url_template": "https://github.com///archive/.tar.gz" - } -} diff --git a/copilot-core/nix/sources.nix b/copilot-core/nix/sources.nix deleted file mode 100644 index fe3dadf7e..000000000 --- a/copilot-core/nix/sources.nix +++ /dev/null @@ -1,198 +0,0 @@ -# This file has been generated by Niv. - -let - - # - # The fetchers. fetch_ fetches specs of type . - # - - fetch_file = pkgs: name: spec: - let - name' = sanitizeName name + "-src"; - in - if spec.builtin or true then - builtins_fetchurl { inherit (spec) url sha256; name = name'; } - else - pkgs.fetchurl { inherit (spec) url sha256; name = name'; }; - - fetch_tarball = pkgs: name: spec: - let - name' = sanitizeName name + "-src"; - in - if spec.builtin or true then - builtins_fetchTarball { name = name'; inherit (spec) url sha256; } - else - pkgs.fetchzip { name = name'; inherit (spec) url sha256; }; - - fetch_git = name: spec: - let - ref = - spec.ref or ( - if spec ? branch then "refs/heads/${spec.branch}" else - if spec ? tag then "refs/tags/${spec.tag}" else - abort "In git source '${name}': Please specify `ref`, `tag` or `branch`!" - ); - submodules = spec.submodules or false; - submoduleArg = - let - nixSupportsSubmodules = builtins.compareVersions builtins.nixVersion "2.4" >= 0; - emptyArgWithWarning = - if submodules - then - builtins.trace - ( - "The niv input \"${name}\" uses submodules " - + "but your nix's (${builtins.nixVersion}) builtins.fetchGit " - + "does not support them" - ) - { } - else { }; - in - if nixSupportsSubmodules - then { inherit submodules; } - else emptyArgWithWarning; - in - builtins.fetchGit - ({ url = spec.repo; inherit (spec) rev; inherit ref; } // submoduleArg); - - fetch_local = spec: spec.path; - - fetch_builtin-tarball = name: throw - ''[${name}] The niv type "builtin-tarball" is deprecated. You should instead use `builtin = true`. - $ niv modify ${name} -a type=tarball -a builtin=true''; - - fetch_builtin-url = name: throw - ''[${name}] The niv type "builtin-url" will soon be deprecated. You should instead use `builtin = true`. - $ niv modify ${name} -a type=file -a builtin=true''; - - # - # Various helpers - # - - # https://github.com/NixOS/nixpkgs/pull/83241/files#diff-c6f540a4f3bfa4b0e8b6bafd4cd54e8bR695 - sanitizeName = name: - ( - concatMapStrings (s: if builtins.isList s then "-" else s) - ( - builtins.split "[^[:alnum:]+._?=-]+" - ((x: builtins.elemAt (builtins.match "\\.*(.*)" x) 0) name) - ) - ); - - # The set of packages used when specs are fetched using non-builtins. - mkPkgs = sources: system: - let - sourcesNixpkgs = - import (builtins_fetchTarball { inherit (sources.nixpkgs) url sha256; }) { inherit system; }; - hasNixpkgsPath = builtins.any (x: x.prefix == "nixpkgs") builtins.nixPath; - hasThisAsNixpkgsPath = == ./.; - in - if builtins.hasAttr "nixpkgs" sources - then sourcesNixpkgs - else if hasNixpkgsPath && ! hasThisAsNixpkgsPath then - import { } - else - abort - '' - Please specify either (through -I or NIX_PATH=nixpkgs=...) or - add a package called "nixpkgs" to your sources.json. - ''; - - # The actual fetching function. - fetch = pkgs: name: spec: - - if ! builtins.hasAttr "type" spec then - abort "ERROR: niv spec ${name} does not have a 'type' attribute" - else if spec.type == "file" then fetch_file pkgs name spec - else if spec.type == "tarball" then fetch_tarball pkgs name spec - else if spec.type == "git" then fetch_git name spec - else if spec.type == "local" then fetch_local spec - else if spec.type == "builtin-tarball" then fetch_builtin-tarball name - else if spec.type == "builtin-url" then fetch_builtin-url name - else - abort "ERROR: niv spec ${name} has unknown type ${builtins.toJSON spec.type}"; - - # If the environment variable NIV_OVERRIDE_${name} is set, then use - # the path directly as opposed to the fetched source. - replace = name: drv: - let - saneName = stringAsChars (c: if (builtins.match "[a-zA-Z0-9]" c) == null then "_" else c) name; - ersatz = builtins.getEnv "NIV_OVERRIDE_${saneName}"; - in - if ersatz == "" then drv else - # this turns the string into an actual Nix path (for both absolute and - # relative paths) - if builtins.substring 0 1 ersatz == "/" then /. + ersatz else /. + builtins.getEnv "PWD" + "/${ersatz}"; - - # Ports of functions for older nix versions - - # a Nix version of mapAttrs if the built-in doesn't exist - mapAttrs = builtins.mapAttrs or ( - f: set: with builtins; - listToAttrs (map (attr: { name = attr; value = f attr set.${attr}; }) (attrNames set)) - ); - - # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/lists.nix#L295 - range = first: last: if first > last then [ ] else builtins.genList (n: first + n) (last - first + 1); - - # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/strings.nix#L257 - stringToCharacters = s: map (p: builtins.substring p 1 s) (range 0 (builtins.stringLength s - 1)); - - # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/strings.nix#L269 - stringAsChars = f: s: concatStrings (map f (stringToCharacters s)); - concatMapStrings = f: list: concatStrings (map f list); - concatStrings = builtins.concatStringsSep ""; - - # https://github.com/NixOS/nixpkgs/blob/8a9f58a375c401b96da862d969f66429def1d118/lib/attrsets.nix#L331 - optionalAttrs = cond: as: if cond then as else { }; - - # fetchTarball version that is compatible between all the versions of Nix - builtins_fetchTarball = { url, name ? null, sha256 }@attrs: - let - inherit (builtins) lessThan nixVersion fetchTarball; - in - if lessThan nixVersion "1.12" then - fetchTarball ({ inherit url; } // (optionalAttrs (name != null) { inherit name; })) - else - fetchTarball attrs; - - # fetchurl version that is compatible between all the versions of Nix - builtins_fetchurl = { url, name ? null, sha256 }@attrs: - let - inherit (builtins) lessThan nixVersion fetchurl; - in - if lessThan nixVersion "1.12" then - fetchurl ({ inherit url; } // (optionalAttrs (name != null) { inherit name; })) - else - fetchurl attrs; - - # Create the final "sources" from the config - mkSources = config: - mapAttrs - ( - name: spec: - if builtins.hasAttr "outPath" spec - then - abort - "The values in sources.json should not have an 'outPath' attribute" - else - spec // { outPath = replace name (fetch config.pkgs name spec); } - ) - config.sources; - - # The "config" used by the fetchers - mkConfig = - { sourcesFile ? if builtins.pathExists ./sources.json then ./sources.json else null - , sources ? if sourcesFile == null then { } else builtins.fromJSON (builtins.readFile sourcesFile) - , system ? builtins.currentSystem - , pkgs ? mkPkgs sources system - }: rec { - # The sources, i.e. the attribute set of spec name to spec - inherit sources; - - # The "pkgs" (evaluated nixpkgs) to use for e.g. non-builtin fetchers - inherit pkgs; - }; - -in -mkSources (mkConfig { }) // { __functor = _: settings: mkSources (mkConfig settings); } diff --git a/copilot-interpreter/default.nix b/copilot-interpreter/default.nix index b48893682..0e1b300e8 100644 --- a/copilot-interpreter/default.nix +++ b/copilot-interpreter/default.nix @@ -1,4 +1,4 @@ -{ sources ? import ./nix/sources.nix, ghc ? "ghc98" }: +{ sources ? import ../nix/sources.nix, ghc ? "ghc98" }: let depOverlay = n: o: { copilot-core = (import ../copilot-core { inherit sources ghc; }).copilot-core; diff --git a/copilot-interpreter/nix/sources.json b/copilot-interpreter/nix/sources.json deleted file mode 100644 index 7a59ceccc..000000000 --- a/copilot-interpreter/nix/sources.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "nixpkgs": { - "branch": "master", - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "63117158fe4f7f9b34eaecef088c417f8151e4ba", - "sha256": "sha256:036cjpfjghm6f8h4cldpv040kfvii7x8g5php4vyn9qmpncybxj6", - "type": "tarball", - "url": "https://github.com/NixOS/nixpkgs/archive/63117158fe4f7f9b34eaecef088c417f8151e4ba.tar.gz", - "url_template": "https://github.com///archive/.tar.gz" - } -} diff --git a/copilot-interpreter/nix/sources.nix b/copilot-interpreter/nix/sources.nix deleted file mode 100644 index fe3dadf7e..000000000 --- a/copilot-interpreter/nix/sources.nix +++ /dev/null @@ -1,198 +0,0 @@ -# This file has been generated by Niv. - -let - - # - # The fetchers. fetch_ fetches specs of type . - # - - fetch_file = pkgs: name: spec: - let - name' = sanitizeName name + "-src"; - in - if spec.builtin or true then - builtins_fetchurl { inherit (spec) url sha256; name = name'; } - else - pkgs.fetchurl { inherit (spec) url sha256; name = name'; }; - - fetch_tarball = pkgs: name: spec: - let - name' = sanitizeName name + "-src"; - in - if spec.builtin or true then - builtins_fetchTarball { name = name'; inherit (spec) url sha256; } - else - pkgs.fetchzip { name = name'; inherit (spec) url sha256; }; - - fetch_git = name: spec: - let - ref = - spec.ref or ( - if spec ? branch then "refs/heads/${spec.branch}" else - if spec ? tag then "refs/tags/${spec.tag}" else - abort "In git source '${name}': Please specify `ref`, `tag` or `branch`!" - ); - submodules = spec.submodules or false; - submoduleArg = - let - nixSupportsSubmodules = builtins.compareVersions builtins.nixVersion "2.4" >= 0; - emptyArgWithWarning = - if submodules - then - builtins.trace - ( - "The niv input \"${name}\" uses submodules " - + "but your nix's (${builtins.nixVersion}) builtins.fetchGit " - + "does not support them" - ) - { } - else { }; - in - if nixSupportsSubmodules - then { inherit submodules; } - else emptyArgWithWarning; - in - builtins.fetchGit - ({ url = spec.repo; inherit (spec) rev; inherit ref; } // submoduleArg); - - fetch_local = spec: spec.path; - - fetch_builtin-tarball = name: throw - ''[${name}] The niv type "builtin-tarball" is deprecated. You should instead use `builtin = true`. - $ niv modify ${name} -a type=tarball -a builtin=true''; - - fetch_builtin-url = name: throw - ''[${name}] The niv type "builtin-url" will soon be deprecated. You should instead use `builtin = true`. - $ niv modify ${name} -a type=file -a builtin=true''; - - # - # Various helpers - # - - # https://github.com/NixOS/nixpkgs/pull/83241/files#diff-c6f540a4f3bfa4b0e8b6bafd4cd54e8bR695 - sanitizeName = name: - ( - concatMapStrings (s: if builtins.isList s then "-" else s) - ( - builtins.split "[^[:alnum:]+._?=-]+" - ((x: builtins.elemAt (builtins.match "\\.*(.*)" x) 0) name) - ) - ); - - # The set of packages used when specs are fetched using non-builtins. - mkPkgs = sources: system: - let - sourcesNixpkgs = - import (builtins_fetchTarball { inherit (sources.nixpkgs) url sha256; }) { inherit system; }; - hasNixpkgsPath = builtins.any (x: x.prefix == "nixpkgs") builtins.nixPath; - hasThisAsNixpkgsPath = == ./.; - in - if builtins.hasAttr "nixpkgs" sources - then sourcesNixpkgs - else if hasNixpkgsPath && ! hasThisAsNixpkgsPath then - import { } - else - abort - '' - Please specify either (through -I or NIX_PATH=nixpkgs=...) or - add a package called "nixpkgs" to your sources.json. - ''; - - # The actual fetching function. - fetch = pkgs: name: spec: - - if ! builtins.hasAttr "type" spec then - abort "ERROR: niv spec ${name} does not have a 'type' attribute" - else if spec.type == "file" then fetch_file pkgs name spec - else if spec.type == "tarball" then fetch_tarball pkgs name spec - else if spec.type == "git" then fetch_git name spec - else if spec.type == "local" then fetch_local spec - else if spec.type == "builtin-tarball" then fetch_builtin-tarball name - else if spec.type == "builtin-url" then fetch_builtin-url name - else - abort "ERROR: niv spec ${name} has unknown type ${builtins.toJSON spec.type}"; - - # If the environment variable NIV_OVERRIDE_${name} is set, then use - # the path directly as opposed to the fetched source. - replace = name: drv: - let - saneName = stringAsChars (c: if (builtins.match "[a-zA-Z0-9]" c) == null then "_" else c) name; - ersatz = builtins.getEnv "NIV_OVERRIDE_${saneName}"; - in - if ersatz == "" then drv else - # this turns the string into an actual Nix path (for both absolute and - # relative paths) - if builtins.substring 0 1 ersatz == "/" then /. + ersatz else /. + builtins.getEnv "PWD" + "/${ersatz}"; - - # Ports of functions for older nix versions - - # a Nix version of mapAttrs if the built-in doesn't exist - mapAttrs = builtins.mapAttrs or ( - f: set: with builtins; - listToAttrs (map (attr: { name = attr; value = f attr set.${attr}; }) (attrNames set)) - ); - - # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/lists.nix#L295 - range = first: last: if first > last then [ ] else builtins.genList (n: first + n) (last - first + 1); - - # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/strings.nix#L257 - stringToCharacters = s: map (p: builtins.substring p 1 s) (range 0 (builtins.stringLength s - 1)); - - # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/strings.nix#L269 - stringAsChars = f: s: concatStrings (map f (stringToCharacters s)); - concatMapStrings = f: list: concatStrings (map f list); - concatStrings = builtins.concatStringsSep ""; - - # https://github.com/NixOS/nixpkgs/blob/8a9f58a375c401b96da862d969f66429def1d118/lib/attrsets.nix#L331 - optionalAttrs = cond: as: if cond then as else { }; - - # fetchTarball version that is compatible between all the versions of Nix - builtins_fetchTarball = { url, name ? null, sha256 }@attrs: - let - inherit (builtins) lessThan nixVersion fetchTarball; - in - if lessThan nixVersion "1.12" then - fetchTarball ({ inherit url; } // (optionalAttrs (name != null) { inherit name; })) - else - fetchTarball attrs; - - # fetchurl version that is compatible between all the versions of Nix - builtins_fetchurl = { url, name ? null, sha256 }@attrs: - let - inherit (builtins) lessThan nixVersion fetchurl; - in - if lessThan nixVersion "1.12" then - fetchurl ({ inherit url; } // (optionalAttrs (name != null) { inherit name; })) - else - fetchurl attrs; - - # Create the final "sources" from the config - mkSources = config: - mapAttrs - ( - name: spec: - if builtins.hasAttr "outPath" spec - then - abort - "The values in sources.json should not have an 'outPath' attribute" - else - spec // { outPath = replace name (fetch config.pkgs name spec); } - ) - config.sources; - - # The "config" used by the fetchers - mkConfig = - { sourcesFile ? if builtins.pathExists ./sources.json then ./sources.json else null - , sources ? if sourcesFile == null then { } else builtins.fromJSON (builtins.readFile sourcesFile) - , system ? builtins.currentSystem - , pkgs ? mkPkgs sources system - }: rec { - # The sources, i.e. the attribute set of spec name to spec - inherit sources; - - # The "pkgs" (evaluated nixpkgs) to use for e.g. non-builtin fetchers - inherit pkgs; - }; - -in -mkSources (mkConfig { }) // { __functor = _: settings: mkSources (mkConfig settings); } diff --git a/copilot-language/default.nix b/copilot-language/default.nix index d5edcbbb9..6524e8cb2 100644 --- a/copilot-language/default.nix +++ b/copilot-language/default.nix @@ -1,4 +1,4 @@ -{ sources ? import ./nix/sources.nix, ghc ? "ghc98" }: +{ sources ? import ../nix/sources.nix, ghc ? "ghc98" }: let depOverlay = n: o: { copilot-core = (import ../copilot-core { inherit sources ghc; }).copilot-core; diff --git a/copilot-language/nix/sources.json b/copilot-language/nix/sources.json deleted file mode 100644 index 7a59ceccc..000000000 --- a/copilot-language/nix/sources.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "nixpkgs": { - "branch": "master", - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "63117158fe4f7f9b34eaecef088c417f8151e4ba", - "sha256": "sha256:036cjpfjghm6f8h4cldpv040kfvii7x8g5php4vyn9qmpncybxj6", - "type": "tarball", - "url": "https://github.com/NixOS/nixpkgs/archive/63117158fe4f7f9b34eaecef088c417f8151e4ba.tar.gz", - "url_template": "https://github.com///archive/.tar.gz" - } -} diff --git a/copilot-language/nix/sources.nix b/copilot-language/nix/sources.nix deleted file mode 100644 index fe3dadf7e..000000000 --- a/copilot-language/nix/sources.nix +++ /dev/null @@ -1,198 +0,0 @@ -# This file has been generated by Niv. - -let - - # - # The fetchers. fetch_ fetches specs of type . - # - - fetch_file = pkgs: name: spec: - let - name' = sanitizeName name + "-src"; - in - if spec.builtin or true then - builtins_fetchurl { inherit (spec) url sha256; name = name'; } - else - pkgs.fetchurl { inherit (spec) url sha256; name = name'; }; - - fetch_tarball = pkgs: name: spec: - let - name' = sanitizeName name + "-src"; - in - if spec.builtin or true then - builtins_fetchTarball { name = name'; inherit (spec) url sha256; } - else - pkgs.fetchzip { name = name'; inherit (spec) url sha256; }; - - fetch_git = name: spec: - let - ref = - spec.ref or ( - if spec ? branch then "refs/heads/${spec.branch}" else - if spec ? tag then "refs/tags/${spec.tag}" else - abort "In git source '${name}': Please specify `ref`, `tag` or `branch`!" - ); - submodules = spec.submodules or false; - submoduleArg = - let - nixSupportsSubmodules = builtins.compareVersions builtins.nixVersion "2.4" >= 0; - emptyArgWithWarning = - if submodules - then - builtins.trace - ( - "The niv input \"${name}\" uses submodules " - + "but your nix's (${builtins.nixVersion}) builtins.fetchGit " - + "does not support them" - ) - { } - else { }; - in - if nixSupportsSubmodules - then { inherit submodules; } - else emptyArgWithWarning; - in - builtins.fetchGit - ({ url = spec.repo; inherit (spec) rev; inherit ref; } // submoduleArg); - - fetch_local = spec: spec.path; - - fetch_builtin-tarball = name: throw - ''[${name}] The niv type "builtin-tarball" is deprecated. You should instead use `builtin = true`. - $ niv modify ${name} -a type=tarball -a builtin=true''; - - fetch_builtin-url = name: throw - ''[${name}] The niv type "builtin-url" will soon be deprecated. You should instead use `builtin = true`. - $ niv modify ${name} -a type=file -a builtin=true''; - - # - # Various helpers - # - - # https://github.com/NixOS/nixpkgs/pull/83241/files#diff-c6f540a4f3bfa4b0e8b6bafd4cd54e8bR695 - sanitizeName = name: - ( - concatMapStrings (s: if builtins.isList s then "-" else s) - ( - builtins.split "[^[:alnum:]+._?=-]+" - ((x: builtins.elemAt (builtins.match "\\.*(.*)" x) 0) name) - ) - ); - - # The set of packages used when specs are fetched using non-builtins. - mkPkgs = sources: system: - let - sourcesNixpkgs = - import (builtins_fetchTarball { inherit (sources.nixpkgs) url sha256; }) { inherit system; }; - hasNixpkgsPath = builtins.any (x: x.prefix == "nixpkgs") builtins.nixPath; - hasThisAsNixpkgsPath = == ./.; - in - if builtins.hasAttr "nixpkgs" sources - then sourcesNixpkgs - else if hasNixpkgsPath && ! hasThisAsNixpkgsPath then - import { } - else - abort - '' - Please specify either (through -I or NIX_PATH=nixpkgs=...) or - add a package called "nixpkgs" to your sources.json. - ''; - - # The actual fetching function. - fetch = pkgs: name: spec: - - if ! builtins.hasAttr "type" spec then - abort "ERROR: niv spec ${name} does not have a 'type' attribute" - else if spec.type == "file" then fetch_file pkgs name spec - else if spec.type == "tarball" then fetch_tarball pkgs name spec - else if spec.type == "git" then fetch_git name spec - else if spec.type == "local" then fetch_local spec - else if spec.type == "builtin-tarball" then fetch_builtin-tarball name - else if spec.type == "builtin-url" then fetch_builtin-url name - else - abort "ERROR: niv spec ${name} has unknown type ${builtins.toJSON spec.type}"; - - # If the environment variable NIV_OVERRIDE_${name} is set, then use - # the path directly as opposed to the fetched source. - replace = name: drv: - let - saneName = stringAsChars (c: if (builtins.match "[a-zA-Z0-9]" c) == null then "_" else c) name; - ersatz = builtins.getEnv "NIV_OVERRIDE_${saneName}"; - in - if ersatz == "" then drv else - # this turns the string into an actual Nix path (for both absolute and - # relative paths) - if builtins.substring 0 1 ersatz == "/" then /. + ersatz else /. + builtins.getEnv "PWD" + "/${ersatz}"; - - # Ports of functions for older nix versions - - # a Nix version of mapAttrs if the built-in doesn't exist - mapAttrs = builtins.mapAttrs or ( - f: set: with builtins; - listToAttrs (map (attr: { name = attr; value = f attr set.${attr}; }) (attrNames set)) - ); - - # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/lists.nix#L295 - range = first: last: if first > last then [ ] else builtins.genList (n: first + n) (last - first + 1); - - # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/strings.nix#L257 - stringToCharacters = s: map (p: builtins.substring p 1 s) (range 0 (builtins.stringLength s - 1)); - - # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/strings.nix#L269 - stringAsChars = f: s: concatStrings (map f (stringToCharacters s)); - concatMapStrings = f: list: concatStrings (map f list); - concatStrings = builtins.concatStringsSep ""; - - # https://github.com/NixOS/nixpkgs/blob/8a9f58a375c401b96da862d969f66429def1d118/lib/attrsets.nix#L331 - optionalAttrs = cond: as: if cond then as else { }; - - # fetchTarball version that is compatible between all the versions of Nix - builtins_fetchTarball = { url, name ? null, sha256 }@attrs: - let - inherit (builtins) lessThan nixVersion fetchTarball; - in - if lessThan nixVersion "1.12" then - fetchTarball ({ inherit url; } // (optionalAttrs (name != null) { inherit name; })) - else - fetchTarball attrs; - - # fetchurl version that is compatible between all the versions of Nix - builtins_fetchurl = { url, name ? null, sha256 }@attrs: - let - inherit (builtins) lessThan nixVersion fetchurl; - in - if lessThan nixVersion "1.12" then - fetchurl ({ inherit url; } // (optionalAttrs (name != null) { inherit name; })) - else - fetchurl attrs; - - # Create the final "sources" from the config - mkSources = config: - mapAttrs - ( - name: spec: - if builtins.hasAttr "outPath" spec - then - abort - "The values in sources.json should not have an 'outPath' attribute" - else - spec // { outPath = replace name (fetch config.pkgs name spec); } - ) - config.sources; - - # The "config" used by the fetchers - mkConfig = - { sourcesFile ? if builtins.pathExists ./sources.json then ./sources.json else null - , sources ? if sourcesFile == null then { } else builtins.fromJSON (builtins.readFile sourcesFile) - , system ? builtins.currentSystem - , pkgs ? mkPkgs sources system - }: rec { - # The sources, i.e. the attribute set of spec name to spec - inherit sources; - - # The "pkgs" (evaluated nixpkgs) to use for e.g. non-builtin fetchers - inherit pkgs; - }; - -in -mkSources (mkConfig { }) // { __functor = _: settings: mkSources (mkConfig settings); } diff --git a/copilot-libraries/default.nix b/copilot-libraries/default.nix index 631419be9..33886020b 100644 --- a/copilot-libraries/default.nix +++ b/copilot-libraries/default.nix @@ -1,4 +1,4 @@ -{ sources ? import ./nix/sources.nix, ghc ? "ghc98" }: +{ sources ? import ../nix/sources.nix, ghc ? "ghc98" }: let depOverlay = n: o: { copilot-language = (import ../copilot-language { inherit sources ghc; }).copilot-language; diff --git a/copilot-libraries/nix/sources.json b/copilot-libraries/nix/sources.json deleted file mode 100644 index 7a59ceccc..000000000 --- a/copilot-libraries/nix/sources.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "nixpkgs": { - "branch": "master", - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "63117158fe4f7f9b34eaecef088c417f8151e4ba", - "sha256": "sha256:036cjpfjghm6f8h4cldpv040kfvii7x8g5php4vyn9qmpncybxj6", - "type": "tarball", - "url": "https://github.com/NixOS/nixpkgs/archive/63117158fe4f7f9b34eaecef088c417f8151e4ba.tar.gz", - "url_template": "https://github.com///archive/.tar.gz" - } -} diff --git a/copilot-libraries/nix/sources.nix b/copilot-libraries/nix/sources.nix deleted file mode 100644 index fe3dadf7e..000000000 --- a/copilot-libraries/nix/sources.nix +++ /dev/null @@ -1,198 +0,0 @@ -# This file has been generated by Niv. - -let - - # - # The fetchers. fetch_ fetches specs of type . - # - - fetch_file = pkgs: name: spec: - let - name' = sanitizeName name + "-src"; - in - if spec.builtin or true then - builtins_fetchurl { inherit (spec) url sha256; name = name'; } - else - pkgs.fetchurl { inherit (spec) url sha256; name = name'; }; - - fetch_tarball = pkgs: name: spec: - let - name' = sanitizeName name + "-src"; - in - if spec.builtin or true then - builtins_fetchTarball { name = name'; inherit (spec) url sha256; } - else - pkgs.fetchzip { name = name'; inherit (spec) url sha256; }; - - fetch_git = name: spec: - let - ref = - spec.ref or ( - if spec ? branch then "refs/heads/${spec.branch}" else - if spec ? tag then "refs/tags/${spec.tag}" else - abort "In git source '${name}': Please specify `ref`, `tag` or `branch`!" - ); - submodules = spec.submodules or false; - submoduleArg = - let - nixSupportsSubmodules = builtins.compareVersions builtins.nixVersion "2.4" >= 0; - emptyArgWithWarning = - if submodules - then - builtins.trace - ( - "The niv input \"${name}\" uses submodules " - + "but your nix's (${builtins.nixVersion}) builtins.fetchGit " - + "does not support them" - ) - { } - else { }; - in - if nixSupportsSubmodules - then { inherit submodules; } - else emptyArgWithWarning; - in - builtins.fetchGit - ({ url = spec.repo; inherit (spec) rev; inherit ref; } // submoduleArg); - - fetch_local = spec: spec.path; - - fetch_builtin-tarball = name: throw - ''[${name}] The niv type "builtin-tarball" is deprecated. You should instead use `builtin = true`. - $ niv modify ${name} -a type=tarball -a builtin=true''; - - fetch_builtin-url = name: throw - ''[${name}] The niv type "builtin-url" will soon be deprecated. You should instead use `builtin = true`. - $ niv modify ${name} -a type=file -a builtin=true''; - - # - # Various helpers - # - - # https://github.com/NixOS/nixpkgs/pull/83241/files#diff-c6f540a4f3bfa4b0e8b6bafd4cd54e8bR695 - sanitizeName = name: - ( - concatMapStrings (s: if builtins.isList s then "-" else s) - ( - builtins.split "[^[:alnum:]+._?=-]+" - ((x: builtins.elemAt (builtins.match "\\.*(.*)" x) 0) name) - ) - ); - - # The set of packages used when specs are fetched using non-builtins. - mkPkgs = sources: system: - let - sourcesNixpkgs = - import (builtins_fetchTarball { inherit (sources.nixpkgs) url sha256; }) { inherit system; }; - hasNixpkgsPath = builtins.any (x: x.prefix == "nixpkgs") builtins.nixPath; - hasThisAsNixpkgsPath = == ./.; - in - if builtins.hasAttr "nixpkgs" sources - then sourcesNixpkgs - else if hasNixpkgsPath && ! hasThisAsNixpkgsPath then - import { } - else - abort - '' - Please specify either (through -I or NIX_PATH=nixpkgs=...) or - add a package called "nixpkgs" to your sources.json. - ''; - - # The actual fetching function. - fetch = pkgs: name: spec: - - if ! builtins.hasAttr "type" spec then - abort "ERROR: niv spec ${name} does not have a 'type' attribute" - else if spec.type == "file" then fetch_file pkgs name spec - else if spec.type == "tarball" then fetch_tarball pkgs name spec - else if spec.type == "git" then fetch_git name spec - else if spec.type == "local" then fetch_local spec - else if spec.type == "builtin-tarball" then fetch_builtin-tarball name - else if spec.type == "builtin-url" then fetch_builtin-url name - else - abort "ERROR: niv spec ${name} has unknown type ${builtins.toJSON spec.type}"; - - # If the environment variable NIV_OVERRIDE_${name} is set, then use - # the path directly as opposed to the fetched source. - replace = name: drv: - let - saneName = stringAsChars (c: if (builtins.match "[a-zA-Z0-9]" c) == null then "_" else c) name; - ersatz = builtins.getEnv "NIV_OVERRIDE_${saneName}"; - in - if ersatz == "" then drv else - # this turns the string into an actual Nix path (for both absolute and - # relative paths) - if builtins.substring 0 1 ersatz == "/" then /. + ersatz else /. + builtins.getEnv "PWD" + "/${ersatz}"; - - # Ports of functions for older nix versions - - # a Nix version of mapAttrs if the built-in doesn't exist - mapAttrs = builtins.mapAttrs or ( - f: set: with builtins; - listToAttrs (map (attr: { name = attr; value = f attr set.${attr}; }) (attrNames set)) - ); - - # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/lists.nix#L295 - range = first: last: if first > last then [ ] else builtins.genList (n: first + n) (last - first + 1); - - # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/strings.nix#L257 - stringToCharacters = s: map (p: builtins.substring p 1 s) (range 0 (builtins.stringLength s - 1)); - - # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/strings.nix#L269 - stringAsChars = f: s: concatStrings (map f (stringToCharacters s)); - concatMapStrings = f: list: concatStrings (map f list); - concatStrings = builtins.concatStringsSep ""; - - # https://github.com/NixOS/nixpkgs/blob/8a9f58a375c401b96da862d969f66429def1d118/lib/attrsets.nix#L331 - optionalAttrs = cond: as: if cond then as else { }; - - # fetchTarball version that is compatible between all the versions of Nix - builtins_fetchTarball = { url, name ? null, sha256 }@attrs: - let - inherit (builtins) lessThan nixVersion fetchTarball; - in - if lessThan nixVersion "1.12" then - fetchTarball ({ inherit url; } // (optionalAttrs (name != null) { inherit name; })) - else - fetchTarball attrs; - - # fetchurl version that is compatible between all the versions of Nix - builtins_fetchurl = { url, name ? null, sha256 }@attrs: - let - inherit (builtins) lessThan nixVersion fetchurl; - in - if lessThan nixVersion "1.12" then - fetchurl ({ inherit url; } // (optionalAttrs (name != null) { inherit name; })) - else - fetchurl attrs; - - # Create the final "sources" from the config - mkSources = config: - mapAttrs - ( - name: spec: - if builtins.hasAttr "outPath" spec - then - abort - "The values in sources.json should not have an 'outPath' attribute" - else - spec // { outPath = replace name (fetch config.pkgs name spec); } - ) - config.sources; - - # The "config" used by the fetchers - mkConfig = - { sourcesFile ? if builtins.pathExists ./sources.json then ./sources.json else null - , sources ? if sourcesFile == null then { } else builtins.fromJSON (builtins.readFile sourcesFile) - , system ? builtins.currentSystem - , pkgs ? mkPkgs sources system - }: rec { - # The sources, i.e. the attribute set of spec name to spec - inherit sources; - - # The "pkgs" (evaluated nixpkgs) to use for e.g. non-builtin fetchers - inherit pkgs; - }; - -in -mkSources (mkConfig { }) // { __functor = _: settings: mkSources (mkConfig settings); } diff --git a/copilot-prettyprinter/default.nix b/copilot-prettyprinter/default.nix index b8d08f22b..753ec1bff 100644 --- a/copilot-prettyprinter/default.nix +++ b/copilot-prettyprinter/default.nix @@ -1,4 +1,4 @@ -{ sources ? import ./nix/sources.nix, ghc ? "ghc98" }: +{ sources ? import ../nix/sources.nix, ghc ? "ghc98" }: let depOverlay = n: o: { copilot-core = (import ../copilot-core { inherit sources ghc; }).copilot-core; diff --git a/copilot-prettyprinter/nix/sources.json b/copilot-prettyprinter/nix/sources.json deleted file mode 100644 index 7a59ceccc..000000000 --- a/copilot-prettyprinter/nix/sources.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "nixpkgs": { - "branch": "master", - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "63117158fe4f7f9b34eaecef088c417f8151e4ba", - "sha256": "sha256:036cjpfjghm6f8h4cldpv040kfvii7x8g5php4vyn9qmpncybxj6", - "type": "tarball", - "url": "https://github.com/NixOS/nixpkgs/archive/63117158fe4f7f9b34eaecef088c417f8151e4ba.tar.gz", - "url_template": "https://github.com///archive/.tar.gz" - } -} diff --git a/copilot-prettyprinter/nix/sources.nix b/copilot-prettyprinter/nix/sources.nix deleted file mode 100644 index fe3dadf7e..000000000 --- a/copilot-prettyprinter/nix/sources.nix +++ /dev/null @@ -1,198 +0,0 @@ -# This file has been generated by Niv. - -let - - # - # The fetchers. fetch_ fetches specs of type . - # - - fetch_file = pkgs: name: spec: - let - name' = sanitizeName name + "-src"; - in - if spec.builtin or true then - builtins_fetchurl { inherit (spec) url sha256; name = name'; } - else - pkgs.fetchurl { inherit (spec) url sha256; name = name'; }; - - fetch_tarball = pkgs: name: spec: - let - name' = sanitizeName name + "-src"; - in - if spec.builtin or true then - builtins_fetchTarball { name = name'; inherit (spec) url sha256; } - else - pkgs.fetchzip { name = name'; inherit (spec) url sha256; }; - - fetch_git = name: spec: - let - ref = - spec.ref or ( - if spec ? branch then "refs/heads/${spec.branch}" else - if spec ? tag then "refs/tags/${spec.tag}" else - abort "In git source '${name}': Please specify `ref`, `tag` or `branch`!" - ); - submodules = spec.submodules or false; - submoduleArg = - let - nixSupportsSubmodules = builtins.compareVersions builtins.nixVersion "2.4" >= 0; - emptyArgWithWarning = - if submodules - then - builtins.trace - ( - "The niv input \"${name}\" uses submodules " - + "but your nix's (${builtins.nixVersion}) builtins.fetchGit " - + "does not support them" - ) - { } - else { }; - in - if nixSupportsSubmodules - then { inherit submodules; } - else emptyArgWithWarning; - in - builtins.fetchGit - ({ url = spec.repo; inherit (spec) rev; inherit ref; } // submoduleArg); - - fetch_local = spec: spec.path; - - fetch_builtin-tarball = name: throw - ''[${name}] The niv type "builtin-tarball" is deprecated. You should instead use `builtin = true`. - $ niv modify ${name} -a type=tarball -a builtin=true''; - - fetch_builtin-url = name: throw - ''[${name}] The niv type "builtin-url" will soon be deprecated. You should instead use `builtin = true`. - $ niv modify ${name} -a type=file -a builtin=true''; - - # - # Various helpers - # - - # https://github.com/NixOS/nixpkgs/pull/83241/files#diff-c6f540a4f3bfa4b0e8b6bafd4cd54e8bR695 - sanitizeName = name: - ( - concatMapStrings (s: if builtins.isList s then "-" else s) - ( - builtins.split "[^[:alnum:]+._?=-]+" - ((x: builtins.elemAt (builtins.match "\\.*(.*)" x) 0) name) - ) - ); - - # The set of packages used when specs are fetched using non-builtins. - mkPkgs = sources: system: - let - sourcesNixpkgs = - import (builtins_fetchTarball { inherit (sources.nixpkgs) url sha256; }) { inherit system; }; - hasNixpkgsPath = builtins.any (x: x.prefix == "nixpkgs") builtins.nixPath; - hasThisAsNixpkgsPath = == ./.; - in - if builtins.hasAttr "nixpkgs" sources - then sourcesNixpkgs - else if hasNixpkgsPath && ! hasThisAsNixpkgsPath then - import { } - else - abort - '' - Please specify either (through -I or NIX_PATH=nixpkgs=...) or - add a package called "nixpkgs" to your sources.json. - ''; - - # The actual fetching function. - fetch = pkgs: name: spec: - - if ! builtins.hasAttr "type" spec then - abort "ERROR: niv spec ${name} does not have a 'type' attribute" - else if spec.type == "file" then fetch_file pkgs name spec - else if spec.type == "tarball" then fetch_tarball pkgs name spec - else if spec.type == "git" then fetch_git name spec - else if spec.type == "local" then fetch_local spec - else if spec.type == "builtin-tarball" then fetch_builtin-tarball name - else if spec.type == "builtin-url" then fetch_builtin-url name - else - abort "ERROR: niv spec ${name} has unknown type ${builtins.toJSON spec.type}"; - - # If the environment variable NIV_OVERRIDE_${name} is set, then use - # the path directly as opposed to the fetched source. - replace = name: drv: - let - saneName = stringAsChars (c: if (builtins.match "[a-zA-Z0-9]" c) == null then "_" else c) name; - ersatz = builtins.getEnv "NIV_OVERRIDE_${saneName}"; - in - if ersatz == "" then drv else - # this turns the string into an actual Nix path (for both absolute and - # relative paths) - if builtins.substring 0 1 ersatz == "/" then /. + ersatz else /. + builtins.getEnv "PWD" + "/${ersatz}"; - - # Ports of functions for older nix versions - - # a Nix version of mapAttrs if the built-in doesn't exist - mapAttrs = builtins.mapAttrs or ( - f: set: with builtins; - listToAttrs (map (attr: { name = attr; value = f attr set.${attr}; }) (attrNames set)) - ); - - # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/lists.nix#L295 - range = first: last: if first > last then [ ] else builtins.genList (n: first + n) (last - first + 1); - - # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/strings.nix#L257 - stringToCharacters = s: map (p: builtins.substring p 1 s) (range 0 (builtins.stringLength s - 1)); - - # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/strings.nix#L269 - stringAsChars = f: s: concatStrings (map f (stringToCharacters s)); - concatMapStrings = f: list: concatStrings (map f list); - concatStrings = builtins.concatStringsSep ""; - - # https://github.com/NixOS/nixpkgs/blob/8a9f58a375c401b96da862d969f66429def1d118/lib/attrsets.nix#L331 - optionalAttrs = cond: as: if cond then as else { }; - - # fetchTarball version that is compatible between all the versions of Nix - builtins_fetchTarball = { url, name ? null, sha256 }@attrs: - let - inherit (builtins) lessThan nixVersion fetchTarball; - in - if lessThan nixVersion "1.12" then - fetchTarball ({ inherit url; } // (optionalAttrs (name != null) { inherit name; })) - else - fetchTarball attrs; - - # fetchurl version that is compatible between all the versions of Nix - builtins_fetchurl = { url, name ? null, sha256 }@attrs: - let - inherit (builtins) lessThan nixVersion fetchurl; - in - if lessThan nixVersion "1.12" then - fetchurl ({ inherit url; } // (optionalAttrs (name != null) { inherit name; })) - else - fetchurl attrs; - - # Create the final "sources" from the config - mkSources = config: - mapAttrs - ( - name: spec: - if builtins.hasAttr "outPath" spec - then - abort - "The values in sources.json should not have an 'outPath' attribute" - else - spec // { outPath = replace name (fetch config.pkgs name spec); } - ) - config.sources; - - # The "config" used by the fetchers - mkConfig = - { sourcesFile ? if builtins.pathExists ./sources.json then ./sources.json else null - , sources ? if sourcesFile == null then { } else builtins.fromJSON (builtins.readFile sourcesFile) - , system ? builtins.currentSystem - , pkgs ? mkPkgs sources system - }: rec { - # The sources, i.e. the attribute set of spec name to spec - inherit sources; - - # The "pkgs" (evaluated nixpkgs) to use for e.g. non-builtin fetchers - inherit pkgs; - }; - -in -mkSources (mkConfig { }) // { __functor = _: settings: mkSources (mkConfig settings); } diff --git a/copilot-theorem/default.nix b/copilot-theorem/default.nix index cb4caf650..493260e3c 100644 --- a/copilot-theorem/default.nix +++ b/copilot-theorem/default.nix @@ -1,4 +1,4 @@ -{ sources ? import ./nix/sources.nix, ghc ? "ghc98" }: +{ sources ? import ../nix/sources.nix, ghc ? "ghc98" }: let depOverlay = n: o: { copilot-core = (import ../copilot-core { inherit sources ghc; }).copilot-core; diff --git a/copilot-theorem/nix/sources.json b/copilot-theorem/nix/sources.json deleted file mode 100644 index 7a59ceccc..000000000 --- a/copilot-theorem/nix/sources.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "nixpkgs": { - "branch": "master", - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "63117158fe4f7f9b34eaecef088c417f8151e4ba", - "sha256": "sha256:036cjpfjghm6f8h4cldpv040kfvii7x8g5php4vyn9qmpncybxj6", - "type": "tarball", - "url": "https://github.com/NixOS/nixpkgs/archive/63117158fe4f7f9b34eaecef088c417f8151e4ba.tar.gz", - "url_template": "https://github.com///archive/.tar.gz" - } -} diff --git a/copilot-theorem/nix/sources.nix b/copilot-theorem/nix/sources.nix deleted file mode 100644 index fe3dadf7e..000000000 --- a/copilot-theorem/nix/sources.nix +++ /dev/null @@ -1,198 +0,0 @@ -# This file has been generated by Niv. - -let - - # - # The fetchers. fetch_ fetches specs of type . - # - - fetch_file = pkgs: name: spec: - let - name' = sanitizeName name + "-src"; - in - if spec.builtin or true then - builtins_fetchurl { inherit (spec) url sha256; name = name'; } - else - pkgs.fetchurl { inherit (spec) url sha256; name = name'; }; - - fetch_tarball = pkgs: name: spec: - let - name' = sanitizeName name + "-src"; - in - if spec.builtin or true then - builtins_fetchTarball { name = name'; inherit (spec) url sha256; } - else - pkgs.fetchzip { name = name'; inherit (spec) url sha256; }; - - fetch_git = name: spec: - let - ref = - spec.ref or ( - if spec ? branch then "refs/heads/${spec.branch}" else - if spec ? tag then "refs/tags/${spec.tag}" else - abort "In git source '${name}': Please specify `ref`, `tag` or `branch`!" - ); - submodules = spec.submodules or false; - submoduleArg = - let - nixSupportsSubmodules = builtins.compareVersions builtins.nixVersion "2.4" >= 0; - emptyArgWithWarning = - if submodules - then - builtins.trace - ( - "The niv input \"${name}\" uses submodules " - + "but your nix's (${builtins.nixVersion}) builtins.fetchGit " - + "does not support them" - ) - { } - else { }; - in - if nixSupportsSubmodules - then { inherit submodules; } - else emptyArgWithWarning; - in - builtins.fetchGit - ({ url = spec.repo; inherit (spec) rev; inherit ref; } // submoduleArg); - - fetch_local = spec: spec.path; - - fetch_builtin-tarball = name: throw - ''[${name}] The niv type "builtin-tarball" is deprecated. You should instead use `builtin = true`. - $ niv modify ${name} -a type=tarball -a builtin=true''; - - fetch_builtin-url = name: throw - ''[${name}] The niv type "builtin-url" will soon be deprecated. You should instead use `builtin = true`. - $ niv modify ${name} -a type=file -a builtin=true''; - - # - # Various helpers - # - - # https://github.com/NixOS/nixpkgs/pull/83241/files#diff-c6f540a4f3bfa4b0e8b6bafd4cd54e8bR695 - sanitizeName = name: - ( - concatMapStrings (s: if builtins.isList s then "-" else s) - ( - builtins.split "[^[:alnum:]+._?=-]+" - ((x: builtins.elemAt (builtins.match "\\.*(.*)" x) 0) name) - ) - ); - - # The set of packages used when specs are fetched using non-builtins. - mkPkgs = sources: system: - let - sourcesNixpkgs = - import (builtins_fetchTarball { inherit (sources.nixpkgs) url sha256; }) { inherit system; }; - hasNixpkgsPath = builtins.any (x: x.prefix == "nixpkgs") builtins.nixPath; - hasThisAsNixpkgsPath = == ./.; - in - if builtins.hasAttr "nixpkgs" sources - then sourcesNixpkgs - else if hasNixpkgsPath && ! hasThisAsNixpkgsPath then - import { } - else - abort - '' - Please specify either (through -I or NIX_PATH=nixpkgs=...) or - add a package called "nixpkgs" to your sources.json. - ''; - - # The actual fetching function. - fetch = pkgs: name: spec: - - if ! builtins.hasAttr "type" spec then - abort "ERROR: niv spec ${name} does not have a 'type' attribute" - else if spec.type == "file" then fetch_file pkgs name spec - else if spec.type == "tarball" then fetch_tarball pkgs name spec - else if spec.type == "git" then fetch_git name spec - else if spec.type == "local" then fetch_local spec - else if spec.type == "builtin-tarball" then fetch_builtin-tarball name - else if spec.type == "builtin-url" then fetch_builtin-url name - else - abort "ERROR: niv spec ${name} has unknown type ${builtins.toJSON spec.type}"; - - # If the environment variable NIV_OVERRIDE_${name} is set, then use - # the path directly as opposed to the fetched source. - replace = name: drv: - let - saneName = stringAsChars (c: if (builtins.match "[a-zA-Z0-9]" c) == null then "_" else c) name; - ersatz = builtins.getEnv "NIV_OVERRIDE_${saneName}"; - in - if ersatz == "" then drv else - # this turns the string into an actual Nix path (for both absolute and - # relative paths) - if builtins.substring 0 1 ersatz == "/" then /. + ersatz else /. + builtins.getEnv "PWD" + "/${ersatz}"; - - # Ports of functions for older nix versions - - # a Nix version of mapAttrs if the built-in doesn't exist - mapAttrs = builtins.mapAttrs or ( - f: set: with builtins; - listToAttrs (map (attr: { name = attr; value = f attr set.${attr}; }) (attrNames set)) - ); - - # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/lists.nix#L295 - range = first: last: if first > last then [ ] else builtins.genList (n: first + n) (last - first + 1); - - # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/strings.nix#L257 - stringToCharacters = s: map (p: builtins.substring p 1 s) (range 0 (builtins.stringLength s - 1)); - - # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/strings.nix#L269 - stringAsChars = f: s: concatStrings (map f (stringToCharacters s)); - concatMapStrings = f: list: concatStrings (map f list); - concatStrings = builtins.concatStringsSep ""; - - # https://github.com/NixOS/nixpkgs/blob/8a9f58a375c401b96da862d969f66429def1d118/lib/attrsets.nix#L331 - optionalAttrs = cond: as: if cond then as else { }; - - # fetchTarball version that is compatible between all the versions of Nix - builtins_fetchTarball = { url, name ? null, sha256 }@attrs: - let - inherit (builtins) lessThan nixVersion fetchTarball; - in - if lessThan nixVersion "1.12" then - fetchTarball ({ inherit url; } // (optionalAttrs (name != null) { inherit name; })) - else - fetchTarball attrs; - - # fetchurl version that is compatible between all the versions of Nix - builtins_fetchurl = { url, name ? null, sha256 }@attrs: - let - inherit (builtins) lessThan nixVersion fetchurl; - in - if lessThan nixVersion "1.12" then - fetchurl ({ inherit url; } // (optionalAttrs (name != null) { inherit name; })) - else - fetchurl attrs; - - # Create the final "sources" from the config - mkSources = config: - mapAttrs - ( - name: spec: - if builtins.hasAttr "outPath" spec - then - abort - "The values in sources.json should not have an 'outPath' attribute" - else - spec // { outPath = replace name (fetch config.pkgs name spec); } - ) - config.sources; - - # The "config" used by the fetchers - mkConfig = - { sourcesFile ? if builtins.pathExists ./sources.json then ./sources.json else null - , sources ? if sourcesFile == null then { } else builtins.fromJSON (builtins.readFile sourcesFile) - , system ? builtins.currentSystem - , pkgs ? mkPkgs sources system - }: rec { - # The sources, i.e. the attribute set of spec name to spec - inherit sources; - - # The "pkgs" (evaluated nixpkgs) to use for e.g. non-builtin fetchers - inherit pkgs; - }; - -in -mkSources (mkConfig { }) // { __functor = _: settings: mkSources (mkConfig settings); } diff --git a/copilot-verifier/default.nix b/copilot-verifier/default.nix index b25b09c76..5796d0dab 100644 --- a/copilot-verifier/default.nix +++ b/copilot-verifier/default.nix @@ -1,4 +1,4 @@ -{ sources ? import ./nix/sources.nix, ghc ? "ghc98" }: +{ sources ? import ../nix/sources.nix, ghc ? "ghc98" }: let depOverlay = n: o: { copilot = (import ../copilot { inherit sources ghc; }).copilot; diff --git a/copilot-verifier/nix/sources.nix b/copilot-verifier/nix/sources.nix deleted file mode 100644 index fe3dadf7e..000000000 --- a/copilot-verifier/nix/sources.nix +++ /dev/null @@ -1,198 +0,0 @@ -# This file has been generated by Niv. - -let - - # - # The fetchers. fetch_ fetches specs of type . - # - - fetch_file = pkgs: name: spec: - let - name' = sanitizeName name + "-src"; - in - if spec.builtin or true then - builtins_fetchurl { inherit (spec) url sha256; name = name'; } - else - pkgs.fetchurl { inherit (spec) url sha256; name = name'; }; - - fetch_tarball = pkgs: name: spec: - let - name' = sanitizeName name + "-src"; - in - if spec.builtin or true then - builtins_fetchTarball { name = name'; inherit (spec) url sha256; } - else - pkgs.fetchzip { name = name'; inherit (spec) url sha256; }; - - fetch_git = name: spec: - let - ref = - spec.ref or ( - if spec ? branch then "refs/heads/${spec.branch}" else - if spec ? tag then "refs/tags/${spec.tag}" else - abort "In git source '${name}': Please specify `ref`, `tag` or `branch`!" - ); - submodules = spec.submodules or false; - submoduleArg = - let - nixSupportsSubmodules = builtins.compareVersions builtins.nixVersion "2.4" >= 0; - emptyArgWithWarning = - if submodules - then - builtins.trace - ( - "The niv input \"${name}\" uses submodules " - + "but your nix's (${builtins.nixVersion}) builtins.fetchGit " - + "does not support them" - ) - { } - else { }; - in - if nixSupportsSubmodules - then { inherit submodules; } - else emptyArgWithWarning; - in - builtins.fetchGit - ({ url = spec.repo; inherit (spec) rev; inherit ref; } // submoduleArg); - - fetch_local = spec: spec.path; - - fetch_builtin-tarball = name: throw - ''[${name}] The niv type "builtin-tarball" is deprecated. You should instead use `builtin = true`. - $ niv modify ${name} -a type=tarball -a builtin=true''; - - fetch_builtin-url = name: throw - ''[${name}] The niv type "builtin-url" will soon be deprecated. You should instead use `builtin = true`. - $ niv modify ${name} -a type=file -a builtin=true''; - - # - # Various helpers - # - - # https://github.com/NixOS/nixpkgs/pull/83241/files#diff-c6f540a4f3bfa4b0e8b6bafd4cd54e8bR695 - sanitizeName = name: - ( - concatMapStrings (s: if builtins.isList s then "-" else s) - ( - builtins.split "[^[:alnum:]+._?=-]+" - ((x: builtins.elemAt (builtins.match "\\.*(.*)" x) 0) name) - ) - ); - - # The set of packages used when specs are fetched using non-builtins. - mkPkgs = sources: system: - let - sourcesNixpkgs = - import (builtins_fetchTarball { inherit (sources.nixpkgs) url sha256; }) { inherit system; }; - hasNixpkgsPath = builtins.any (x: x.prefix == "nixpkgs") builtins.nixPath; - hasThisAsNixpkgsPath = == ./.; - in - if builtins.hasAttr "nixpkgs" sources - then sourcesNixpkgs - else if hasNixpkgsPath && ! hasThisAsNixpkgsPath then - import { } - else - abort - '' - Please specify either (through -I or NIX_PATH=nixpkgs=...) or - add a package called "nixpkgs" to your sources.json. - ''; - - # The actual fetching function. - fetch = pkgs: name: spec: - - if ! builtins.hasAttr "type" spec then - abort "ERROR: niv spec ${name} does not have a 'type' attribute" - else if spec.type == "file" then fetch_file pkgs name spec - else if spec.type == "tarball" then fetch_tarball pkgs name spec - else if spec.type == "git" then fetch_git name spec - else if spec.type == "local" then fetch_local spec - else if spec.type == "builtin-tarball" then fetch_builtin-tarball name - else if spec.type == "builtin-url" then fetch_builtin-url name - else - abort "ERROR: niv spec ${name} has unknown type ${builtins.toJSON spec.type}"; - - # If the environment variable NIV_OVERRIDE_${name} is set, then use - # the path directly as opposed to the fetched source. - replace = name: drv: - let - saneName = stringAsChars (c: if (builtins.match "[a-zA-Z0-9]" c) == null then "_" else c) name; - ersatz = builtins.getEnv "NIV_OVERRIDE_${saneName}"; - in - if ersatz == "" then drv else - # this turns the string into an actual Nix path (for both absolute and - # relative paths) - if builtins.substring 0 1 ersatz == "/" then /. + ersatz else /. + builtins.getEnv "PWD" + "/${ersatz}"; - - # Ports of functions for older nix versions - - # a Nix version of mapAttrs if the built-in doesn't exist - mapAttrs = builtins.mapAttrs or ( - f: set: with builtins; - listToAttrs (map (attr: { name = attr; value = f attr set.${attr}; }) (attrNames set)) - ); - - # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/lists.nix#L295 - range = first: last: if first > last then [ ] else builtins.genList (n: first + n) (last - first + 1); - - # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/strings.nix#L257 - stringToCharacters = s: map (p: builtins.substring p 1 s) (range 0 (builtins.stringLength s - 1)); - - # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/strings.nix#L269 - stringAsChars = f: s: concatStrings (map f (stringToCharacters s)); - concatMapStrings = f: list: concatStrings (map f list); - concatStrings = builtins.concatStringsSep ""; - - # https://github.com/NixOS/nixpkgs/blob/8a9f58a375c401b96da862d969f66429def1d118/lib/attrsets.nix#L331 - optionalAttrs = cond: as: if cond then as else { }; - - # fetchTarball version that is compatible between all the versions of Nix - builtins_fetchTarball = { url, name ? null, sha256 }@attrs: - let - inherit (builtins) lessThan nixVersion fetchTarball; - in - if lessThan nixVersion "1.12" then - fetchTarball ({ inherit url; } // (optionalAttrs (name != null) { inherit name; })) - else - fetchTarball attrs; - - # fetchurl version that is compatible between all the versions of Nix - builtins_fetchurl = { url, name ? null, sha256 }@attrs: - let - inherit (builtins) lessThan nixVersion fetchurl; - in - if lessThan nixVersion "1.12" then - fetchurl ({ inherit url; } // (optionalAttrs (name != null) { inherit name; })) - else - fetchurl attrs; - - # Create the final "sources" from the config - mkSources = config: - mapAttrs - ( - name: spec: - if builtins.hasAttr "outPath" spec - then - abort - "The values in sources.json should not have an 'outPath' attribute" - else - spec // { outPath = replace name (fetch config.pkgs name spec); } - ) - config.sources; - - # The "config" used by the fetchers - mkConfig = - { sourcesFile ? if builtins.pathExists ./sources.json then ./sources.json else null - , sources ? if sourcesFile == null then { } else builtins.fromJSON (builtins.readFile sourcesFile) - , system ? builtins.currentSystem - , pkgs ? mkPkgs sources system - }: rec { - # The sources, i.e. the attribute set of spec name to spec - inherit sources; - - # The "pkgs" (evaluated nixpkgs) to use for e.g. non-builtin fetchers - inherit pkgs; - }; - -in -mkSources (mkConfig { }) // { __functor = _: settings: mkSources (mkConfig settings); } diff --git a/copilot-visualizer/default.nix b/copilot-visualizer/default.nix index 896230e4f..7db132ae0 100644 --- a/copilot-visualizer/default.nix +++ b/copilot-visualizer/default.nix @@ -1,4 +1,4 @@ -{ sources ? import ./nix/sources.nix, ghc ? "ghc98" }: +{ sources ? import ../nix/sources.nix, ghc ? "ghc98" }: let depOverlay = n: o: { copilot-language = (import ../copilot-language { inherit sources ghc; }).copilot-language; diff --git a/copilot-visualizer/nix/sources.json b/copilot-visualizer/nix/sources.json deleted file mode 100644 index 7a59ceccc..000000000 --- a/copilot-visualizer/nix/sources.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "nixpkgs": { - "branch": "master", - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "63117158fe4f7f9b34eaecef088c417f8151e4ba", - "sha256": "sha256:036cjpfjghm6f8h4cldpv040kfvii7x8g5php4vyn9qmpncybxj6", - "type": "tarball", - "url": "https://github.com/NixOS/nixpkgs/archive/63117158fe4f7f9b34eaecef088c417f8151e4ba.tar.gz", - "url_template": "https://github.com///archive/.tar.gz" - } -} diff --git a/copilot-visualizer/nix/sources.nix b/copilot-visualizer/nix/sources.nix deleted file mode 100644 index fe3dadf7e..000000000 --- a/copilot-visualizer/nix/sources.nix +++ /dev/null @@ -1,198 +0,0 @@ -# This file has been generated by Niv. - -let - - # - # The fetchers. fetch_ fetches specs of type . - # - - fetch_file = pkgs: name: spec: - let - name' = sanitizeName name + "-src"; - in - if spec.builtin or true then - builtins_fetchurl { inherit (spec) url sha256; name = name'; } - else - pkgs.fetchurl { inherit (spec) url sha256; name = name'; }; - - fetch_tarball = pkgs: name: spec: - let - name' = sanitizeName name + "-src"; - in - if spec.builtin or true then - builtins_fetchTarball { name = name'; inherit (spec) url sha256; } - else - pkgs.fetchzip { name = name'; inherit (spec) url sha256; }; - - fetch_git = name: spec: - let - ref = - spec.ref or ( - if spec ? branch then "refs/heads/${spec.branch}" else - if spec ? tag then "refs/tags/${spec.tag}" else - abort "In git source '${name}': Please specify `ref`, `tag` or `branch`!" - ); - submodules = spec.submodules or false; - submoduleArg = - let - nixSupportsSubmodules = builtins.compareVersions builtins.nixVersion "2.4" >= 0; - emptyArgWithWarning = - if submodules - then - builtins.trace - ( - "The niv input \"${name}\" uses submodules " - + "but your nix's (${builtins.nixVersion}) builtins.fetchGit " - + "does not support them" - ) - { } - else { }; - in - if nixSupportsSubmodules - then { inherit submodules; } - else emptyArgWithWarning; - in - builtins.fetchGit - ({ url = spec.repo; inherit (spec) rev; inherit ref; } // submoduleArg); - - fetch_local = spec: spec.path; - - fetch_builtin-tarball = name: throw - ''[${name}] The niv type "builtin-tarball" is deprecated. You should instead use `builtin = true`. - $ niv modify ${name} -a type=tarball -a builtin=true''; - - fetch_builtin-url = name: throw - ''[${name}] The niv type "builtin-url" will soon be deprecated. You should instead use `builtin = true`. - $ niv modify ${name} -a type=file -a builtin=true''; - - # - # Various helpers - # - - # https://github.com/NixOS/nixpkgs/pull/83241/files#diff-c6f540a4f3bfa4b0e8b6bafd4cd54e8bR695 - sanitizeName = name: - ( - concatMapStrings (s: if builtins.isList s then "-" else s) - ( - builtins.split "[^[:alnum:]+._?=-]+" - ((x: builtins.elemAt (builtins.match "\\.*(.*)" x) 0) name) - ) - ); - - # The set of packages used when specs are fetched using non-builtins. - mkPkgs = sources: system: - let - sourcesNixpkgs = - import (builtins_fetchTarball { inherit (sources.nixpkgs) url sha256; }) { inherit system; }; - hasNixpkgsPath = builtins.any (x: x.prefix == "nixpkgs") builtins.nixPath; - hasThisAsNixpkgsPath = == ./.; - in - if builtins.hasAttr "nixpkgs" sources - then sourcesNixpkgs - else if hasNixpkgsPath && ! hasThisAsNixpkgsPath then - import { } - else - abort - '' - Please specify either (through -I or NIX_PATH=nixpkgs=...) or - add a package called "nixpkgs" to your sources.json. - ''; - - # The actual fetching function. - fetch = pkgs: name: spec: - - if ! builtins.hasAttr "type" spec then - abort "ERROR: niv spec ${name} does not have a 'type' attribute" - else if spec.type == "file" then fetch_file pkgs name spec - else if spec.type == "tarball" then fetch_tarball pkgs name spec - else if spec.type == "git" then fetch_git name spec - else if spec.type == "local" then fetch_local spec - else if spec.type == "builtin-tarball" then fetch_builtin-tarball name - else if spec.type == "builtin-url" then fetch_builtin-url name - else - abort "ERROR: niv spec ${name} has unknown type ${builtins.toJSON spec.type}"; - - # If the environment variable NIV_OVERRIDE_${name} is set, then use - # the path directly as opposed to the fetched source. - replace = name: drv: - let - saneName = stringAsChars (c: if (builtins.match "[a-zA-Z0-9]" c) == null then "_" else c) name; - ersatz = builtins.getEnv "NIV_OVERRIDE_${saneName}"; - in - if ersatz == "" then drv else - # this turns the string into an actual Nix path (for both absolute and - # relative paths) - if builtins.substring 0 1 ersatz == "/" then /. + ersatz else /. + builtins.getEnv "PWD" + "/${ersatz}"; - - # Ports of functions for older nix versions - - # a Nix version of mapAttrs if the built-in doesn't exist - mapAttrs = builtins.mapAttrs or ( - f: set: with builtins; - listToAttrs (map (attr: { name = attr; value = f attr set.${attr}; }) (attrNames set)) - ); - - # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/lists.nix#L295 - range = first: last: if first > last then [ ] else builtins.genList (n: first + n) (last - first + 1); - - # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/strings.nix#L257 - stringToCharacters = s: map (p: builtins.substring p 1 s) (range 0 (builtins.stringLength s - 1)); - - # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/strings.nix#L269 - stringAsChars = f: s: concatStrings (map f (stringToCharacters s)); - concatMapStrings = f: list: concatStrings (map f list); - concatStrings = builtins.concatStringsSep ""; - - # https://github.com/NixOS/nixpkgs/blob/8a9f58a375c401b96da862d969f66429def1d118/lib/attrsets.nix#L331 - optionalAttrs = cond: as: if cond then as else { }; - - # fetchTarball version that is compatible between all the versions of Nix - builtins_fetchTarball = { url, name ? null, sha256 }@attrs: - let - inherit (builtins) lessThan nixVersion fetchTarball; - in - if lessThan nixVersion "1.12" then - fetchTarball ({ inherit url; } // (optionalAttrs (name != null) { inherit name; })) - else - fetchTarball attrs; - - # fetchurl version that is compatible between all the versions of Nix - builtins_fetchurl = { url, name ? null, sha256 }@attrs: - let - inherit (builtins) lessThan nixVersion fetchurl; - in - if lessThan nixVersion "1.12" then - fetchurl ({ inherit url; } // (optionalAttrs (name != null) { inherit name; })) - else - fetchurl attrs; - - # Create the final "sources" from the config - mkSources = config: - mapAttrs - ( - name: spec: - if builtins.hasAttr "outPath" spec - then - abort - "The values in sources.json should not have an 'outPath' attribute" - else - spec // { outPath = replace name (fetch config.pkgs name spec); } - ) - config.sources; - - # The "config" used by the fetchers - mkConfig = - { sourcesFile ? if builtins.pathExists ./sources.json then ./sources.json else null - , sources ? if sourcesFile == null then { } else builtins.fromJSON (builtins.readFile sourcesFile) - , system ? builtins.currentSystem - , pkgs ? mkPkgs sources system - }: rec { - # The sources, i.e. the attribute set of spec name to spec - inherit sources; - - # The "pkgs" (evaluated nixpkgs) to use for e.g. non-builtin fetchers - inherit pkgs; - }; - -in -mkSources (mkConfig { }) // { __functor = _: settings: mkSources (mkConfig settings); } diff --git a/copilot/default.nix b/copilot/default.nix index cba76477b..6be9ccc08 100644 --- a/copilot/default.nix +++ b/copilot/default.nix @@ -1,4 +1,4 @@ -{ sources ? import ./nix/sources.nix, ghc ? "ghc98" }: +{ sources ? import ../nix/sources.nix, ghc ? "ghc98" }: let depOverlay = n: o: { copilot-core = (import ../copilot-core { inherit sources ghc; }).copilot-core; diff --git a/copilot/nix/sources.json b/copilot/nix/sources.json deleted file mode 100644 index 7a59ceccc..000000000 --- a/copilot/nix/sources.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "nixpkgs": { - "branch": "master", - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "63117158fe4f7f9b34eaecef088c417f8151e4ba", - "sha256": "sha256:036cjpfjghm6f8h4cldpv040kfvii7x8g5php4vyn9qmpncybxj6", - "type": "tarball", - "url": "https://github.com/NixOS/nixpkgs/archive/63117158fe4f7f9b34eaecef088c417f8151e4ba.tar.gz", - "url_template": "https://github.com///archive/.tar.gz" - } -} diff --git a/copilot/nix/sources.nix b/copilot/nix/sources.nix deleted file mode 100644 index fe3dadf7e..000000000 --- a/copilot/nix/sources.nix +++ /dev/null @@ -1,198 +0,0 @@ -# This file has been generated by Niv. - -let - - # - # The fetchers. fetch_ fetches specs of type . - # - - fetch_file = pkgs: name: spec: - let - name' = sanitizeName name + "-src"; - in - if spec.builtin or true then - builtins_fetchurl { inherit (spec) url sha256; name = name'; } - else - pkgs.fetchurl { inherit (spec) url sha256; name = name'; }; - - fetch_tarball = pkgs: name: spec: - let - name' = sanitizeName name + "-src"; - in - if spec.builtin or true then - builtins_fetchTarball { name = name'; inherit (spec) url sha256; } - else - pkgs.fetchzip { name = name'; inherit (spec) url sha256; }; - - fetch_git = name: spec: - let - ref = - spec.ref or ( - if spec ? branch then "refs/heads/${spec.branch}" else - if spec ? tag then "refs/tags/${spec.tag}" else - abort "In git source '${name}': Please specify `ref`, `tag` or `branch`!" - ); - submodules = spec.submodules or false; - submoduleArg = - let - nixSupportsSubmodules = builtins.compareVersions builtins.nixVersion "2.4" >= 0; - emptyArgWithWarning = - if submodules - then - builtins.trace - ( - "The niv input \"${name}\" uses submodules " - + "but your nix's (${builtins.nixVersion}) builtins.fetchGit " - + "does not support them" - ) - { } - else { }; - in - if nixSupportsSubmodules - then { inherit submodules; } - else emptyArgWithWarning; - in - builtins.fetchGit - ({ url = spec.repo; inherit (spec) rev; inherit ref; } // submoduleArg); - - fetch_local = spec: spec.path; - - fetch_builtin-tarball = name: throw - ''[${name}] The niv type "builtin-tarball" is deprecated. You should instead use `builtin = true`. - $ niv modify ${name} -a type=tarball -a builtin=true''; - - fetch_builtin-url = name: throw - ''[${name}] The niv type "builtin-url" will soon be deprecated. You should instead use `builtin = true`. - $ niv modify ${name} -a type=file -a builtin=true''; - - # - # Various helpers - # - - # https://github.com/NixOS/nixpkgs/pull/83241/files#diff-c6f540a4f3bfa4b0e8b6bafd4cd54e8bR695 - sanitizeName = name: - ( - concatMapStrings (s: if builtins.isList s then "-" else s) - ( - builtins.split "[^[:alnum:]+._?=-]+" - ((x: builtins.elemAt (builtins.match "\\.*(.*)" x) 0) name) - ) - ); - - # The set of packages used when specs are fetched using non-builtins. - mkPkgs = sources: system: - let - sourcesNixpkgs = - import (builtins_fetchTarball { inherit (sources.nixpkgs) url sha256; }) { inherit system; }; - hasNixpkgsPath = builtins.any (x: x.prefix == "nixpkgs") builtins.nixPath; - hasThisAsNixpkgsPath = == ./.; - in - if builtins.hasAttr "nixpkgs" sources - then sourcesNixpkgs - else if hasNixpkgsPath && ! hasThisAsNixpkgsPath then - import { } - else - abort - '' - Please specify either (through -I or NIX_PATH=nixpkgs=...) or - add a package called "nixpkgs" to your sources.json. - ''; - - # The actual fetching function. - fetch = pkgs: name: spec: - - if ! builtins.hasAttr "type" spec then - abort "ERROR: niv spec ${name} does not have a 'type' attribute" - else if spec.type == "file" then fetch_file pkgs name spec - else if spec.type == "tarball" then fetch_tarball pkgs name spec - else if spec.type == "git" then fetch_git name spec - else if spec.type == "local" then fetch_local spec - else if spec.type == "builtin-tarball" then fetch_builtin-tarball name - else if spec.type == "builtin-url" then fetch_builtin-url name - else - abort "ERROR: niv spec ${name} has unknown type ${builtins.toJSON spec.type}"; - - # If the environment variable NIV_OVERRIDE_${name} is set, then use - # the path directly as opposed to the fetched source. - replace = name: drv: - let - saneName = stringAsChars (c: if (builtins.match "[a-zA-Z0-9]" c) == null then "_" else c) name; - ersatz = builtins.getEnv "NIV_OVERRIDE_${saneName}"; - in - if ersatz == "" then drv else - # this turns the string into an actual Nix path (for both absolute and - # relative paths) - if builtins.substring 0 1 ersatz == "/" then /. + ersatz else /. + builtins.getEnv "PWD" + "/${ersatz}"; - - # Ports of functions for older nix versions - - # a Nix version of mapAttrs if the built-in doesn't exist - mapAttrs = builtins.mapAttrs or ( - f: set: with builtins; - listToAttrs (map (attr: { name = attr; value = f attr set.${attr}; }) (attrNames set)) - ); - - # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/lists.nix#L295 - range = first: last: if first > last then [ ] else builtins.genList (n: first + n) (last - first + 1); - - # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/strings.nix#L257 - stringToCharacters = s: map (p: builtins.substring p 1 s) (range 0 (builtins.stringLength s - 1)); - - # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/strings.nix#L269 - stringAsChars = f: s: concatStrings (map f (stringToCharacters s)); - concatMapStrings = f: list: concatStrings (map f list); - concatStrings = builtins.concatStringsSep ""; - - # https://github.com/NixOS/nixpkgs/blob/8a9f58a375c401b96da862d969f66429def1d118/lib/attrsets.nix#L331 - optionalAttrs = cond: as: if cond then as else { }; - - # fetchTarball version that is compatible between all the versions of Nix - builtins_fetchTarball = { url, name ? null, sha256 }@attrs: - let - inherit (builtins) lessThan nixVersion fetchTarball; - in - if lessThan nixVersion "1.12" then - fetchTarball ({ inherit url; } // (optionalAttrs (name != null) { inherit name; })) - else - fetchTarball attrs; - - # fetchurl version that is compatible between all the versions of Nix - builtins_fetchurl = { url, name ? null, sha256 }@attrs: - let - inherit (builtins) lessThan nixVersion fetchurl; - in - if lessThan nixVersion "1.12" then - fetchurl ({ inherit url; } // (optionalAttrs (name != null) { inherit name; })) - else - fetchurl attrs; - - # Create the final "sources" from the config - mkSources = config: - mapAttrs - ( - name: spec: - if builtins.hasAttr "outPath" spec - then - abort - "The values in sources.json should not have an 'outPath' attribute" - else - spec // { outPath = replace name (fetch config.pkgs name spec); } - ) - config.sources; - - # The "config" used by the fetchers - mkConfig = - { sourcesFile ? if builtins.pathExists ./sources.json then ./sources.json else null - , sources ? if sourcesFile == null then { } else builtins.fromJSON (builtins.readFile sourcesFile) - , system ? builtins.currentSystem - , pkgs ? mkPkgs sources system - }: rec { - # The sources, i.e. the attribute set of spec name to spec - inherit sources; - - # The "pkgs" (evaluated nixpkgs) to use for e.g. non-builtin fetchers - inherit pkgs; - }; - -in -mkSources (mkConfig { }) // { __functor = _: settings: mkSources (mkConfig settings); } diff --git a/copilot-verifier/nix/sources.json b/nix/sources.json similarity index 100% rename from copilot-verifier/nix/sources.json rename to nix/sources.json diff --git a/copilot-bluespec/nix/sources.nix b/nix/sources.nix similarity index 100% rename from copilot-bluespec/nix/sources.nix rename to nix/sources.nix From 51adbf665c2b5cfffcb826d536d5ccd1b49ccdff Mon Sep 17 00:00:00 2001 From: Daniil Iaitskov Date: Sat, 15 Nov 2025 17:53:42 +0300 Subject: [PATCH 15/18] nix setup HLS in core --- copilot-core/hie.yaml | 10 ++++++++++ copilot-core/shell.nix | 8 ++++++++ 2 files changed, 18 insertions(+) create mode 100644 copilot-core/hie.yaml create mode 100644 copilot-core/shell.nix diff --git a/copilot-core/hie.yaml b/copilot-core/hie.yaml new file mode 100644 index 000000000..20e14b24f --- /dev/null +++ b/copilot-core/hie.yaml @@ -0,0 +1,10 @@ +cradle: + multi: + - path: "./src" + config: + cradle: + cabal: + - path: "./tests" + config: + cradle: + cabal: diff --git a/copilot-core/shell.nix b/copilot-core/shell.nix new file mode 100644 index 000000000..a46dae22d --- /dev/null +++ b/copilot-core/shell.nix @@ -0,0 +1,8 @@ +{}: +let + inherit (import ./. {}) copilot-core hp np; +in +hp.shellFor { + packages = p: [ copilot-core ]; + nativeBuildInputs = (with np; [ cabal-install ghcid niv ]) ++ (with hp; [ haskell-language-server ]); +} From 2adb2adffe62431390f03e7715aa78ef78b0c739 Mon Sep 17 00:00:00 2001 From: Daniil Iaitskov Date: Sat, 15 Nov 2025 17:56:12 +0300 Subject: [PATCH 16/18] nix setup HLS in prettyprinter --- copilot-prettyprinter/hie.yaml | 6 ++++++ copilot-prettyprinter/shell.nix | 8 ++++++++ 2 files changed, 14 insertions(+) create mode 100644 copilot-prettyprinter/hie.yaml create mode 100644 copilot-prettyprinter/shell.nix diff --git a/copilot-prettyprinter/hie.yaml b/copilot-prettyprinter/hie.yaml new file mode 100644 index 000000000..cea2181ba --- /dev/null +++ b/copilot-prettyprinter/hie.yaml @@ -0,0 +1,6 @@ +cradle: + multi: + - path: "./src" + config: + cradle: + cabal: diff --git a/copilot-prettyprinter/shell.nix b/copilot-prettyprinter/shell.nix new file mode 100644 index 000000000..04487e86b --- /dev/null +++ b/copilot-prettyprinter/shell.nix @@ -0,0 +1,8 @@ +{}: +let + inherit (import ./. {}) copilot-prettyprinter hp np; +in +hp.shellFor { + packages = p: [ copilot-prettyprinter ]; + nativeBuildInputs = (with np; [ cabal-install ghcid niv ]) ++ (with hp; [ haskell-language-server ]); +} From d764bd05f26b537c88ddbe90f9123819286732f8 Mon Sep 17 00:00:00 2001 From: Daniil Iaitskov Date: Sat, 15 Nov 2025 18:00:39 +0300 Subject: [PATCH 17/18] nix setup HLS in interpeter --- copilot-interpreter/hie.yaml | 10 ++++++++++ copilot-interpreter/shell.nix | 8 ++++++++ 2 files changed, 18 insertions(+) create mode 100644 copilot-interpreter/hie.yaml create mode 100644 copilot-interpreter/shell.nix diff --git a/copilot-interpreter/hie.yaml b/copilot-interpreter/hie.yaml new file mode 100644 index 000000000..20e14b24f --- /dev/null +++ b/copilot-interpreter/hie.yaml @@ -0,0 +1,10 @@ +cradle: + multi: + - path: "./src" + config: + cradle: + cabal: + - path: "./tests" + config: + cradle: + cabal: diff --git a/copilot-interpreter/shell.nix b/copilot-interpreter/shell.nix new file mode 100644 index 000000000..412ab618a --- /dev/null +++ b/copilot-interpreter/shell.nix @@ -0,0 +1,8 @@ +{}: +let + inherit (import ./. {}) copilot-interpreter hp np; +in +hp.shellFor { + packages = p: [ copilot-interpreter ]; + nativeBuildInputs = (with np; [ cabal-install ghcid niv ]) ++ (with hp; [ haskell-language-server ]); +} From a2069532a71233fd39dd60ff0d694a6f160bad64 Mon Sep 17 00:00:00 2001 From: Daniil Iaitskov Date: Sat, 15 Nov 2025 19:50:05 +0300 Subject: [PATCH 18/18] nix setup HLS in rest of modules --- copilot-bluespec/default.nix | 4 +++- copilot-bluespec/hie.yaml | 10 ++++++++++ copilot-bluespec/shell.nix | 8 ++++++++ copilot-language/hie.yaml | 10 ++++++++++ copilot-language/shell.nix | 8 ++++++++ copilot-libraries/hie.yaml | 10 ++++++++++ copilot-libraries/shell.nix | 8 ++++++++ copilot-theorem/hie.yaml | 10 ++++++++++ copilot-theorem/shell.nix | 8 ++++++++ copilot-verifier/hie.yaml | 10 ++++++++++ copilot-verifier/shell.nix | 5 ++++- copilot-visualizer/hie.yaml | 6 ++++++ copilot-visualizer/shell.nix | 8 ++++++++ 13 files changed, 103 insertions(+), 2 deletions(-) create mode 100644 copilot-bluespec/hie.yaml create mode 100644 copilot-bluespec/shell.nix create mode 100644 copilot-language/hie.yaml create mode 100644 copilot-language/shell.nix create mode 100644 copilot-libraries/hie.yaml create mode 100644 copilot-libraries/shell.nix create mode 100644 copilot-theorem/hie.yaml create mode 100644 copilot-theorem/shell.nix create mode 100644 copilot-verifier/hie.yaml create mode 100644 copilot-visualizer/hie.yaml create mode 100644 copilot-visualizer/shell.nix diff --git a/copilot-bluespec/default.nix b/copilot-bluespec/default.nix index 97430f9b3..e6edf53e2 100644 --- a/copilot-bluespec/default.nix +++ b/copilot-bluespec/default.nix @@ -13,10 +13,11 @@ let "^LICENSE$" ]; + externalDeps = [ np.bluespec np.removeReferencesTo ]; copilot-bluespec-base = (hp.callCabal2nix "copilot-bluespec" (np.lib.sourceByRegex ./. sourceRegexes) {} ).overrideAttrs(oa: { - nativeBuildInputs = [ np.bluespec np.removeReferencesTo ]; + propagatedBuildInputs = (oa.propagatedBuildInputs or []) ++ externalDeps; }); copilot-bluespec-overlay = _n: _o: { copilot-bluespec = copilot-bluespec-base; }; hp = bhp.override (o: { @@ -28,5 +29,6 @@ let in { inherit np; inherit hp; + inherit externalDeps; inherit copilot-bluespec; } diff --git a/copilot-bluespec/hie.yaml b/copilot-bluespec/hie.yaml new file mode 100644 index 000000000..20e14b24f --- /dev/null +++ b/copilot-bluespec/hie.yaml @@ -0,0 +1,10 @@ +cradle: + multi: + - path: "./src" + config: + cradle: + cabal: + - path: "./tests" + config: + cradle: + cabal: diff --git a/copilot-bluespec/shell.nix b/copilot-bluespec/shell.nix new file mode 100644 index 000000000..b30503d68 --- /dev/null +++ b/copilot-bluespec/shell.nix @@ -0,0 +1,8 @@ +{}: +let + inherit (import ./. {}) copilot-bluespec hp np externalDeps; +in +hp.shellFor { + packages = p: [ copilot-bluespec ]; + nativeBuildInputs = (with np; [ cabal-install ghcid niv ]) ++ (with hp; [ haskell-language-server ]) ++ externalDeps; +} diff --git a/copilot-language/hie.yaml b/copilot-language/hie.yaml new file mode 100644 index 000000000..20e14b24f --- /dev/null +++ b/copilot-language/hie.yaml @@ -0,0 +1,10 @@ +cradle: + multi: + - path: "./src" + config: + cradle: + cabal: + - path: "./tests" + config: + cradle: + cabal: diff --git a/copilot-language/shell.nix b/copilot-language/shell.nix new file mode 100644 index 000000000..482083dc6 --- /dev/null +++ b/copilot-language/shell.nix @@ -0,0 +1,8 @@ +{}: +let + inherit (import ./. {}) copilot-language hp np; +in +hp.shellFor { + packages = p: [ copilot-language ]; + nativeBuildInputs = (with np; [ cabal-install ghcid niv ]) ++ (with hp; [ haskell-language-server ]); +} diff --git a/copilot-libraries/hie.yaml b/copilot-libraries/hie.yaml new file mode 100644 index 000000000..20e14b24f --- /dev/null +++ b/copilot-libraries/hie.yaml @@ -0,0 +1,10 @@ +cradle: + multi: + - path: "./src" + config: + cradle: + cabal: + - path: "./tests" + config: + cradle: + cabal: diff --git a/copilot-libraries/shell.nix b/copilot-libraries/shell.nix new file mode 100644 index 000000000..1ce5439b5 --- /dev/null +++ b/copilot-libraries/shell.nix @@ -0,0 +1,8 @@ +{}: +let + inherit (import ./. {}) copilot-libraries hp np; +in +hp.shellFor { + packages = p: [ copilot-libraries ]; + nativeBuildInputs = (with np; [ cabal-install ghcid niv ]) ++ (with hp; [ haskell-language-server ]); +} diff --git a/copilot-theorem/hie.yaml b/copilot-theorem/hie.yaml new file mode 100644 index 000000000..20e14b24f --- /dev/null +++ b/copilot-theorem/hie.yaml @@ -0,0 +1,10 @@ +cradle: + multi: + - path: "./src" + config: + cradle: + cabal: + - path: "./tests" + config: + cradle: + cabal: diff --git a/copilot-theorem/shell.nix b/copilot-theorem/shell.nix new file mode 100644 index 000000000..6311168fb --- /dev/null +++ b/copilot-theorem/shell.nix @@ -0,0 +1,8 @@ +{}: +let + inherit (import ./. {}) copilot-theorem hp np; +in +hp.shellFor { + packages = p: [ copilot-theorem ]; + nativeBuildInputs = (with np; [ cabal-install ghcid niv ]) ++ (with hp; [ haskell-language-server ]); +} diff --git a/copilot-verifier/hie.yaml b/copilot-verifier/hie.yaml new file mode 100644 index 000000000..a99a3847e --- /dev/null +++ b/copilot-verifier/hie.yaml @@ -0,0 +1,10 @@ +cradle: + multi: + - path: "./src" + config: + cradle: + cabal: + - path: "./test" + config: + cradle: + cabal: diff --git a/copilot-verifier/shell.nix b/copilot-verifier/shell.nix index 7cb0ba608..07c1e335b 100644 --- a/copilot-verifier/shell.nix +++ b/copilot-verifier/shell.nix @@ -4,6 +4,9 @@ let in hp.shellFor { packages = p: [ copilot-verifier ]; - nativeBuildInputs = (with np; [ cabal-install ghcid niv]) ++ externalDeps; + nativeBuildInputs = + (with np; [ cabal-install ghcid niv]) ++ + (with hp; [ haskell-language-server ]) ++ + externalDeps; shellHook = shellTuning; } diff --git a/copilot-visualizer/hie.yaml b/copilot-visualizer/hie.yaml new file mode 100644 index 000000000..cea2181ba --- /dev/null +++ b/copilot-visualizer/hie.yaml @@ -0,0 +1,6 @@ +cradle: + multi: + - path: "./src" + config: + cradle: + cabal: diff --git a/copilot-visualizer/shell.nix b/copilot-visualizer/shell.nix new file mode 100644 index 000000000..d6d41df50 --- /dev/null +++ b/copilot-visualizer/shell.nix @@ -0,0 +1,8 @@ +{}: +let + inherit (import ./. {}) copilot-visualizer hp np; +in +hp.shellFor { + packages = p: [ copilot-visualizer ]; + nativeBuildInputs = (with np; [ cabal-install ghcid niv ]) ++ (with hp; [ haskell-language-server ]); +}